public UserObjectReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, ThisIsTotesTheRealLegitThingReaderWriterThing thisIsTotesTheRealLegitThingReaderWriterThing, ITypeSerializer <TUserType> userTypeSerializer)
 {
     this.fullTypeBinaryRepresentationCache             = fullTypeBinaryRepresentationCache;
     this.thisIsTotesTheRealLegitThingReaderWriterThing = thisIsTotesTheRealLegitThingReaderWriterThing;
     this.simplifiedType     = TypeSimplifier.SimplifyType(typeof(TUserType));
     this.userTypeSerializer = userTypeSerializer;
 }
예제 #2
0
 public XmlSerializerRepository()
 {
     _typeSimplifier               = new TypeSimplifier();
     Namespace                     = string.Empty;
     NeedsDeserialization          = true;
     CreateNodeForEmptyEnumeration = false;
 }
 public CollectionReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, ThisIsTotesTheRealLegitThingReaderWriterThing thingReaderWriterDispatcherThing, Type userCollectionType)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
     this.thingReaderWriterDispatcherThing  = thingReaderWriterDispatcherThing;
     this.userCollectionType       = userCollectionType;
     this.simplifiedCollectionType = TypeSimplifier.SimplifyType(userCollectionType);
     this.elementType = EnumerableUtilities.GetEnumerableElementType(simplifiedCollectionType);
 }
        public void WriteThing(SomeMemoryStreamWrapperThing dest, object subject)
        {
            var type = TypeSimplifier.SimplifyType((Type)subject);
            var typeBinaryRepresentation = fullTypeBinaryRepresentationCache.GetOrCompute(type);

            dest.Write(fullTypeBinaryRepresentationCache.GetOrCompute(typeof(Type)));
            dest.Write(typeBinaryRepresentation);
        }
예제 #5
0
        public KeyValuePairReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, ThisIsTotesTheRealLegitThingReaderWriterThing thisIsTotesTheRealLegitThingReaderWriterThing, Type userKvpType)
        {
            this.fullTypeBinaryRepresentationCache             = fullTypeBinaryRepresentationCache;
            this.thisIsTotesTheRealLegitThingReaderWriterThing = thisIsTotesTheRealLegitThingReaderWriterThing;

            Trace.Assert(userKvpType.IsGenericType && userKvpType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair <,>));
            this.userKvpType = userKvpType;
            var genericArguments = userKvpType.GetGenericArguments();

            this.userKeyType       = genericArguments[0];
            this.userValueType     = genericArguments[1];
            this.simplifiedKvpType = TypeSimplifier.SimplifyType(userKvpType);
        }
        public object ReadThing(VoxBinaryReader thingReader, Type hintType)
        {
            var type = typeReader.ReadType(thingReader);

            // special cases for type deserialization
            if (type == typeof(TBoolTrue) || type == typeof(TBoolFalse) || type == typeof(TNull))
            {
                // fall straight to reader, ignoring hintType
                return(thingReaderWriterContainer.Get(type).ReadBody(thingReader));
            }
            else if (type == typeof(Type))
            {
                Trace.Assert(hintType == null || typeof(Type).IsAssignableFrom(hintType));
                return(thingReaderWriterContainer.Get(type).ReadBody(thingReader));
            }
            else if (integerTypes.Contains(type))
            {
                var value = thingReaderWriterContainer.Get(type).ReadBody(thingReader);
                if (hintType == null)
                {
                    return(value);
                }
                else if (hintType.IsEnum)
                {
                    return(Convert.ChangeType(value, Enum.GetUnderlyingType(hintType)));
                }
                else
                {
                    return(Convert.ChangeType(value, hintType));
                }
            }

            if (hintType != null)
            {
                var simplifiedType = TypeSimplifier.SimplifyType(hintType);

                if (type == simplifiedType)
                {
                    type = hintType;
                }
                else if (!hintType.IsAssignableFrom(type))
                {
                    logger.Error($"Unable to convert from {type.FullName} to hinted {hintType.FullName}.");
                    throw new InvalidStateException();
                }
            }
            return(thingReaderWriterContainer.Get(type).ReadBody(thingReader));
        }
 protected override void Context()
 {
     _listToSimplify = new List <Type>();
     sut             = new TypeSimplifier();
 }