示例#1
0
        public static ThriftType Array(IThriftTypeReference valueTypeReference)
        {
            Guard.ArgumentNotNull(valueTypeReference, nameof(valueTypeReference));

            return(new ThriftType(ThriftProtocolType.List, valueTypeReference.CSharpType.MakeArrayType(),
                                  null, valueTypeReference));
        }
示例#2
0
        public static ThriftType List(IThriftTypeReference valueTypeReference)
        {
            Guard.ArgumentNotNull(valueTypeReference, nameof(valueTypeReference));

            var listType = typeof(List <>).MakeGenericType(valueTypeReference.CSharpType);

            return(new ThriftType(ThriftProtocolType.List, listType, null, valueTypeReference));
        }
示例#3
0
        public static ThriftType Set(IThriftTypeReference valueTypeReference)
        {
            Guard.ArgumentNotNull(valueTypeReference, nameof(valueTypeReference));

            var setType = typeof(HashSet <>).MakeGenericType(valueTypeReference.CSharpType);

            return(new ThriftType(ThriftProtocolType.Set, setType, null, valueTypeReference));
        }
示例#4
0
        public static ThriftType Dictionary(IThriftTypeReference keyTypeReference,
                                            IThriftTypeReference valueTypeReference)
        {
            Guard.ArgumentNotNull(keyTypeReference, nameof(keyTypeReference));
            Guard.ArgumentNotNull(valueTypeReference, nameof(valueTypeReference));


            var mapType = typeof(Dictionary <,>).MakeGenericType(keyTypeReference.CSharpType, valueTypeReference.CSharpType);

            return(new ThriftType(ThriftProtocolType.Map, mapType, keyTypeReference, valueTypeReference));
        }
示例#5
0
        private ThriftType(ThriftType underlyingType, Type nullableType)
        {
            this.CSharpType    = nullableType;
            this.UncoercedType = underlyingType;

            this.ProtocolType  = underlyingType.ProtocolType;
            keyTypeReference   = null;
            valueTypeReference = null;
            structMetadata     = null;
            enumMetadata       = underlyingType.enumMetadata;
        }
示例#6
0
        private ThriftType(ThriftStructMetadata structMetadata)
        {
            Guard.ArgumentNotNull(structMetadata, nameof(structMetadata));

            this.ProtocolType   = ThriftProtocolType.Struct;
            this.CSharpType     = structMetadata.StructType;
            keyTypeReference    = null;
            valueTypeReference  = null;
            this.structMetadata = structMetadata;
            this.UncoercedType  = null;
        }
示例#7
0
        private ThriftType(ThriftProtocolType protocolType, Type csharpType)
        {
            Guard.ArgumentNotNull(csharpType, "csharpType");

            this.ProtocolType  = protocolType;
            this.CSharpType    = csharpType;
            keyTypeReference   = null;
            valueTypeReference = null;
            structMetadata     = null;
            this.UncoercedType = null;
        }
示例#8
0
        private ThriftType(ThriftEnumMetadata enumMetadata)
        {
            Guard.ArgumentNotNull(enumMetadata, "enumMetadata");

            this.ProtocolType  = ThriftProtocolType.Enum;
            this.CSharpType    = enumMetadata.EnumType;
            keyTypeReference   = null;
            valueTypeReference = null;
            structMetadata     = null;
            this.enumMetadata  = enumMetadata;
            this.UncoercedType = null;
        }
示例#9
0
        private ThriftType(ThriftProtocolType protocolType,
                           Type javaType,
                           IThriftTypeReference keyTypeReference,
                           IThriftTypeReference valueTypeReference)
        {
            Guard.ArgumentNotNull(javaType, nameof(javaType));
            Guard.ArgumentNotNull(valueTypeReference, nameof(valueTypeReference));


            this.ProtocolType       = protocolType;
            this.CSharpType         = javaType;
            this.keyTypeReference   = keyTypeReference;
            this.valueTypeReference = valueTypeReference;
            this.structMetadata     = null;
            this.UncoercedType      = null;
        }
