GetGlobalConverter() public method

public GetGlobalConverter ( Type type ) : ISaveGameConverter
type System.Type
return ISaveGameConverter
Exemplo n.º 1
0
        object DeserializeObject(Type expectedType)
        {
            if (expectedType != null && m_globalConverters != null)
            {
                var conv = m_globalConverters.GetGlobalConverter(expectedType);

                if (conv != null)
                {
                    var ob = _DeserializeObject(conv.OutputType);

                    if (ob == null)
                    {
                        return(null);
                    }

                    return(conv.ConvertFromSerializable(ob));
                }
            }

            return(_DeserializeObject(expectedType));
        }
Exemplo n.º 2
0
        void SerializeObject(object ob, Type containerType)
        {
            if (ob == null)
            {
                m_writer.WriteNull();
                return;
            }

            var type = ob.GetType();

            if (m_globalConverters != null)
            {
                var globalConverter = m_globalConverters.GetGlobalConverter(type);
                if (globalConverter != null)
                {
                    ob = globalConverter.ConvertToSerializable(ob);
                    SerializeObject(ob, containerType);
                    return;
                }
            }

            bool writeType = !type.IsValueType && type != containerType;

            var typeInfo = TypeInfo.GetTypeInfo(type);

            switch (typeInfo.TypeClass)
            {
            case TypeClass.Undefined:
                throw new Exception();

            case TypeClass.Basic:
                m_writer.WriteValue(ob);
                break;

            case TypeClass.Enum:
                if (writeType)
                {
                    throw new Exception();
                }

                var value = typeInfo.TypeConverter.ConvertToInvariantString(ob);
                m_writer.WriteValue(value);

                break;

            case TypeClass.Convertable:
                if (writeType)
                {
                    throw new Exception();
                }

                WriteConvertable(ob, typeInfo);
                break;

            case TypeClass.Array:
            case TypeClass.List:
            case TypeClass.GenericList:
                if (writeType)
                {
                    throw new Exception();
                }

                WriteIEnumerable(ob, typeInfo);
                break;

            case TypeClass.GenericDictionary:
                WriteGenericDictionary(ob, typeInfo, writeType);
                break;

            case TypeClass.Dictionary:
                throw new NotImplementedException();

            case TypeClass.GameObject:
                WriteGameObject(ob, typeInfo, writeType);
                break;

            case TypeClass.Serializable:
                WriteSerializable(ob, typeInfo, writeType);
                break;

            default:
                throw new NotImplementedException();
            }
        }