Esempio n. 1
0
            public SerializationToken SerializeProperty(object graph, PropertyInfo property)
            {
                if (graph == null)
                {
                    return new SerializationToken {
                               TokenType = SerializationTokenType.Null
                    }
                }
                ;
                if (_tokens.ContainsKey(graph))
                {
                    return(_tokens[graph]);
                }
                SerializationToken result = new SerializationToken();

                _tokens[graph] = result;
                ISerializerToken serializerToken = null;

                if (property != null)
                {
                    ConverterAttribute converterAttribute = property.GetCustomAttribute <ConverterAttribute>();
                    if (converterAttribute != null)
                    {
                        serializerToken =
                            (ISerializerToken)Activator.CreateInstance(converterAttribute.SerializerTokenType);
                    }
                }
                if (serializerToken == null)
                {
                    serializerToken = Resolve(graph.GetType());
                }
                serializerToken.Serialize(graph, this, result);
                _tokens[graph] = result;
                return(result);
            }
Esempio n. 2
0
            private ISerializerToken Resolve(Type type)
            {
                ConverterAttribute converterAttribute = type.GetCustomAttribute <ConverterAttribute>();

                if (converterAttribute != null)
                {
                    return((ISerializerToken)Activator.CreateInstance(converterAttribute.SerializerTokenType));
                }
                return(_serializerTokens.First(token => token.IsSupportType(type)));
            }
Esempio n. 3
0
            public DeserializeResult DeserializeProperty(SerializationToken serializationToken, PropertyInfo property)
            {
                if (serializationToken.Type == null)
                {
                    return new DeserializeResult {
                               Use = false
                    }
                }
                ;
                if (serializationToken.TokenType == SerializationTokenType.Null)
                {
                    return(new DeserializeResult());
                }
                if (_reverseTokens.ContainsKey(serializationToken))
                {
                    return new DeserializeResult {
                               Result = _reverseTokens[serializationToken]
                    }
                }
                ;
                DeserializeResult result          = new DeserializeResult();
                ISerializerToken  serializerToken = null;

                if (property != null)
                {
                    ConverterAttribute converterAttribute = property.GetCustomAttribute <ConverterAttribute>();

                    if (converterAttribute != null)
                    {
                        serializerToken =
                            (ISerializerToken)Activator.CreateInstance(converterAttribute.SerializerTokenType);
                    }
                }
                if (serializerToken == null)
                {
                    serializerToken = Resolve(serializationToken.Type);
                }

                serializerToken.Deserialize(serializationToken, this, result);
                if (result.Use)
                {
                    _reverseTokens[serializationToken] = result.Result;
                }
                return(result);
            }