I have created a custom object with several properties that use private
variables. I used an object with properties so I could better control
validation and share the code between applications.
Is it possible to access object properties as if they were in a collection?
I would like to be able to retrieve and update the properties kinda like:
objectinstancename("propertyname")
Can this be done? Do I need to handle this in a differnet manner or add
additional code to allow it?
Thanks in advance.
Ken Tucker [MVP] - 21 Dec 2005 18:06 GMT
Hi,
Take a look at reflection.
http://msdn2.microsoft.com/en-us/library/t0cs7xez.aspx
http://msdn2.microsoft.com/en-us/library/system.reflection.propertyinfo.aspx
Ken
----------------------------
> I have created a custom object with several properties that use private
> variables. I used an object with properties so I could better control
[quoted text clipped - 8 lines]
>
> Thanks in advance.
Chris Dunaway - 21 Dec 2005 19:56 GMT
> Is it possible to access object properties as if they were in a collection?
> I would like to be able to retrieve and update the properties kinda like:
> objectinstancename("propertyname")
Why? Isn't
objectinstancename.propertyname
better than what you propose? You get intellisense and it's fewer
character to type. If you must access using a string, then reflection
will work for that, but it will more typing rather than less and more
prone to errors.
Branco Medeiros - 21 Dec 2005 20:23 GMT
<snip>
> Is it possible to access object properties as if they were in a collection?
> I would like to be able to retrieve and update the properties kinda like:
> objectinstancename("propertyname")
<snip>
VB.Net still supports the good old "CallByName" function:
SomeValue = CallByName(Obj, "PropName", CallType.Get)
HTH.
Regards,
Branco.