Пример #1
0
        public Codec CreateCodec(Protocol protocol, CodecInfoWithAttributes codecInfoWithAttrs)
        {
            Type type = codecInfoWithAttrs.Info.type;

            if (!type.IsGenericType || !ReferenceEquals(type.GetGenericTypeDefinition(), typeof(Dictionary <,>)))
            {
                return(null);
            }
            Type type2         = type.GetGenericArguments()[0];
            Type type3         = type.GetGenericArguments()[1];
            bool optional      = false;
            bool varied        = false;
            bool optionalValue = false;
            bool variedValue   = false;

            if (codecInfoWithAttrs.IsAttributePresent <ProtocolDictionaryAttribute>())
            {
                ProtocolDictionaryAttribute attribute = codecInfoWithAttrs.GetAttribute <ProtocolDictionaryAttribute>();
                optional      = attribute.OptionalKey;
                varied        = attribute.VariedKey;
                optionalValue = attribute.OptionalValue;
                variedValue   = attribute.VariedValue;
            }
            return(new DictionaryCodec(type, new CodecInfoWithAttributes(type2, optional, varied), new CodecInfoWithAttributes(type3, optionalValue, variedValue)));
        }
Пример #2
0
        public Codec CreateCodec(Protocol protocol, CodecInfoWithAttributes codecInfoWithAttrs)
        {
            Type type = codecInfoWithAttrs.Info.type;

            if (!type.IsGenericType || !ReferenceEquals(type.GetGenericTypeDefinition(), typeof(List <>)))
            {
                return(null);
            }
            Type type2    = type.GetGenericArguments()[0];
            bool optional = false;
            bool varied   = false;

            if (codecInfoWithAttrs.IsAttributePresent <ProtocolCollectionAttribute>())
            {
                ProtocolCollectionAttribute attribute = codecInfoWithAttrs.GetAttribute <ProtocolCollectionAttribute>();
                optional = attribute.Optional;
                varied   = attribute.Varied;
            }
            return(new ListCodec(type, new CodecInfoWithAttributes(type2, optional, varied)));
        }
Пример #3
0
        public Codec CreateCodec(Protocol protocol, CodecInfoWithAttributes codecInfoWithAttrs)
        {
            Type type = codecInfoWithAttrs.Info.type;

            if (!type.IsArray)
            {
                return(null);
            }
            Type elementType = type.GetElementType();
            bool optional    = false;
            bool varied      = false;

            if (codecInfoWithAttrs.IsAttributePresent <ProtocolCollectionAttribute>())
            {
                ProtocolCollectionAttribute attribute = codecInfoWithAttrs.GetAttribute <ProtocolCollectionAttribute>();
                optional = attribute.Optional;
                varied   = attribute.Varied;
            }
            return(new ArrayCodec(elementType, new CodecInfoWithAttributes(type.GetElementType(), optional, varied)));
        }