コード例 #1
0
ファイル: ReflectionHelper.cs プロジェクト: b-y-t-e/sql4js
        public static Dictionary <string, object> ToDictionary(Object Value)
        {
            if (Value == null || MyTypeHelper.IsPrimitive(Value.GetType()))
            {
                return(null);
            }

            Dictionary <string, object> dict = new Dictionary <string, object>();

            foreach (var field in GetFields(Value))
            {
                dict[field.Name] = field.GetValue(Value);
            }

            foreach (var property in GetProperties(Value))
            {
                dict[property.Name] = property.GetValue(Value);
            }

            return(dict);
        }
コード例 #2
0
ファイル: ReflectionHelper.cs プロジェクト: b-y-t-e/sql4js
        public static bool SetValue <DataType>(this Object Item, String PropertyName, DataType Value)
        {
            var lProperty = GetProperty(Item, PropertyName);

            if (lProperty != null)
            {
                var lType1 = lProperty.PropertyType;
                var lType2 = typeof(DataType);
                if (lType1.Equals(lType2) || MyTypeHelper.Is(lType2, lType1))
                {
                    lProperty.SetValue(Item, Value, null);
                }
                else
                {
                    var lNewValue = MyTypeHelper.ConvertTo(Value, lType1);
                    lProperty.SetValue(Item, lNewValue, null);
                }
                return(true);
            }
            return(false);
        }