Пример #1
0
        public static ITypeSerialize GetByType(System.Type type)
        {
            ITypeSerialize ts       = null;
            string         fullname = type.FullName;

            if (AllTypes.TryGetValue(fullname, out ts))
            {
                return(ts);
            }

            if (Help.isType(type, typeof(Object)))
            {
                return(AllTypes[typeof(Object).FullName]);
            }

            if (type.IsArray)
            {
                ts = new ArrayAnyType(type);
                AllTypes.Add(fullname, ts);
            }
            else if (type.IsGenericType && fullname.StartsWith("System.Collections.Generic.List`1[["))
            {
                ts = new ListAnyType(type);
                AllTypes.Add(fullname, ts);
            }
            else
            {
                List <FieldInfo> fieldinfos = Help.GetSerializeField(type);
                ts = new AnyType(type, fieldinfos);
                AllTypes.Add(fullname, ts);
            }

            return(ts);
        }
Пример #2
0
        public static ITypeSerialize GetByType(System.Type type)
        {
            ITypeSerialize ts       = null;
            string         fullname = type.FullName;

            if (AllTypes.TryGetValue(fullname, out ts))
            {
                return(ts);
            }

            if (Help.isType(type, typeof(UnityEngine.Object)))
            {
                ts = unityObjectSerialize;
            }
            else
            {
                if (type.IsEnum)
                {
#if USE_HOT
                    if (type is ILRuntimeType)
                    {
                        ts = new HotEnumTypeSerialize((ILRuntimeType)type);
                    }
                    else
                    {
#endif
                    ts = new EnumTypeSerialize(type);
#if USE_HOT
                }
#endif
                }
                else if (type.IsArray)
                {
                    ts = new ArrayAnyType(type);
                }
                else if (Help.isListType(type))
                {
                    ts = new ListAnyType(type);
                }
                else
                {
                    var atts = type.GetCustomAttributes(typeof(SmartAttribute), false);
                    if (atts != null && atts.Length > 0)
                    {
                        ts = new SmartSerializer(type, new AnyTypeSerialize(type, Help.GetSerializeField(type)));
                    }
                    else
                    {
                        List <FieldInfo> fieldinfos = Help.GetSerializeField(type);
                        ts = new AnyTypeSerialize(type, fieldinfos);
                    }
                }
            }

            AllTypes.Add(fullname, ts);
            return(ts);
        }