Property path to a string

  • Thread starter Thread starter Noulouk
  • Start date Start date
N

Noulouk

Hi ,

I need a string which is the path of a property in my class.
For example, my property path is :
MyNamespace1.Drawing.Class1.Property1 (found with intellisense) --> I
need to put this to a string

I know how to do with a class:
typeof(MyNamespace1.Drawing.Class1).FullName --> I get the string for
my class path

But i don't know how to do the same for my property ?

thanks in advance for your help.
 
Noulouk,

If you are trying to get all of them for a type, then you can call the
GetProperties method on the Type instance representing the class, and
enumerate through those.

If you are inside your property, then you can call the GetProperty
method, passing the name of the property you are in to get the property info
(but then, one could argue that since you are in the property itself, you
should know the name of it, and don't need reflection to make the call).

If you want a method that doesn't take a property name (like a helper,
for a log), you can get the call stack (through the StackTrace or StackFrame
classes) and then get the MethodInfo representing the method being called
through the GetMethod method.

Hope this helps.
 
Thanks for your answer.
You are right, I'm inside my property but I love intellisense and I hate
to have to rewrite the name of my property in a string.
If I change my property name, error could be thrown.

Hope the intellisense and framework will be upgraded to do such a thing.
 
Back
Top