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 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
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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: 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...
| |