示例#10
0
        protected override ThriftFieldMetadata BuildField(IEnumerable <FieldMetadata> input)
        {
            short id = -1;
            //IDictionary<String, String> idlAnnotations = null;
            String               name                = null;
            Requiredness         requiredness        = Requiredness.Unspecified;
            bool                 recursive           = false;
            IThriftTypeReference thriftTypeReference = null;

            // process field injections and extractions
            List <IThriftInjection> injections = new List <IThriftInjection>();
            IThriftExtraction       extraction = null;

            foreach (FieldMetadata fieldMetadata in input)
            {
                id           = fieldMetadata.Id;
                name         = fieldMetadata.Name;
                recursive    = fieldMetadata.IsRecursiveReference ?? false;
                requiredness = fieldMetadata.Requiredness;
                //idlAnnotations = fieldMetadata.getIdlAnnotations();
                thriftTypeReference = this.Catalog.GetFieldThriftTypeReference(fieldMetadata);

                FieldInjection fieldInjection = fieldMetadata as FieldInjection;
                if (fieldInjection != null)
                {
                    injections.Add(new ThriftFieldInjection(fieldInjection.Id,
                                                            fieldInjection.Name,
                                                            fieldInjection.Field,
                                                            fieldInjection.Type));
                }
                else if (fieldMetadata is ParameterInjection)
                {
                    ParameterInjection parameterInjection = (ParameterInjection)fieldMetadata;
                    injections.Add(new ThriftParameterInjection(
                                       parameterInjection.Id,
                                       parameterInjection.Name,
                                       parameterInjection.ParameterIndex,
                                       fieldMetadata.CSharpType
                                       ));
                }
                else if (fieldMetadata is FieldExtractor)
                {
                    FieldExtractor fieldExtractor = (FieldExtractor)fieldMetadata;
                    extraction = new ThriftFieldExtractor(
                        fieldExtractor.Id, fieldExtractor.Name,
                        fieldExtractor.Type,
                        fieldExtractor.Field,
                        fieldExtractor.CSharpType);
                }
                else if (fieldMetadata is MethodExtractor)
                {
                    MethodExtractor methodExtractor = (MethodExtractor)fieldMetadata;
                    extraction = new ThriftMethodExtractor(
                        methodExtractor.Id,
                        methodExtractor.Name,
                        methodExtractor.Type,
                        methodExtractor.Method,
                        methodExtractor.CSharpType);
                }
            }

            // add type coercion
            TypeCoercion coercion = null;

            if (!thriftTypeReference.Recursive && thriftTypeReference.Get().IsCoerced)
            {
                coercion = this.Catalog.GetDefaultCoercion(thriftTypeReference.Get().CSharpType);
            }

            if (recursive && requiredness != Requiredness.Optional)
            {
                this.MetadataErrors.AddError($"Struct '{this.StructName}' field '{name}' is recursive but not marked optional");
            }

            ThriftFieldMetadata thriftFieldMetadata = new ThriftFieldMetadata(
                id,
                recursive,
                requiredness,
                //idlAnnotations,
                thriftTypeReference,
                name,
                FieldKind.ThriftField,
                injections,
                extraction: extraction,
                coercion: coercion
                );

            return(thriftFieldMetadata);
        }
示例#11
0
        //private IEnumerable<String> documentation;

        public ThriftFieldMetadata(
            short id,
            bool isRecursiveReference,
            Requiredness requiredness,
            //IEnumerable<KeyValuePair<String, String>> idlAnnotations,
            IThriftTypeReference thriftTypeReference,
            String name,
            FieldKind fieldKind,
            IEnumerable <IThriftInjection> injections       = null,
            ThriftConstructorInjection constructorInjection = null,
            ThriftMethodInjection methodInjection           = null,
            IThriftExtraction extraction = null,
            TypeCoercion coercion        = null
            )
        {
            Guard.ArgumentNotNull(thriftTypeReference, nameof(thriftTypeReference));
            Guard.ArgumentNotNull(fieldKind, nameof(fieldKind));
            Guard.ArgumentNullOrWhiteSpaceString(name, nameof(name));
            Guard.ArgumentNotNull(thriftTypeReference, nameof(thriftTypeReference));
            Guard.ArgumentNullOrWhiteSpaceString(name, nameof(name));
            //Guard.ArgumentNotNull(constructorInjection, nameof(constructorInjection));
            //Guard.ArgumentNotNull(methodInjection, nameof(methodInjection));
            //Guard.ArgumentNotNull(extraction, nameof(extraction));
            //Guard.ArgumentNotNull(coercion, nameof(coercion));

            this.IsRecursiveReference = isRecursiveReference;
            this.Required             = requiredness;
            this._thriftTypeReference = thriftTypeReference;
            this._fieldKind           = fieldKind;
            this.Name                  = name;
            this.Injections            = injections ?? Enumerable.Empty <IThriftInjection>();
            this._constructorInjection = constructorInjection;
            this._methodInjection      = methodInjection;

            this._extraction = extraction;
            this._coercion   = coercion;

            switch (fieldKind)
            {
            case FieldKind.ThriftField:
                Guard.ArgumentCondition(id >= 0, "isLegacyId must be specified on fields with negative IDs", nameof(id));

                break;

            case FieldKind.ThriftUnionId:
                Guard.ArgumentCondition(id == short.MinValue, "thrift union id must be short.MinValue", nameof(id));
                break;
            }

            Guard.ArgumentCondition(injections.Any() ||
                                    extraction != null ||
                                    constructorInjection != null ||
                                    methodInjection != null, "A thrift field must have an injection or extraction point");

            this.Id = id;

            if (extraction != null)
            {
                if (extraction is ThriftFieldExtractor)
                {
                    ThriftFieldExtractor e = (ThriftFieldExtractor)extraction;
                    //this.documentation = ThriftCatalog.getThriftDocumentation(e.getField());
                }
                else if (extraction != null && extraction is ThriftMethodExtractor)
                {
                    ThriftMethodExtractor e = (ThriftMethodExtractor)extraction;
                    //this.documentation = ThriftCatalog.getThriftDocumentation(e.getMethod());
                }
            }

            //this.idlAnnotations = idlAnnotations;
        }
示例#12
0
 public IThriftCodec GetElementCodec(IThriftTypeReference thriftTypeReference)
 {
     return(GetCodec(thriftTypeReference.Get()));
 }