在ImageFormat
的名稱,有幾個特性,如Png
,Tiff
等獲取靜態屬性由酒店
現在,給出一個字符串,可以獲取相應的靜態屬性?
下面的代碼
[Test]
public void GetPng()
{
Assert.AreEqual(ImageFormat.Png, GetImageFormat("Png")); //how to construct a GetImageFormat function?
}
在ImageFormat
的名稱,有幾個特性,如Png
,Tiff
等獲取靜態屬性由酒店
現在,給出一個字符串,可以獲取相應的靜態屬性?
下面的代碼
[Test]
public void GetPng()
{
Assert.AreEqual(ImageFormat.Png, GetImageFormat("Png")); //how to construct a GetImageFormat function?
}
static ImageFormat GetImageFormat(string name)
{
return (ImageFormat)typeof(ImageFormat)
.GetProperty(name)
.GetValue(null, null);
}
public static void Main()
{
typeof(ImageFormat).GetProperty("GetPng", BindingFlags.Public |
BindingFlags.Static);
}
PropertyInfo pi = typeof(ImageFormat)
.GetProperty("Png", BindingFlags.Static | BindingFlags.Public);
+1(最佳格式勝) – 2010-07-20 13:50:06