473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Property list

Want to know if/how to get a list of properties that are available in a
class and store the properties names in an arraylist.

TIA,

Raymond Lewallen
Nov 20 '05 #1
7 1672
Nevermind found the PropertyInfo type in reflection. Overlooked it before.

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Want to know if/how to get a list of properties that are available in a
class and store the properties names in an arraylist.

TIA,

Raymond Lewallen

Nov 20 '05 #2
* "Raymond Lewallen" <Ra******************@nospam.faa.gov> scripsit:
Want to know if/how to get a list of properties that are available in a
class and store the properties names in an arraylist.


\\\
Me.ListBox1.DisplayMember = "Name"
Me.ListBox1.DataSource = GetType(SystemColors).GetProperties()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Ok, what I thought I had figured out isn't working. Can anyone tell me why
my lenght for propertyinfo always comes up zero?

Public Class PdfSupport
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type, _
ByRef al As ArrayList) As ArrayList
Dim propertyInformation As PropertyInfo() = _
type.GetProperties(BindingFlags.Public)
Dim propertyCount As Int32
For propertyCount = 0 To propertyInformation.Length - 1
Dim currentProperty As PropertyInfo = _
CType(propertyInformation(propertyCount), PropertyInfo)
al.Add(currentProperty.Name.ToString)
Next propertyCount
Return al
End Function
End Class

Public Class Retrieve

Dim _al As New ArrayList

Public Sub New()
Load()
End Sub

Private Sub Load()

LoadArrayList()

End Sub

Private Sub LoadArrayList()
_al =
PdfSupport.ReflectPropertyNamesToArrayList(GetType (MyClass), _al)
End Sub

End Class

Friend Class MyClass

Public ReadOnly Property A() As String
Get
Return "Hello"
End Get
End Property

Public ReadOnly Property B() As String
Get
Return "World"
End Get
End Property

Public ReadOnly Property C() As String
Get
Return "How"
End Get
End Property

Public ReadOnly Property D() As String
Get
Return "Are"
End Get
End Property

Public ReadOnly Property E() As String
Get
Return "You"
End Get
End Property

End Class
"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Want to know if/how to get a list of properties that are available in a
class and store the properties names in an arraylist.

TIA,

Raymond Lewallen

Nov 20 '05 #4
I found that part in reflection, but I'm trying to get it to work by passing
the type into a function as a parameter, with no success. See my other post
in this topic.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2k************@uni-berlin.de...
* "Raymond Lewallen" <Ra******************@nospam.faa.gov> scripsit:
Want to know if/how to get a list of properties that are available in a
class and store the properties names in an arraylist.


\\\
Me.ListBox1.DisplayMember = "Name"
Me.ListBox1.DataSource = GetType(SystemColors).GetProperties()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5
"Raymond Lewallen" <Ra******************@nospam.faa.gov> schrieb:
I found that part in reflection, but I'm trying to get it to work
by passing the type into a function as a parameter, with no
success. See my other post in this topic.


\\\
ListAllTypes(Me.GetType(), Me.ListBox1)
..
..
..
Private Sub ListAllTypes(ByVal Type As Type, ByVal ListBox As ListBox)
ListBox.DisplayMember = "Name"
ListBox.DataSource = Type.GetProperties()
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
Raymond,
Ok, what I thought I had figured out isn't working. Can anyone tell me why my lenght for propertyinfo always comes up zero? Because your GetProperties call is returning only members that have only the
Public attribute set. At the very least you also need to include
BindingFlags.Instance if you want instance properties & possible
BindingFlags.Static if you want Shared properties. Be certain to read the
Type.GetProperties(bindingFlags) help to find out how to call it. I would
simply use Type.GetProperties().
However I have a few questions comments about your code:
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type, _
ByRef al As ArrayList) As ArrayList
Why return the array via both the parameters & the return value?

I would change the function to:
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type _
) As ArrayList Dim al As New ArrayList

Note ArrayList is a Reference type, passing it as ByRef is redundent. ByRef
allows ReflectPropertyNamesToArrayList to modify the _al variable itself,
the ArrayList object itself is automatically modifiable by virtue of being a
Reference type.
Why are you calling ToString on a String property?
al.Add(currentProperty.Name.ToString)
I would change it to (as Name is already a string).
al.Add(currentProperty.Name)

Why are you creating an instance of the ArrayList, just to ignore it when
you call ReflectPropertyNamesToArrayList?

I would not use the New keyword on the declaration of _al:
Public Class Retrieve

Dim _al As ArrayList _al =
PdfSupport.ReflectPropertyNamesToArrayList(GetType (MyClass))
Hope this helps
Jay

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:er*************@tk2msftngp13.phx.gbl... Ok, what I thought I had figured out isn't working. Can anyone tell me why my lenght for propertyinfo always comes up zero?

Public Class PdfSupport
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type, _
ByRef al As ArrayList) As ArrayList
Dim propertyInformation As PropertyInfo() = _
type.GetProperties(BindingFlags.Public)
Dim propertyCount As Int32
For propertyCount = 0 To propertyInformation.Length - 1
Dim currentProperty As PropertyInfo = _
CType(propertyInformation(propertyCount), PropertyInfo) al.Add(currentProperty.Name.ToString)
Next propertyCount
Return al
End Function
End Class

Public Class Retrieve

Dim _al As New ArrayList

Public Sub New()
Load()
End Sub

Private Sub Load()

LoadArrayList()

End Sub

