Ejemplo n.º 1
0
        ///<summary>
        ///Assigns all fields an id if possible.  Fields are grouped by name and for each group, if there
        ///is a single id, all fields in the group are assigned this id.  If the group has multiple ids,
        ///an error is reported.
        ///</summary>
        protected ISet <String> InferThriftFieldIds()
        {
            ISet <String> fieldsWithConflictingIds = new HashSet <String>();

            // group fields by explicit name or by name extracted from field, method or property
            var fieldsByExplicitOrExtractedName = this._fields.GroupBy(FieldMetadata.GetOrExtractThriftFieldName());

            InferThriftFieldIds(fieldsByExplicitOrExtractedName, fieldsWithConflictingIds);

            // group fields by name extracted from field, method or property
            // this allows thrift name to be set explicitly without having to duplicate the name on getters and setters
            // todo should this be the only way this works?
            var fieldsByExtractedName = _fields.GroupBy(FieldMetadata.ExtractThriftFieldName());

            InferThriftFieldIds(fieldsByExtractedName, fieldsWithConflictingIds);

            return(fieldsWithConflictingIds);
        }
Ejemplo n.º 2
0
        protected String ExtractFieldName(short id, IEnumerable <FieldMetadata> fields)
        {
            // get the names used by these fields
            var names = fields.Select(FieldMetadata.ExtractThriftFieldName()).Where(n => !String.IsNullOrWhiteSpace(n)).Distinct();

            String name;

            if (names.Any())
            {
                if (names.Count() > 1)
                {
                    _metadataErrors.AddWarning($"Thrift class {this.StructName} field {id} has multiple names {String.Join(", ", names)}");
                }
                name = names.First();
            }
            else
            {
                throw new ThriftyException("cant get name from FieldMetadata collection");
            }
            return(name);
        }