コード例 #1
0
ファイル: BinarySerializable.cs プロジェクト: wuxiongbin/XIL
        static ITypeSerialize GetByType(ILRuntimeFieldInfo fieldInfo)
        {
            if (FieldInfoTypes.TryGetValue(fieldInfo, out var ts))
            {
                return(ts);
            }

            var fieldType = fieldInfo.FieldType;

            if (fieldType is ILRuntimeWrapperType)
            {
                fieldType = ((ILRuntimeWrapperType)fieldType).RealType;
            }

            if (Help.isType(fieldType, typeof(UnityEngine.Object)))
            {
                ts = unityObjectSerialize;
            }
            else if (Help.isDictionaryType(fieldType))
            {
                ts = new DictionaryType(fieldType, fieldInfo);
            }
            else
            {
                bool isListType = false;
                if (fieldType.IsArray || (isListType = Help.isListType(fieldType)))
                {
                    int    arrayCount  = 0;
                    string elementType = null;

                    ILRuntimeFieldInfo ilFieldInfo = (ILRuntimeFieldInfo)fieldInfo;
                    GetElementType(ilFieldInfo.Definition.FieldType, ref arrayCount, out elementType);
                    var et = GetType(elementType);
                    if (et is ILRuntimeType) // 不是热更当中的类型
                    {
                        ts = new HotArrayAnyType(et, isListType, arrayCount);
                    }
                    else
                    {
                        ts = GetByType(fieldType);
                    }
                }
                else
                {
                    ts = GetByType(fieldType);
                }
            }

            FieldInfoTypes.Add(fieldInfo, ts);
            return(ts);
        }
コード例 #2
0
        public void Reset(System.Type elementType, bool isListType, int arrayCount)
        {
            this.elementType = elementType;
            this.isListType  = isListType;
            this.arrayCount  = arrayCount;
            if (arrayCount == 1)
            {
                elementTypeSerialize = BinarySerializable.GetByType(elementType);
            }
            else
            {
                elementTypeSerialize = new HotArrayAnyType(elementType, isListType, arrayCount - 1);
            }

            elementTypeFullName = this.elementType.FullName;
        }