propertyinfo

Is there any way to get the PropertyInfo from the getter of that property?

Is there any way I can get the PropertyInfo for a property from its getter? Like this: public object Foo { get { PropertyInfo propertyInfoForFoo = xxx; ... } } I want to avoid having to hard code the name of the property as a string, as that's tricky to maintain. I'm using .NET 2.0, so I'm hoping for a lin...

Non-static method requires a target in PropertyInfo.SetValue

Ok, so I'm learning about generics and I'm trying to make this thing run, but its keep saying me the same error. Here's the code: public static T Test<T>(MyClass myClass) where T : MyClass2 { var result = default(T); var resultType = typeof(T); var fromClass = myClass.GetType(); var toProperties =...

Reflection failed for properties on anonymous types in Silverlight

Hi, I'm using Silverlight 4 with VS 2010 and trying to do reflection on anonymous type and I got some "Attempt by method '...' to access method '...' failed.". I tried various workarounds for this but I couldn't find and simple ones. class.CallAnonymous("SimpleClass", "HelloFunc", new { strIn = "Boo" }); public void CallA...

Get string name of property using reflection

There is a whole wealth of reflection examples out there that allow you to get either: 1. All properties in a class 2. A single property, provided you know the string name Is there a way (using reflection, TypeDescriptor, or otherwise) to get the string name of a property in a class at runtime, provided all I have is an instance of t...

Reflection on Properties for highest level one

class CBase { object A {get;set;} object B {get;set;} } class CDerived : CBase { object X {get;set} object Y {get;set;} } I'm trying to get first level properties. For the example above, intended properties are X and Y, not A and B. With the following code i'm getting all the properties {A,B,X,Y}. Is there any solution without att...