2011-03-09 33 views

回答

5

你可以使用Type類的getProperty()方法:)與BindingFlags.Static http://msdn.microsoft.com/en-us/library/kz0a8sxy.aspx

Type t = typeof(MyType); 
PropertyInfo pi = t.GetProperty("Foo"); 
object value = pi.GetValue(null, null); 

class MyType 
{ 
public static string Foo 
{ 
    get { return "bar"; } 
} 
} 
4

使用Type.GetProperty(。然後PropertyInfo.GetValue()。

3

就像你會得到任何其他財產(例如,看看the answer to this question)。

唯一的區別是當您撥打GetValue時,您會提供null作爲目標對象。

相關問題