Private Sub LoadArrayList()
_al =
PdfSupport.ReflectPropertyNamesToArrayList(GetType (MyClass), _al)
End Sub

End Class

Friend Class MyClass

Public ReadOnly Property A() As String
Get
Return "Hello"
End Get
End Property

Public ReadOnly Property B() As String
Get
Return "World"
End Get
End Property

Public ReadOnly Property C() As String
Get
Return "How"
End Get
End Property

Public ReadOnly Property D() As String
Get
Return "Are"
End Get
End Property

Public ReadOnly Property E() As String
Get
Return "You"
End Get
End Property

End Class
"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
Want to know if/how to get a list of properties that are available in a
class and store the properties names in an arraylist.

TIA,

Raymond Lewallen


Nov 20 '05 #7
Jay,

Thanks for all your input. In answer to all your questions and comments,
its simple. I'm a DBA, not a programmer. :) I am however trying my best to
learn all this .NET stuff.

Raymond Lewallen

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Raymond,
Ok, what I thought I had figured out isn't working. Can anyone tell me why
my lenght for propertyinfo always comes up zero?

Because your GetProperties call is returning only members that have only

the Public attribute set. At the very least you also need to include
BindingFlags.Instance if you want instance properties & possible
BindingFlags.Static if you want Shared properties. Be certain to read the
Type.GetProperties(bindingFlags) help to find out how to call it. I would
simply use Type.GetProperties().
However I have a few questions comments about your code:
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type, _
ByRef al As ArrayList) As ArrayList
Why return the array via both the parameters & the return value?

I would change the function to:
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type _
) As ArrayList

Dim al As New ArrayList

Note ArrayList is a Reference type, passing it as ByRef is redundent.

ByRef allows ReflectPropertyNamesToArrayList to modify the _al variable itself,
the ArrayList object itself is automatically modifiable by virtue of being a Reference type.
Why are you calling ToString on a String property?
al.Add(currentProperty.Name.ToString)


I would change it to (as Name is already a string).
al.Add(currentProperty.Name)

Why are you creating an instance of the ArrayList, just to ignore it when
you call ReflectPropertyNamesToArrayList?

I would not use the New keyword on the declaration of _al:
Public Class Retrieve

Dim _al As ArrayList

_al =
PdfSupport.ReflectPropertyNamesToArrayList(GetType (MyClass))


Hope this helps
Jay

"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message
news:er*************@tk2msftngp13.phx.gbl...
Ok, what I thought I had figured out isn't working. Can anyone tell me

why
my lenght for propertyinfo always comes up zero?

Public Class PdfSupport
Shared Function ReflectPropertyNamesToArrayList(ByVal type As Type, _
ByRef al As ArrayList) As ArrayList
Dim propertyInformation As PropertyInfo() = _
type.GetProperties(BindingFlags.Public)
Dim propertyCount As Int32
For propertyCount = 0 To propertyInformation.Length - 1
Dim currentProperty As PropertyInfo = _
CType(propertyInformation(propertyCount),

PropertyInfo)
al.Add(currentProperty.Name.ToString)
Next propertyCount
Return al
End Function
End Class

Public Class Retrieve

Dim _al As New ArrayList

Public Sub New()
Load()
End Sub

Private Sub Load()

LoadArrayList()

End Sub

Private Sub LoadArrayList()
_al =
PdfSupport.ReflectPropertyNamesToArrayList(GetType (MyClass), _al)
End Sub

End Class

Friend Class MyClass

Public ReadOnly Property A() As String
Get
Return "Hello"
End Get
End Property

Public ReadOnly Property B() As String
Get
Return "World"
End Get
End Property

Public ReadOnly Property C() As String
Get
Return "How"
End Get
End Property

Public ReadOnly Property D() As String
Get
Return "Are"
End Get
End Property

Public ReadOnly Property E() As String
Get
Return "You"
End Get
End Property

End Class
"Raymond Lewallen" <Ra******************@nospam.faa.gov> wrote in message news:eA**************@tk2msftngp13.phx.gbl...
Want to know if/how to get a list of properties that are available in a class and store the properties names in an arraylist.

TIA,

Raymond Lewallen



Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
1
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if...
0
by: Jordan Bowness | last post by:
I make a similar post in another newsgroup, but this example is simplified somewhat. I have a component (cmpMyComponent) with 2 properties. The 1st property is a string value (Description) and...
6
by: Altman | last post by:
I would like to use an indexed property to access my private array of user controls. If I don't use an indexed property, the property will show up in my Properties Window during development. Is...
9
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private...
1
by: shapper | last post by:
Hello, I created a user control (.ascx) with a property as follows: Private _Messages As Generic.List(Of String) Public Property Messages() As Generic.List(Of String) Get Return _Messages...
1
by: shapper | last post by:
Hello, I have a class where I created various controls. One of the controls have a property which is a generic list of WebControl. Then in web site page I have something like: Dim a As New...
1
by: shapper | last post by:
Hello, I am creating a control which I will compile in a class. I am having problems when I use a property in the View State: ' Items <Bindable(True), Category("Data"), DefaultValue(""),...
3
by: shapper | last post by:
Hello, Is there a difference between defining a control property in the following two ways: ' Items ... Private _Items As Generic.List(Of ListItem) = New Generic.List(Of ListItem) ****...
1
by: dwillis | last post by:
ok will try again on this forum to bee clear i'm using vb.net 2005. so on to the problem i've search the net extensivly and can not find a clear example on how to acomplish what i'm trying to do....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.