|
-
May 19th, 2005, 08:40 AM
#1
Thread Starter
Hyperactive Member
property from c# to vb.net
I'm trying to port this property to vb.net.
but i don't know what the
bit is doing. please help.
Code:
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;
}
}
-
May 19th, 2005, 08:53 AM
#2
Frenzied Member
Re: property from c# to vb.net
I just put the C# code through the C# to VB.NET converter, and this is what it created:
VB Code:
Public Overridable User Property index)() As Me(int
Get
If Not (CType(Me.List(index),User)).IsLoaded Then
(CType(Me.List(index), User)).Load()
End If
ReturnCType(Me.List(index), User)
End Get
Set (ByVal Value As Me(int)
Me.List(index) = value
End Set
End Property
~Peter

-
May 19th, 2005, 09:42 AM
#3
Fanatic Member
Re: property from c# to vb.net
'This' is synonymous with 'Me'. Brackets [] are used for arrays*, so the property looks to be an index to a collection class. That is, if i have a People class housing Person objects,
Code:
public Person this[int index]
will return the Person object associated w/ the supplied index.
* As an aside, this is one of the places where VB is just retarded. () for arrays/indices and functions/parameters makes no sense at all. They do different things - make them look different. You may now return to your scheduled programming.
-
May 19th, 2005, 12:07 PM
#4
Re: property from c# to vb.net
It's equivalent to setting the Item property as Default in vb.net
-
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
|