Пример #1
0
        internal object GetValue(Type type, int level)
        {
            PacketException.VerifyRecursionError(ref level);
            var info = Cache.GetConverterOrInfo(this.converters, type, out var converter);

            return(info == null
                ? converter.GetObjectChecked(this.block, true)
                : this.GetValueMatch(type, level, info));
        }
Пример #2
0
 internal object GetValueMatch(Type valueType, int level, Info valueInfo)
 {
     PacketException.VerifyRecursionError(ref level);
     return(valueInfo.To switch
     {
         InfoFlags.Reader => this,
         InfoFlags.RawReader => new PacketRawReader(this),
         InfoFlags.Collection => this.GetValueCollection(level, valueInfo),
         InfoFlags.Enumerable => this.GetValueEnumerable(level, valueInfo),
         InfoFlags.Dictionary => this.GetValueDictionary(level, valueInfo),
         _ => this.GetValueDefault(valueType, level),
     });
Пример #3
0
        private static Token GetToken(ConverterDictionary converters, object value, int level)
        {
            PacketException.VerifyRecursionError(ref level);
            if (value == null)
            {
                return(Token.Empty);
            }
            var type = value.GetType();
            var info = Cache.GetConverterOrInfo(converters, type, out var converter);

            return(info == null ? new Value(converter.GetBytesChecked(value)) : GetTokenMatch(converters, value, level, info));
        }
Пример #4
0
 private static Token GetTokenMatch(ConverterDictionary converters, object value, int level, Info valueInfo)
 {
     PacketException.VerifyRecursionError(ref level);
     return(valueInfo.From switch
     {
         InfoFlags.Writer => ((PacketWriter)value).token,
         InfoFlags.RawWriter => new Value(((PacketRawWriter)value).stream.ToArray()),
         InfoFlags.Bytes => new Value(((ICollection <byte>)value).ToBytes()),
         InfoFlags.SBytes => new Value(((ICollection <sbyte>)value).ToBytes()),
         InfoFlags.Enumerable => GetTokenEnumerable(converters, value, level, valueInfo),
         InfoFlags.Dictionary => GetTokenDictionary(converters, value, level, valueInfo),
         InfoFlags.Expando => GetTokenExpando(converters, value, level),
         _ => GetTokenDefault(converters, value, level, valueInfo),
     });