Exemplo n.º 1
0
        private SerializeInstanceInfo GetUninitializedTypeInfo(SerializeTypeEnum type)
        {
            SerializeInstanceInfo info = null;

            switch (type)
            {
            case SerializeTypeEnum.Null:
            case SerializeTypeEnum.Byte:
            case SerializeTypeEnum.Bool:
            case SerializeTypeEnum.Int16:
            case SerializeTypeEnum.Int32:
            case SerializeTypeEnum.Int64:
            case SerializeTypeEnum.UInt16:
            case SerializeTypeEnum.UInt32:
            case SerializeTypeEnum.UInt64:
            case SerializeTypeEnum.Float:
            case SerializeTypeEnum.Double:
            case SerializeTypeEnum.String:
            {
                info = new PrimitiveTypeInfo(type, this);
            }
            break;

            case SerializeTypeEnum.Enum:
            {
                info = new EnumInfo();
            }
            break;

            case SerializeTypeEnum.ArrayOfPrimitives:
            {
                info = new ArrayOfPrimitivesInfo(this);
            }
            break;

            case SerializeTypeEnum.ArrayOfByref:
            {
                info = new ArrayOfByRefInfo(this);
            }
            break;

            case SerializeTypeEnum.Custom:
            {
                info = new CustomInfo(this);
            }
            break;

            case SerializeTypeEnum.SerializedYet:
            {
                info = new SerializedYetInfo(-1);
            }
            break;

            default:
                break;
            }
            return(info);
        }
Exemplo n.º 2
0
        private SerializeInstanceInfo GetInstanceInfo(object obj)
        {
            if (obj is null)
            {
                return(null);
            }

            var t = obj.GetType();
            SerializeInstanceInfo info;

            if (t.IsPrimitive || t == typeof(string))
            {
                info = new PrimitiveTypeInfo(obj, this);
            }
            else if (t.IsEnum)
            {
                info = new EnumInfo(obj);
            }
            else if (t.IsArray)
            {
                var arr = obj as Array;

                if (SerializeTypes.GetTypeEnum(t.GetElementType()) != SerializeTypeEnum.Custom)
                {
                    info = new ArrayOfPrimitivesInfo(arr, this);
                }
                else
                {
                    info = new ArrayOfByRefInfo(arr, this);
                }
            }
            else
            {
                info = new CustomInfo(obj, this);
            }

            // _serializedInstances.Add(info);
            return(info);
        }