示例#1
0
        private List <EnumTypeValue> BuildValues()
        {
            var values = new List <EnumTypeValue>();

            foreach (var c in _choices)
            {
                var name          = BuilderHelpers.DisambiguateName(Type, c.CSharpName());
                var memberMapping = _typeMapping?.GetForMember(name);
                values.Add(new EnumTypeValue(
                               BuilderHelpers.CreateMemberDeclaration(name, Type, "public", memberMapping?.ExistingMember, _context.TypeFactory),
                               CreateDescription(c),
                               BuilderHelpers.ParseConstant(c.Value, BaseType)));
            }

            return(values);
        }
示例#2
0
        private IEnumerable <ObjectTypeProperty> BuildProperties()
        {
            // WORKAROUND: https://github.com/Azure/autorest.modelerfour/issues/261
            var existingProperties = EnumerateHierarchy()
                                     .Skip(1)
                                     .SelectMany(type => type.Properties)
                                     .Select(p => p.SchemaProperty?.Language.Default.Name)
                                     .ToHashSet();

            foreach (var objectSchema in GetCombinedSchemas())
            {
                foreach (Property property in objectSchema.Properties !)
                {
                    if (existingProperties.Contains(property.Language.Default.Name))
                    {
                        // WORKAROUND: https://github.com/Azure/autorest.modelerfour/issues/261
                        continue;
                    }

                    var name = BuilderHelpers.DisambiguateName(Type, property.CSharpName());
                    SourceMemberMapping?memberMapping = _sourceTypeMapping?.GetForMember(name);
                    bool isNotInput = (objectSchema.IsOutput || objectSchema.IsException) && !objectSchema.IsInput;
                    bool isReadOnly = IsStruct ||
                                      isNotInput ||
                                      property.ReadOnly == true ||
                                      // Required properties of input objects should be readonly
                                      (property.Required == true && objectSchema.IsInputOnly);

                    if (property.IsDiscriminator == true)
                    {
                        // Discriminator properties should be writeable
                        isReadOnly = false;
                    }

                    CSharpType type = _typeFactory.CreateType(
                        property.Schema,
                        property.IsNullable());

                    if (!_objectSchema.IsInput)
                    {
                        type = TypeFactory.GetOutputType(type);
                    }

                    var accessibility = property.IsDiscriminator == true ? "internal" : "public";

                    CSharpType?initializeWithType = memberMapping?.Initialize == true?TypeFactory.GetImplementationType(type) : null;

                    yield return(new ObjectTypeProperty(
                                     BuilderHelpers.CreateMemberDeclaration(name, type, accessibility, memberMapping?.ExistingMember, _typeFactory),
                                     BuilderHelpers.EscapeXmlDescription(property.Language.Default.Description),
                                     isReadOnly,
                                     property,
                                     initializeWithType,
                                     memberMapping?.EmptyAsUndefined ?? false));
                }
            }

            if (AdditionalPropertiesProperty is ObjectTypeProperty additionalPropertiesProperty)
            {
                yield return(additionalPropertiesProperty);
            }
        }