473,396 Members | 2,061 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,396 software developers and data experts.

Reflection (I think)

I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be able
to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston
Nov 21 '05 #1
6 827
Hi,

Test class

Public Class MyTestClass

Dim mstrA As String

Dim mstrB As String

Dim mintC As Integer

Public Property A() As String

Get

Return mstrA

End Get

Set(ByVal Value As String)

mstrA = Value

End Set

End Property

Public Property B() As String

Get

Return mstrB

End Get

Set(ByVal Value As String)

mstrB = Value

End Set

End Property

Public Property C() As Integer

Get

Return mintC

End Get

Set(ByVal Value As Integer)

mintC = Value

End Set

End Property

End Class

To get values

Dim c As New MyTestClass

c.A = "a"

c.B = "B"

c.C = 100

Dim t As Type = c.GetType

For Each pi As Reflection.PropertyInfo In t.GetProperties

Debug.WriteLine(String.Format("{0} {1} {2}", pi.Name, _

pi.PropertyType.FullName, pi.GetValue(c, Nothing)))

Next

Ken

----------------------

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be able
to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston
Nov 21 '05 #2
Good clean Answer Ken !

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
Hi,

Test class

Public Class MyTestClass

Dim mstrA As String

Dim mstrB As String

Dim mintC As Integer

Public Property A() As String

Get

Return mstrA

End Get

Set(ByVal Value As String)

mstrA = Value

End Set

End Property

Public Property B() As String

Get

Return mstrB

End Get

Set(ByVal Value As String)

mstrB = Value

End Set

End Property

Public Property C() As Integer

Get

Return mintC

End Get

Set(ByVal Value As Integer)

mintC = Value

End Set

End Property

End Class

To get values

Dim c As New MyTestClass

c.A = "a"

c.B = "B"

c.C = 100

Dim t As Type = c.GetType

For Each pi As Reflection.PropertyInfo In t.GetProperties

Debug.WriteLine(String.Format("{0} {1} {2}", pi.Name, _

pi.PropertyType.FullName, pi.GetValue(c, Nothing)))

Next

Ken

----------------------

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be able to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston

Nov 21 '05 #3
Thanks. I think I can figure it out from what you've given me.

"Ken Tucker [MVP]" wrote:
Hi,

Test class

Public Class MyTestClass

Dim mstrA As String

Dim mstrB As String

Dim mintC As Integer

Public Property A() As String

Get

Return mstrA

End Get

Set(ByVal Value As String)

mstrA = Value

End Set

End Property

Public Property B() As String

Get

Return mstrB

End Get

Set(ByVal Value As String)

mstrB = Value

End Set

End Property

Public Property C() As Integer

Get

Return mintC

End Get

Set(ByVal Value As Integer)

mintC = Value

End Set

End Property

End Class

To get values

Dim c As New MyTestClass

c.A = "a"

c.B = "B"

c.C = 100

Dim t As Type = c.GetType

For Each pi As Reflection.PropertyInfo In t.GetProperties

Debug.WriteLine(String.Format("{0} {1} {2}", pi.Name, _

pi.PropertyType.FullName, pi.GetValue(c, Nothing)))

Next

Ken

----------------------

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be able
to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston

Nov 21 '05 #4
You might be interested in what I finally ended up with where:

'TagEdit is my class object name
' Artist is a property that returns a data structure of type TagEdit.TextData

Dim f as TagEdit = New TagEdit()
dim t as TagEdit.TxtData

Dim mymethod As MethodInfo =
GetType(TagEdit).GetProperty_("Artist").GetGetMeth od

t = CType(mymethod.Invoke(f, Nothing), TagEdit.TxtData)

'It works! Now all I've got to do is figure out how to do this with
properties that have overloads with different input parameters..use Binding
flags I think!

"Ken Tucker [MVP]" wrote:
Hi,

Test class

Public Class MyTestClass

Dim mstrA As String

Dim mstrB As String

Dim mintC As Integer

Public Property A() As String

Get

Return mstrA

End Get

Set(ByVal Value As String)

mstrA = Value

End Set

End Property

Public Property B() As String

Get

Return mstrB

End Get

Set(ByVal Value As String)

mstrB = Value

End Set

End Property

Public Property C() As Integer

Get

Return mintC

End Get

Set(ByVal Value As Integer)

mintC = Value

End Set

End Property

End Class

To get values

Dim c As New MyTestClass

c.A = "a"

c.B = "B"

c.C = 100

Dim t As Type = c.GetType

For Each pi As Reflection.PropertyInfo In t.GetProperties

Debug.WriteLine(String.Format("{0} {1} {2}", pi.Name, _

pi.PropertyType.FullName, pi.GetValue(c, Nothing)))

Next

Ken

----------------------

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be able
to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston

Nov 21 '05 #5
If you have 150 properties, you're probably going to have more in the
future. I suggest you ditch them all and try something different. Perhaps a
key/value pattern.

AddProperty(key as string, value as string)
GetProperty(key as string)
GetProperty(index as integer)
RemoveProperty(key as string)

--
Jonathan Allen
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be able to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston

Nov 21 '05 #6
Interesting suggestion but I'm not sure how to implement this. I assume this
code goes in the class but not sure how set/get each property in my
application that uses the class with this technique.

"Jonathan Allen" wrote:
If you have 150 properties, you're probably going to have more in the
future. I suggest you ditch them all and try something different. Perhaps a
key/value pattern.

AddProperty(key as string, value as string)
GetProperty(key as string)
GetProperty(index as integer)
RemoveProperty(key as string)

--
Jonathan Allen
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com...
I have a class that has 150 properties and I would like to, in additon to
calling the properties like myclass.property1, I would also like to be

able
to call the property using an index string. For example;

Public Class myClass

public property prop1()

end property

end class

Public property getProperty(prop1index)
'What code can I use here to call property "Prop1"
end property

end class
Dennis in Houston


Nov 21 '05 #7

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

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
7
by: sujit | last post by:
Hi All, I have query regarding "C++ and Reflection". I could not get sufficient information from net on this topic. Does C++ support reflection or any features similar to some other languages...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
2
by: Mark | last post by:
Am I out of my mind if I use Reflection everytime someone logs into our site to get and track the current Major/Minor/Build/Revision version that the person is viewing our site through? This...
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
17
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.