Get name of property as a string

Posted by Jim C on Stack Overflow See other posts from Stack Overflow or by Jim C
Published on 2010-05-12T16:12:06Z Indexed on 2010/05/12 16:24 UTC
Read the original article Hit count: 171

Filed under:
|
|

I'm trying to improve the maintainability of some code involving reflection. The app has a .NET Remoting interface exposing (among other things) a method called Execute for accessing parts of the app not included in its published remote interface.

Here is how the app designates properties (a static one in this example) which are meant to be accessible via Execute:

RemoteMgr.ExposeProperty("SomeSecret", typeof(SomeClass), "SomeProperty");

So a remote user could call:

string response = remoteObject.Execute("SomeSecret");

and the app would use reflection to find SomeClass.SomeProperty and return its value as a string.

Unfortunately, if someone renames SomeProperty and forgets to change the 3rd parm of ExposeProperty(), it breaks this mechanism.

I need to the equivalent of:

SomeClass.SomeProperty.GetTheNameOfThisPropertyAsAString()

to use as the 3rd parm in ExposeProperty so refactoring tools would take care of renames.

Is there a way to do this? Thanks in advance.

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection