Skip to content

Commit acd472e

Browse files
committedJun 19, 2015
support for partial classes, fix for prefixing regression :shipit:
1 parent 6d2ebb1 commit acd472e

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed
 

‎JsonCSharpClassGeneratorLib/CodeWriters/CSharpCodeWriter.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, TextWriter sw, b
125125

126126
public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
127127
{
128-
var visibility = config.InternalVisibility ? "internal" : "public";
129-
130-
128+
var visibility = (config.InternalVisibility ? "internal" : "public") + (config.GeneratePartialClasses ? " partial" : "");
131129

132130
if (config.UseNestedClasses)
133131
{
@@ -223,7 +221,7 @@ private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw,
223221

224222
private bool ShouldPrefix(string fieldName)
225223
{
226-
if (!Char.IsLetter(fieldName.ToCharArray()[0]))
224+
if (char.IsNumber(fieldName.ToCharArray()[0]))
227225
return true;
228226

229227
if (_csharpKeywords.Contains(fieldName))

‎JsonCSharpClassGeneratorLib/IJsonClassGeneratorConfig.cs

+1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ public interface IJsonClassGeneratorConfig
2323
bool AlwaysUseNullableValues { get; set; }
2424
bool UseNamespaces { get; }
2525
bool ExamplesInDocumentation { get; set; }
26+
bool GeneratePartialClasses { get; set; }
2627
}
2728
}

‎JsonCSharpClassGeneratorLib/JsonClassGenerator.cs

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class JsonClassGenerator : IJsonClassGeneratorConfig
3838
private bool used = false;
3939
public bool UseNamespaces { get { return Namespace != null; } }
4040

41+
public bool GeneratePartialClasses { get; set; }
42+
4143
public void GenerateClasses()
4244
{
4345
if (CodeWriter == null) CodeWriter = new CSharpCodeWriter();

‎JsonCSharpClassGeneratorLib/JsonType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal JsonType MaybeMakeNullable(IJsonClassGeneratorConfig generator)
7676

7777
public void AssignName(string name)
7878
{
79-
if (!char.IsLetter(name.ToCharArray()[0]))
79+
if (char.IsNumber(name.ToCharArray()[0]))
8080
name = "_" + name;
8181

8282
AssignedName = name;

0 commit comments

Comments
 (0)