Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Access Base Class Property values through reflection

$
0
0

Hi,

I am trying to access the property values assigned to base class property through reflection.
Tried with all permutations and combinations with different values (check "Actual line of error"), but tired.
Kindly suggest me some possible solution.

I have put the necessery code and error messages/information.

Error: Object does not match target type
Trace:
 at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
 at System.Reflection.RuntimeMethodInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
 at System.Reflection.RuntimeMethodInfo.GetValue(Object obj, Object[] index)

/* Main  class implementation	*/
List<AcceableClass> accessableClassList = new List<AcceableClass>();
System.Reflection.PropertyInfo[] properties = typeof(T). BaseType.GetProperties();
foreach(System.Reflection.PropertyInfo bp in properties)
{
	if(bp.Name == "BClProperty")
	{
		object[] index = {0};
		bp.GetValues(accessableClassList, index); // Actual line of error
	}
}
public class AcceableClass
{
	public string Key {get; set;}
	public int Expected {get; set;}
	public int Actual {get; set;}
}
public class BaseClass
{
	public List<AcceableClass> BClProperty {get; set;}
}
public class BaseClass
{
	public int MyProperty {get; set;}
}


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>