yes but value would be the return value of "Text" and not the object which is the parameter it self.
I mean in C++ you can set a pointer to a Object or Objects Parameter/Method. Becous the Parameter and Method header have a address in the Memory. I need a object who is linkt to the address in the memory. I dont know its possible in C# without using unsafe statement.
If I'm reading this correctly, you want to get a pointer to the actual code behind the property.
The most obvious solution would be to have a delegate, however you cannot have a delegate over a property -- only over methods.
If you really need to get the address of a property, there's no way to do that in C#, safe or unsafe. The concept is actually much more difficult then it would first seem. A "property" actually is just a metadata conecpt -- in IL it's expressed as a get and set method. When loaded into memory and then used a property can actually have 5 different "addresses", the metadata of the property itself, the IL of the getter and setter, and the JITed code for the getter and setter.
If you can refactor what you need, I think using a delegate to an instance method would be your best bet.
But is it possilbe to get a reference object to the Property of the Class without using usafe stuff With Reflection I saw its maybe possible (i dont know how), but they using the Type of the Object as Reference and not the Instance of the Object.
Pointer in c#
elix
http://www.codersource.net/csharp_unsafe_code.html
Peter Nowak (Germany)
yes but value would be the return value of "Text" and not the object which is the parameter it self.
I mean in C++ you can set a pointer to a Object or Objects Parameter/Method. Becous the Parameter and Method header have a address in the Memory. I need a object who is linkt to the address in the memory. I dont know its possible in C# without using unsafe statement.
PropertyInfo prop3 = builden1a.GetType().GetProperty(IsFinished);
this is fine, but it uses the GetType() and takes the Information from the class of builden1a.
I need something like
Property prop3 = builden1a.GetProperty(IsFinished);
Directly form the object builden1a and prop3 is a referenc to the Property "IsFinished" it self and not to the return value.
GoHogs
If I'm reading this correctly, you want to get a pointer to the actual code behind the property.
The most obvious solution would be to have a delegate, however you cannot have a delegate over a property -- only over methods.
If you really need to get the address of a property, there's no way to do that in C#, safe or unsafe. The concept is actually much more difficult then it would first seem. A "property" actually is just a metadata conecpt -- in IL it's expressed as a get and set method. When loaded into memory and then used a property can actually have 5 different "addresses", the metadata of the property itself, the IL of the getter and setter, and the JITed code for the getter and setter.
If you can refactor what you need, I think using a delegate to an instance method would be your best bet.
-Shawn
Thomas Gurtl
[code language=c#]
using System.Reflection;
TestClass foo = ...;
PropertyInfo propertyInfo = typeof(TestClass).GetProperty("Text");
object value = propertyInfo.GetValue(foo, null);
[/code]
David Weller
But is it possilbe to get a reference object to the Property of the Class without using usafe stuff With Reflection I saw its maybe possible (i dont know how), but they using the Type of the Object as Reference and not the Instance of the Object.