예제 #1
0
 public static bool IsBrowsable(object source, string propertyName)
 {
     if (source == null || string.IsNullOrEmpty(propertyName))
     {
         return(false);
     }
     return(SFClass.IsBrowsable(SFClass.GetPropertyInfo(source, propertyName)));
 }
예제 #2
0
 public static string Category(object source, string propertyName)
 {
     if (source == null || string.IsNullOrEmpty(propertyName))
     {
         return("Misc");
     }
     return(SFClass.Category(SFClass.GetPropertyInfo(source, propertyName)));
 }
예제 #3
0
        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
            {
            }
        }
예제 #4
0
        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));
        }