Exemple #1
0
        private Type ReadType(EncodingKind kind)
        {
            switch (kind)
            {
            case EncodingKind.TypeRef_1Byte:
                return((Type)_referenceMap.GetValue(_reader.ReadByte()));

            case EncodingKind.TypeRef_2Bytes:
                return((Type)_referenceMap.GetValue(_reader.ReadUInt16()));

            case EncodingKind.TypeRef_4Bytes:
                return((Type)_referenceMap.GetValue(_reader.ReadInt32()));

            case EncodingKind.Type:
                int id           = _referenceMap.GetNextReferenceId();
                var assemblyName = this.ReadStringValue();
                var typeName     = this.ReadStringValue();

                Type type;
                if (!_binder.TryGetType(new TypeKey(assemblyName, typeName), out type))
                {
                    throw NoSerializationTypeException(typeName);
                }

                _referenceMap.SetValue(id, type);
                return(type);

            default:
                throw ExceptionUtilities.UnexpectedValue(kind);
            }
        }