private EnumType(Schema schema, BuildContext context, Schema baseType, IEnumerable <ChoiceValue> choices, bool isExtendable) : base(context)
        {
            _context = context;
            _choices = choices;

            DefaultName          = schema.CSharpName();
            DefaultAccessibility = schema.Extensions?.Accessibility ?? "public";
            DefaultNamespace     = schema.Extensions?.Namespace ?? $"{_context.DefaultNamespace}.Models";

            if (ExistingType != null)
            {
                isExtendable = ExistingType.TypeKind switch
                {
                    TypeKind.Enum => false,
                    TypeKind.Struct => true,
                    _ => throw new InvalidOperationException(
                              $"{ExistingType.ToDisplayString()} cannot be mapped to enum," +
                              $" expected enum or struct got {ExistingType.TypeKind}")
                };

                _typeMapping = context.SourceInputModel.CreateForModel(ExistingType);
            }

            BaseType     = context.TypeFactory.CreateType(baseType, false);
            Description  = BuilderHelpers.CreateDescription(schema);
            IsExtendable = isExtendable;
        }
Beispiel #2
0
        public ObjectType(ObjectSchema objectSchema, BuildContext context) : base(context)
        {
            _objectSchema         = objectSchema;
            _typeFactory          = context.TypeFactory;
            _serializationBuilder = new SerializationBuilder();

            var hasUsage = objectSchema.Usage.Any() && !objectSchema.IsExceptionOnly;

            DefaultAccessibility = objectSchema.Extensions?.Accessibility ?? (hasUsage ? "public" : "internal");
            Description          = BuilderHelpers.CreateDescription(objectSchema);
            DefaultName          = objectSchema.CSharpName();
            DefaultNamespace     = objectSchema.Extensions?.Namespace ?? $"{context.DefaultNamespace}.Models";

            _sourceTypeMapping = context.SourceInputModel.CreateForModel(ExistingType);
        }