예제 #1
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)));
        }
예제 #2
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)));
        }