public static PropInfo FindProp(object obj, System.Reflection.MemberInfo member) { PropInfo result; if (member is System.Reflection.PropertyInfo) { result = new PropInfo(obj, (System.Reflection.PropertyInfo)member); } else if (member is System.Reflection.FieldInfo) { result = new PropInfo(obj, (System.Reflection.FieldInfo)member); } else { result = null; } return(result); }
public static PropInfo[] GetProps(object obj) { System.Reflection.BindingFlags bindingAttr = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public; System.Type type = obj.GetType(); System.Collections.Generic.List <PropInfo> list = new System.Collections.Generic.List <PropInfo>(); System.Reflection.PropertyInfo[] properties = type.GetProperties(bindingAttr); for (int i = 0; i < properties.Length; i++) { System.Reflection.PropertyInfo prop = properties[i]; list.Add(new PropInfo(obj, prop)); } System.Reflection.FieldInfo[] fields = type.GetFields(bindingAttr); for (int i = 0; i < fields.Length; i++) { System.Reflection.FieldInfo field = fields[i]; list.Add(new PropInfo(obj, field)); } PropInfo[] array = new PropInfo[list.Count]; list.CopyTo(array); return(array); }
public static void SetPropValue(object obj, string name, object value) { PropInfo prop = ReflectionUtils.GetProp(obj, name); prop.Value = value; }
public static object GetPropValue(object obj, string name) { PropInfo prop = ReflectionUtils.GetProp(obj, name); return(prop.Value); }