E
ESPNSTI
Hi,
I'm looking some way to get the name of a specific property of an object.
For example instead of having to specify the property name as a literal like
this:
MyObject obj = New MyObject();
DoSomethingWithAProperty(obj, "MyProperty");
I would like to be able to look up the property name by doing somehing like
this:
MyObject obj = New MyObject();
DoSomethingWithAProperty(obj, NameOf(obj.MyProperty));
The NameOf() method (which doesn't exist) is what I'm looking for.
The main reason I don't want to use literals is to reduce bugs if a
property's name is changed.
Thanks,
Erik
I'm looking some way to get the name of a specific property of an object.
For example instead of having to specify the property name as a literal like
this:
MyObject obj = New MyObject();
DoSomethingWithAProperty(obj, "MyProperty");
I would like to be able to look up the property name by doing somehing like
this:
MyObject obj = New MyObject();
DoSomethingWithAProperty(obj, NameOf(obj.MyProperty));
The NameOf() method (which doesn't exist) is what I'm looking for.
The main reason I don't want to use literals is to reduce bugs if a
property's name is changed.
Thanks,
Erik