Ejemplo n.º 1
0
        private static string GenerateEnumValue(EnumValueModel value)
        {
            var obsoleteAttribute = value.IsDeprecated
                    ? $@"        {AttributeGenerator.GenerateObsoleteAttribute(value.DeprecationReason)}{Environment.NewLine}"
                    : string.Empty;

            return($@"{obsoleteAttribute}        [EnumMember(Value = ""{value.Name}"")]
        {value.Name.SnakeCaseToPascalCase()},");
        }
        private static string GenerateScalarField(FieldModel field, TypeModel type)
        {
            var obsoleteAttribute = field.IsDeprecated
                    ? $@"        {AttributeGenerator.GenerateObsoleteAttribute(field.DeprecationReason)}{Environment.NewLine}"
                    : string.Empty;

            var name     = TypeUtilities.PascalCase(field.Name);
            var typeName = TypeUtilities.GetCSharpReturnType(type);

            return($"{obsoleteAttribute}        public {typeName} {name} {{ get; }}");
        }
        private static string GenerateObjectField(FieldModel field, TypeModel type, string rootNamespace, string entityNamespace, string queryType)
        {
            var obsoleteAttribute = field.IsDeprecated
                ? $@"        {AttributeGenerator.GenerateObsoleteAttribute(field.DeprecationReason)}{Environment.NewLine}"
                : string.Empty;

            var name     = TypeUtilities.PascalCase(field.Name);
            var typeName = TypeUtilities.GetCSharpReturnType(type);
            var implName = GetEntityImplementationName(type, (typeName != queryType) ? entityNamespace : rootNamespace);

            return($"{obsoleteAttribute}        public {typeName} {name} => this.CreateProperty(x => x.{name}, {implName}.Create);");
        }
        private static string GenerateScalarMethod(FieldModel field, TypeModel type)
        {
            var obsoleteAttribute = field.IsDeprecated
                ? $@"        {AttributeGenerator.GenerateObsoleteAttribute(field.DeprecationReason)}{Environment.NewLine}"
                : string.Empty;

            var name       = TypeUtilities.PascalCase(field.Name);
            var csharpType = TypeUtilities.GetCSharpReturnType(type);

            GenerateArguments(field, out string arguments, out string parameters);

            return($"{obsoleteAttribute}        public {csharpType} {name}({arguments}) => null;");
        }
        private static string GenerateListField(FieldModel field, TypeModel type)
        {
            var obsoleteAttribute = field.IsDeprecated
                ? $@"        {AttributeGenerator.GenerateObsoleteAttribute(field.DeprecationReason)}{Environment.NewLine}"
                : string.Empty;

            var name     = TypeUtilities.PascalCase(field.Name);
            var typeName = TypeUtilities.GetCSharpReturnType(type);
            var getter   = TypeUtilities.IsCSharpPrimitive(type.OfType) ?
                           "{ get; }" :
                           $"=> this.CreateProperty(x => x.{name});";

            return($"{obsoleteAttribute}        public {typeName} {name} {getter}");
        }