public static ConstructorInfo GetConstructorInfo(Type type, params Type[] argsType)
        {
            IEnumerable <ConstructorInfo> constructors = ReflectionsUtils.GetConstructors(type);
            ConstructorInfo result;

            foreach (ConstructorInfo current in constructors)
            {
                ParameterInfo[] parameters = current.GetParameters();
                if (argsType.Length == parameters.Length)
                {
                    int             num         = 0;
                    bool            flag        = true;
                    ParameterInfo[] parameters2 = current.GetParameters();
                    for (int i = 0; i < parameters2.Length; i++)
                    {
                        ParameterInfo parameterInfo = parameters2[i];
                        if (parameterInfo.ParameterType != argsType[num])
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        result = current;
                        return(result);
                    }
                }
            }
            result = null;
            return(result);
        }
        public static ReflectionsUtils.GetDelegate GetGetMethodByReflection(PropertyInfo propertyInfo)
        {
            MethodInfo methodInfo = ReflectionsUtils.GetGetterMethodInfo(propertyInfo);

            Debug.Log("propertyInfo :" + propertyInfo.Name);
            Debug.Log("methodInfo :" + methodInfo.Name);
            return((object source) => methodInfo.Invoke(source, ReflectionsUtils.EmptyObjects));
        }
        public static ReflectionsUtils.SetDelegate GetSetMethodByReflection(PropertyInfo propertyInfo)
        {
            MethodInfo methodInfo = ReflectionsUtils.GetSetterMethodInfo(propertyInfo);

            return(delegate(object source, object value)
            {
                methodInfo.Invoke(source, new object[]
                {
                    value
                });
            });
        }
        internal virtual IDictionary <string, KeyValuePair <Type, ReflectionsUtils.SetDelegate> > SetterValueFactory(Type type)
        {
            IDictionary <string, KeyValuePair <Type, ReflectionsUtils.SetDelegate> > dictionary = new Dictionary <string, KeyValuePair <Type, ReflectionsUtils.SetDelegate> >();

            foreach (PropertyInfo current in ReflectionsUtils.GetProperties(type))
            {
                if (current.CanWrite)
                {
                    MethodInfo setterMethodInfo = ReflectionsUtils.GetSetterMethodInfo(current);
                    if (!setterMethodInfo.IsStatic && setterMethodInfo.IsPublic)
                    {
                        dictionary[this.MapClrMemberNameToJsonFieldName(current.Name)] = new KeyValuePair <Type, ReflectionsUtils.SetDelegate>(current.PropertyType, ReflectionsUtils.GetSetMethod(current));
                    }
                }
            }
            foreach (FieldInfo current2 in ReflectionsUtils.GetFields(type))
            {
                if (!current2.IsInitOnly && !current2.IsStatic && current2.IsPublic)
                {
                    dictionary[this.MapClrMemberNameToJsonFieldName(current2.Name)] = new KeyValuePair <Type, ReflectionsUtils.SetDelegate>(current2.FieldType, ReflectionsUtils.GetSetMethod(current2));
                }
            }
            return(dictionary);
        }
        internal virtual IDictionary <string, ReflectionsUtils.GetDelegate> GetterValueFactory(Type type)
        {
            IDictionary <string, ReflectionsUtils.GetDelegate> dictionary = new Dictionary <string, ReflectionsUtils.GetDelegate>();

            foreach (PropertyInfo current in ReflectionsUtils.GetProperties(type))
            {
                if (current.CanRead && current.CanWrite)
                {
                    MethodInfo getterMethodInfo = ReflectionsUtils.GetGetterMethodInfo(current);
                    if (!getterMethodInfo.IsStatic && getterMethodInfo.IsPublic)
                    {
                        dictionary[this.MapClrMemberNameToJsonFieldName(current.Name)] = ReflectionsUtils.GetGetMethod(current);
                    }
                }
            }
            foreach (FieldInfo current2 in ReflectionsUtils.GetFields(type))
            {
                if (!current2.IsStatic && current2.IsPublic)
                {
                    dictionary[this.MapClrMemberNameToJsonFieldName(current2.Name)] = ReflectionsUtils.GetGetMethod(current2);
                }
            }
            return(dictionary);
        }
 internal virtual ReflectionsUtils.ConstructorDelegate ContructorDelegateFactory(Type key)
 {
     return(ReflectionsUtils.GetContructor(key, (!key.IsArray) ? PocoJsonSerializerStrategy.EmptyTypes : PocoJsonSerializerStrategy.ArrayConstructorParameterTypes));
 }
        public virtual object DeserializeObject(object value, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            string text = value as string;
            object result;

            if (type == typeof(Guid) && string.IsNullOrEmpty(text))
            {
                result = default(Guid);
            }
            else if (value == null)
            {
                result = null;
            }
            else
            {
                object obj = null;
                if (text != null)
                {
                    if (text.Length != 0)
                    {
                        if (type.IsEnum)
                        {
                            return(Enum.Parse(type, text));
                        }
                        if (type == typeof(DateTime) || (ReflectionsUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTime)))
                        {
                            result = DateTime.ParseExact(text, PocoJsonSerializerStrategy.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);

                            return(result);
                        }
                        if (type == typeof(DateTimeOffset) || (ReflectionsUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTimeOffset)))
                        {
                            result = DateTimeOffset.ParseExact(text, PocoJsonSerializerStrategy.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
                            return(result);
                        }
                        if (type == typeof(Guid) || (ReflectionsUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(Guid)))
                        {
                            result = new Guid(text);
                            return(result);
                        }
                        if (type == typeof(Uri))
                        {
                            result = new Uri(text);
                            return(result);
                        }
                        result = text;
                        return(result);
                    }
                    else
                    {
                        if (type == typeof(Guid))
                        {
                            obj = default(Guid);
                        }
                        else if (ReflectionsUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(Guid))
                        {
                            obj = null;
                        }
                        else
                        {
                            obj = text;
                        }
                        if (!ReflectionsUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(Guid))
                        {
                            result = text;
                            return(result);
                        }
                    }
                }
                else if (value is bool)
                {
                    result = value;
                    return(result);
                }
                bool flag  = value is long;
                bool flag2 = value is double;
                if ((flag && type == typeof(long)) || (flag2 && type == typeof(double)))
                {
                    result = value;
                }
                else if ((flag2 && type != typeof(double)) || (flag && type != typeof(long)))
                {
                    obj = ((!typeof(IConvertible).IsAssignableFrom(type)) ? value : Convert.ChangeType(value, type, CultureInfo.InvariantCulture));
                    if (ReflectionsUtils.IsNullableType(type))
                    {
                        result = ReflectionsUtils.ToNullableType(obj, type);
                    }
                    else
                    {
                        result = obj;
                    }
                }
                else
                {
                    IDictionary <string, object> dictionary = value as IDictionary <string, object>;
                    if (dictionary != null)
                    {
                        IDictionary <string, object> dictionary2 = dictionary;
                        if (ReflectionsUtils.IsTypeDictionary(type))
                        {
                            Type[] genericTypeArguments = ReflectionsUtils.GetGenericTypeArguments(type);
                            Type   type2 = genericTypeArguments[0];
                            Type   type3 = genericTypeArguments[1];
                            Type   key   = typeof(Dictionary <, >).MakeGenericType(new Type[]
                            {
                                type2,
                                type3
                            });
                            IDictionary dictionary3 = (IDictionary)this.ConstructorCache[key](null);
                            foreach (KeyValuePair <string, object> current in dictionary2)
                            {
                                dictionary3.Add(current.Key, this.DeserializeObject(current.Value, type3));
                            }
                            obj = dictionary3;
                        }
                        else if (type == typeof(object))
                        {
                            obj = value;
                        }
                        else
                        {
                            obj = this.ConstructorCache[type](null);
                            foreach (KeyValuePair <string, KeyValuePair <Type, ReflectionsUtils.SetDelegate> > current2 in this.SetCache[type])
                            {
                                object value2;
                                if (dictionary2.TryGetValue(current2.Key, out value2))
                                {
                                    value2 = this.DeserializeObject(value2, current2.Value.Key);
                                    current2.Value.Value(obj, value2);
                                }
                            }
                        }
                    }
                    else
                    {
                        IList <object> list = value as IList <object>;
                        if (list != null)
                        {
                            IList <object> list2 = list;
                            IList          list3 = null;
                            if (type.IsArray)
                            {
                                list3 = (IList)this.ConstructorCache[type](new object[]
                                {
                                    list2.Count
                                });
                                int num = 0;
                                foreach (object current3 in list2)
                                {
                                    list3[num++] = this.DeserializeObject(current3, type.GetElementType());
                                }
                            }
                            else if (ReflectionsUtils.IsTypeGenericeCollectionInterface(type) || ReflectionsUtils.IsAssignableFrom(typeof(IList), type))
                            {
                                Type type4 = ReflectionsUtils.GetGenericTypeArguments(type)[0];
                                Type key2  = typeof(List <>).MakeGenericType(new Type[]
                                {
                                    type4
                                });
                                list3 = (IList)this.ConstructorCache[key2](new object[]
                                {
                                    list2.Count
                                });
                                foreach (object current4 in list2)
                                {
                                    list3.Add(this.DeserializeObject(current4, type4));
                                }
                            }
                            obj = list3;
                        }
                    }
                    result = obj;
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        public static object DeserializeObject(string json, Type type, IJsonSerializerStrategy jsonSerializerStrategy)
        {
            object obj = SimpleJsonTool.DeserializeObject(json);

            return((type != null && (obj == null || !ReflectionsUtils.IsAssignableFrom(obj.GetType(), type))) ? (jsonSerializerStrategy ?? SimpleJsonTool.CurrentJsonSerializerStrategy).DeserializeObject(obj, type) : obj);
        }
 public static ReflectionsUtils.SetDelegate GetSetMethod(FieldInfo fieldInfo)
 {
     return(ReflectionsUtils.GetSetMethodByReflection(fieldInfo));
 }
Exemplo n.º 10
0
 public static ReflectionsUtils.SetDelegate GetSetMethod(PropertyInfo propertyInfo)
 {
     return(ReflectionsUtils.GetSetMethodByReflection(propertyInfo));
 }
Exemplo n.º 11
0
        public static ReflectionsUtils.ConstructorDelegate GetConstructorByReflection(Type type, params Type[] argsType)
        {
            ConstructorInfo constructorInfo = ReflectionsUtils.GetConstructorInfo(type, argsType);

            return((constructorInfo != null) ? ReflectionsUtils.GetConstructorByReflection(constructorInfo) : null);
        }
Exemplo n.º 12
0
 public static ReflectionsUtils.ConstructorDelegate GetContructor(Type type, params Type[] argsType)
 {
     return(ReflectionsUtils.GetConstructorByReflection(type, argsType));
 }
Exemplo n.º 13
0
 public static ReflectionsUtils.ConstructorDelegate GetContructor(ConstructorInfo constructorInfo)
 {
     return(ReflectionsUtils.GetConstructorByReflection(constructorInfo));
 }