internal class BaseItemVO { public string name; public string lockA; }
public static void setValue(Object tar, String name, Object value) { FieldInfo fInfo = tar.GetType().GetField(name); Type type = fInfo.FieldType; if (type==typeof(String)) { //這裏能夠VO中獲取字段的類型 Console.WriteLine("this is a string"); } fInfo.SetValue(tar, value); //設置VO中的字段的值 }
代碼雖然一點點,在讀取xml配置的時候很是有用,簡單記錄一下。this