Example #1
0
        protected IDictionary CreateDictionaryFromMapping(DictionaryMapping mapping)
        {
            if (MappingRegistry.TypeMapper.TypeAnalyzer.IsGenericDictionary(mapping.Type))
            {
                return(TypeCreator.CreateDictionary(mapping.KeyType, mapping.ValueType));
            }

            return((IDictionary)TypeCreator.Instantiate(mapping.Type));
        }
Example #2
0
        protected IList CreateCollectionFromMapping(CollectionMapping mapping, int count)
        {
            if (mapping.IsArray)
            {
                return(TypeCreator.CreateFixedCollection(mapping.Type, count));
            }

            if (MappingRegistry.TypeMapper.TypeAnalyzer.IsGenericCollection(mapping.Type))
            {
                return(TypeCreator.CreateList(mapping.CollectionType));
            }

            return((IList)TypeCreator.Instantiate(mapping.Type));
        }
Example #3
0
        protected virtual object DeserializeDynamicTypeData(TDeserializeState state)
        {
            var dynamicTypeName = GetDynamicTypeNameFromState(state);
            var instanceType    = TypeCreator.LoadType(dynamicTypeName);
            var dataState       = GetDynamicTypeDataFromState(state);

            if (MappingRegistry.TypeMapper.TypeAnalyzer.IsPrimitiveType(instanceType))
            {
                return(DeserializePrimitive(instanceType, dataState));
            }

            var instance    = TypeCreator.Instantiate(instanceType);
            var typeMapping = MappingRegistry.GetMappingFor(instanceType);

            Deserialize(typeMapping.InternalMappings, instance, dataState);

            return(instance);
        }
Example #4
0
        protected virtual void DeserializeNestedObject <T>(NestedMapping nestedMapping, T instance, TDeserializeState state)
        {
            if (IsObjectNull(state))
            {
                nestedMapping.SetValue(instance, null);
                return;
            }

            if (nestedMapping.IsDynamicType)
            {
                var dynamicInstance = DeserializeDynamicTypeData(state);
                nestedMapping.SetValue(instance, dynamicInstance);
                return;
            }

            var childInstance = TypeCreator.Instantiate(nestedMapping.Type);

            nestedMapping.SetValue(instance, childInstance);
            Deserialize(nestedMapping.InternalMappings, childInstance, state);
        }
Example #5
0
        protected virtual object DeserializeDictionaryKey(DictionaryMapping mapping, TDeserializeState state)
        {
            if (IsDataNull(state))
            {
                return(null);
            }

            if (mapping.IsKeyDynamicType)
            {
                return(DeserializeDynamicTypeData(state));
            }

            if (mapping.KeyMappings.Count > 0)
            {
                var keyInstance = TypeCreator.Instantiate(mapping.KeyType);
                Deserialize(mapping.KeyMappings, keyInstance, state);
                return(keyInstance);
            }

            return(DeserializePrimitive(mapping.KeyType, state));
        }
Example #6
0
        protected virtual object DeserializeCollectionElement(CollectionMapping mapping, TDeserializeState state)
        {
            if (IsObjectNull(state))
            {
                return(null);
            }

            if (mapping.IsElementDynamicType)
            {
                return(DeserializeDynamicTypeData(state));
            }

            if (mapping.InternalMappings.Count > 0)
            {
                var elementInstance = TypeCreator.Instantiate(mapping.CollectionType);
                Deserialize(mapping.InternalMappings, elementInstance, state);
                return(elementInstance);
            }

            return(DeserializePrimitive(mapping.CollectionType, state));
        }