|
-
May 20th, 2005, 03:02 AM
#5
Thread Starter
Hyperactive Member
Re: property from c# to vb.net
Thanks to all for the replies.
Sorry to appear dense, but what would be the equivalent in vb.net, can i use the output from the c# tovb.net convert program.
i did some googling on this last nigth and it said something about the proeprty being an indexer, which don't exist in vb.net
or do i just need to set the item property to default?
i'd really like a code example if possible. if it makes it easier here is the class that the property belongs to:
Code:
using System;
using System.Collections;
namespace BVA.ActiveDirectory.Navigator.Objects
{
/// <summary>
/// Collection of users.
/// </summary>
public class UserCollection : CollectionBase
{
/// <summary>
/// This property indicates if the collection is fixed.
/// </summary>
public virtual bool IsFixed
{
get
{
return false;
}
}
/// <summary>
/// Indicates if the collection is read only.
/// </summary>
public virtual bool IsReadOnly
{
get
{
return false;
}
}
/// <summary>
/// Enumerator for this collection.
/// </summary>
public virtual User this[int index]
{
get
{
if (!((User)this.List[index]).IsLoaded)
{
((User)this.List[index]).Load();
}
return (User) this.List[index];
}
set
{
this.List[index] = value;
}
}
/// <summary>
/// Enumerator for this collection. This enumerator gets an item through its name.
/// </summary>
public virtual User this[string Username]
{
get
{
int index = -1;
for (int i=0; i<this.List.Count; i++)
{
if (((User)this.List[i]).UserName==Username)
{
index = i;
}
}
if (index==-1){throw new NullReferenceException ("The User " + Username + " was not found.");}
if (!((User)this.List[index]).IsLoaded)
{
((User)this.List[index]).Load();
}
return (User) this.List[index];
}
set
{
int index = -1;
for (int i=0; i<this.List.Count; i++)
{
if (((User)this.List[i]).UserName==Username)
{
index = i;
}
}
if (index==-1){throw new NullReferenceException ("The User " + Username + " was not found.");}
this.List[index] = value;
}
}
/// <summary>
/// Returns the index (position) of an item in the collection.
/// </summary>
/// <param name="item">Item to be searched.</param>
/// <returns>Returns the index(position) of the item.</returns>
public virtual int IndexOf(User item)
{
return this.List.IndexOf(item);
}
/// <summary>
/// This method appends an item to the collection.
/// </summary>
/// <param name="item">Item to be appended to the collection.</param>
/// <returns>Returns an integer indicating if the item was added.</returns>
public virtual int Add(User item)
{
return this.List.Add(item);
}
/// <summary>
/// Removes an item from the collection.
/// </summary>
/// <param name="item">Item to be removed from the collection.</param>
public virtual void Remove(User item)
{
this.List.Remove(item);
}
/// <summary>
/// Copies an array to another.
/// </summary>
/// <param name="array">Array to be copied.</param>
/// <param name="index">Index to begin the copy.</param>
public virtual void CopyTo(Array array, int index)
{
this.List.CopyTo(array, index);
}
/// <summary>
/// This methoid adds one collection to this collection.
/// </summary>
/// <param name="collection">Collection to be added.</param>
public virtual void AddRange(UserCollection collection)
{
this.InnerList.AddRange(collection);
}
/// <summary>
/// This methoid adds one collection to this collection.
/// </summary>
/// <param name="collection">Collection to be added.</param>
public virtual void AddRange(User[] collection)
{
this.InnerList.AddRange(collection);
}
/// <summary>
/// This method tells if the collection contains the item.
/// </summary>
/// <param name="item">Item to be tested.</param>
/// <returns>Returns true if the collection contains the item.</returns>
public virtual bool Contains(User item)
{
return this.List.Contains(item);
}
/// <summary>
/// Inserts an item in the collection.
/// </summary>
/// <param name="index">Position to be inserted.</param>
/// <param name="item">Item to be inserted.</param>
public virtual void Insert(int index, User item)
{
this.List.Insert(index, item);
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|