Something like
typeof(AClass).GetProperty("AProperty").GetValue(null, null)
will do. Don't forget to cast to int
.
Documentation link: http://msdn.microsoft.com/en-us/library/b05d59ty.aspx (they've got example with static properties, too.) But if you know exactly AClass
, you can use just AClass.AProperty
.
If you are inside AnotherClass<T>
for T = AClass
, you can refer to it as T
:
typeof(T).GetProperty("AProperty").GetValue(null, null)
This will work if you know for sure that your T
has static property AProperty
. If there is no guarantee that such property exists on any T
, you need to check the return values/exceptions on the way.
If only AClass
is interesting for you, you can use something like
if (typeof(T) == typeof(AClass))
n = AClass.AProperty;
else
???