I'm calling a generic method in some of my properties (to fill proxy classes made by NHibernate although this is not important right now)
To do this i want he type of the Property and pass this to a method which does it's magic, some of these properties however are "nested" Meaning for example the Address property will have this but the Country property of the Address also has this functionality.
The problem i seem to be getting is that due to the fact the Address getter is triggering the Country Getter, when i call MethodBase.GetCurrentMethod().ReflectedType; in my Country property it returns Address as it's type, eventhough the type o开发者_C百科f the property in question in actually Country.
Here are some code snippets:
public virtual Country Country
{
get
{
_country = Backoffice.Library.Serialization.Reflection.GetPossiblyProxyProperty(MethodBase.GetCurrentMethod().ReflectedType, _country);
return _country;
}
set { _country = value; }
}
I'm pretty clueless as to why this would return the wrong Type, i really would like this to be as generic as possibly, i could ofc just do a typeof(Country) but then i'd have to set that for all my properties which sucks :(
If you're looking for the property's return type, you should use MethodInfo.ReturnType
and not ReflectedType
...
精彩评论