public static bool IsBrowsable(object source, string propertyName) { if (source == null || string.IsNullOrEmpty(propertyName)) { return(false); } return(SFClass.IsBrowsable(SFClass.GetPropertyInfo(source, propertyName))); }
public static string Category(object source, string propertyName) { if (source == null || string.IsNullOrEmpty(propertyName)) { return("Misc"); } return(SFClass.Category(SFClass.GetPropertyInfo(source, propertyName))); }
public static void SetPropertyValue(object source, string propertyName, object value) { if (source == null || value == null || string.IsNullOrEmpty(propertyName)) { return; } PropertyInfo propertyInfo = SFClass.GetPropertyInfo(source, propertyName); if (!(propertyInfo != (PropertyInfo)null)) { return; } try { if (propertyInfo.PropertyType == value.GetType()) { if (value.GetType().IsGenericType) { object obj = propertyInfo.GetValue(source); IList list = (IList)value; MethodInfo method = obj.GetType().GetMethod("Add"); obj.GetType().GetMethod("Clear").Invoke(obj, (object[])null); for (int index = 0; index < list.Count; ++index) { method.Invoke(obj, new object[1] { list[index] }); } } else { propertyInfo.SetValue(source, value); } } else { try { propertyInfo.SetValue(source, SFClass.ValueAs(propertyInfo.PropertyType, value.ToString())); } catch { } } } catch { } }
public static T GetPropertyValue <T>(object source, string propertyName) { if (source == null || string.IsNullOrEmpty(propertyName)) { return(default(T)); } PropertyInfo propertyInfo = SFClass.GetPropertyInfo(source, propertyName); if (propertyInfo != (PropertyInfo)null) { try { return((T)propertyInfo.GetValue(source)); } catch { } } return(default(T)); }