RicoSuter/NJsonSchema

Not allowed characters in generated C# Code

开放

#552 创建于 2017年11月2日

 (1 条评论) (0 个反应) (0 位负责人)C# (549 个派生)github user discovery
help wantedtype: enhancement

仓库指标

星标
 (1,581 个星标)
PR 合并指标
 (平均合并 39天 6小时) (30 天内合并 1 个 PR)

描述

I'm trying to generate C# Code from a given JSONSchema. The Schema contains a property of type string with possible enum values. One of the enum values contains a "?". When generating the C# code, the name of this enum value is also generated with the "?". Since "?" is an invalid character the generated code is invalid. The workaround for this issue was creating a new IEnumNameGenerator which replaces the "?". Sample code: C#-Enum

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "6.8.6197.43075")]
    public enum KitchenDataCookingstyle
    {
        [System.Runtime.Serialization.EnumMember(Value = "Schnell und einfach")]
        Schnell_und_einfach = 0,
    
        [System.Runtime.Serialization.EnumMember(Value = "Gesunde und frische Ernährung")]
        Gesunde_und_frische_Ernährung = 1,
    
        [System.Runtime.Serialization.EnumMember(Value = "Mehrgängige Menüs für Gäste")]
        Mehrgängige_Menüs_für_Gäste = 2,
    
        [System.Runtime.Serialization.EnumMember(Value = "Anspruchsvoll auf Profi-Niveau")]
        Anspruchsvoll_auf_ProfiNiveau = 3,
    
        [System.Runtime.Serialization.EnumMember(Value = "Torten Plätzchen und Desserts")]
        Torten_Plätzchen_und_Desserts = 4,
    
        [System.Runtime.Serialization.EnumMember(Value = "Kochen? Ich gehe lieber essen")]
        Kochen?_Ich_gehe_lieber_essen = 5,
    
    }

JSONSchema

"Cookingstyle": {
					"title": "Kochart",
					"type": "string",
					"enum": ["Schnell und einfach", "Gesunde und frische Ernährung", "Mehrgängige Menüs für Gäste", "Anspruchsvoll auf Profi-Niveau", "Torten Plätzchen und Desserts", "Kochen? Ich gehe lieber essen"]
				}

贡献者指南