Skip to content

Commit ec3b9ef

Browse files
committed
Major Refactoring
1 parent b537cec commit ec3b9ef

File tree

61 files changed

+1318
-919
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1318
-919
lines changed

JsonClassGenerator.WinForms/MainForm.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
using System.Windows.Forms;
99

1010
using Microsoft.Win32;
11+
using Xamasoft.JsonClassGenerator.CodeWriterConfiguration;
12+
using Xamasoft.JsonClassGenerator.CodeWriters;
13+
using Xamasoft.JsonClassGenerator.Models;
1114

1215
namespace Xamasoft.JsonClassGenerator.WinForms
1316
{
1417
public partial class MainForm : Form
1518
{
1619
private bool preventReentrancy = false;
1720

21+
public CSharpCodeWriterConfig writerConfig { get; set; } = new CSharpCodeWriterConfig();
1822
public MainForm()
1923
{
2024
// `IconTitleFont` is what WinForms *should* be using by default.
@@ -403,45 +407,45 @@ private void TryLoadJsonFile( FileInfo jsonFile )
403407

404408
#endregion
405409

406-
private void ConfigureGenerator( IJsonClassGeneratorConfig config )
410+
private void ConfigureGenerator( JsonClassGenerator config )
407411
{
408412
config.UsePascalCase = this.optsPascalCase.Checked;
409413

410414
//
411415

412416
if( this.optAttribJP.Checked )
413417
{
414-
config.AttributeLibrary = JsonLibrary.NewtonsoftJson;
418+
writerConfig.AttributeLibrary = JsonLibrary.NewtonsoftJson;
415419
}
416420
else// implicit: ( this.optAttribJpn.Checked )
417421
{
418-
config.AttributeLibrary = JsonLibrary.SystemTextJson;
422+
writerConfig.AttributeLibrary = JsonLibrary.SystemTextJson;
419423
}
420424

421425
//
422426

423427
if( this.optMemberProps.Checked )
424428
{
425-
config.MutableClasses.Members = OutputMembers.AsProperties;
429+
writerConfig.OutputMembers = OutputMembers.AsProperties;
426430
}
427431
else// implicit: ( this.optMemberFields.Checked )
428432
{
429-
config.MutableClasses.Members = OutputMembers.AsPublicFields;
433+
writerConfig.OutputMembers = OutputMembers.AsPublicFields;
430434
}
431435

432436
//
433437

434438
if( this.optTypesImmutablePoco.Checked )
435439
{
436-
config.OutputType = OutputTypes.ImmutableClass;
440+
writerConfig.OutputType = OutputTypes.ImmutableClass;
437441
}
438442
else if( this.optTypesMutablePoco.Checked )
439443
{
440-
config.OutputType = OutputTypes.MutableClass;
444+
writerConfig.OutputType = OutputTypes.MutableClass;
441445
}
442446
else// implicit: ( this.optTypesRecords.Checked )
443447
{
444-
config.OutputType = OutputTypes.ImmutableRecord;
448+
writerConfig.OutputType = OutputTypes.ImmutableRecord;
445449
}
446450
}
447451

@@ -473,6 +477,7 @@ private void GenerateCSharp()
473477
}
474478

475479
JsonClassGenerator generator = new JsonClassGenerator();
480+
generator.CodeWriter = new CSharpCodeWriter(writerConfig);
476481
this.ConfigureGenerator( generator );
477482

478483
try
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Xamasoft.JsonClassGenerator.Models;
9+
10+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
11+
{
12+
public class CSharpCodeWriterConfig : CodeWriterConfigurationBase
13+
{
14+
/// <summary>
15+
/// The default constructor with default property values
16+
/// </summary>
17+
public CSharpCodeWriterConfig()
18+
{
19+
UsePascalCase = false;
20+
UseNestedClasses = false;
21+
OutputType = OutputTypes.MutableClass;
22+
AttributeLibrary = JsonLibrary.NewtonsoftJson;
23+
AttributeUsage = JsonPropertyAttributeUsage.OnlyWhenNecessary;
24+
OutputType = OutputTypes.MutableClass;
25+
OutputMembers = OutputMembers.AsProperties;
26+
ReadOnlyCollectionProperties = false;
27+
CollectionType = OutputCollectionType.MutableList;
28+
}
29+
30+
public CSharpCodeWriterConfig(
31+
bool usePascalCase,
32+
bool useNestedClasses,
33+
JsonLibrary attributeLibrary,
34+
JsonPropertyAttributeUsage attributeUsage,
35+
OutputTypes outputType,
36+
OutputMembers members,
37+
bool readOnlyCollectionProperties,
38+
OutputCollectionType collectionType)
39+
{
40+
this.UsePascalCase = usePascalCase;
41+
this.UseNestedClasses = useNestedClasses;
42+
this.AttributeLibrary = attributeLibrary;
43+
this.AttributeUsage = attributeUsage;
44+
this.OutputType = outputType;
45+
this.OutputMembers = members;
46+
this.ReadOnlyCollectionProperties = readOnlyCollectionProperties;
47+
CollectionType = collectionType;
48+
}
49+
50+
public bool UsePascalCase { get; set; }
51+
public bool UseNestedClasses { get; set; }
52+
public JsonLibrary AttributeLibrary { get; set; }
53+
public JsonPropertyAttributeUsage AttributeUsage { get; set; }
54+
public OutputTypes OutputType { get; set; }
55+
public OutputMembers OutputMembers { get; set; }
56+
public bool ReadOnlyCollectionProperties { get; set; }
57+
}
58+
59+
60+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xamasoft.JsonClassGenerator.Models;
7+
8+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
9+
{
10+
public class CodeWriterConfigurationBase
11+
{
12+
/// <summary>
13+
/// The C# <c>namespace</c> or Java <c>package</c> that the generated types will reside in.<br />
14+
/// <see langword="null"/> by default. If null/empty/whitespace then no enclosing namespace will be written in the output.
15+
/// </summary>
16+
public string Namespace { get; set; }
17+
public bool HasNamespace { get { return !String.IsNullOrEmpty(Namespace); } }
18+
19+
/// <summary>
20+
/// The C# <c>namespace</c> or Java <c>package</c> that &quot;secondary&quot; generated types will reside in.<br />
21+
/// <see langword="null"/> by default.
22+
/// </summary>
23+
public string SecondaryNamespace { get; set; }
24+
public bool ExamplesInDocumentation { get; set; }
25+
26+
/// <summary>When <see langword="true"/>, then <see cref="System.Reflection.ObfuscationAttribute"/> will be applied to generated types.</summary>
27+
public bool ApplyObfuscationAttributes { get; set; }
28+
29+
30+
#region Class Settings
31+
public string MainClass { get; set; }
32+
public bool InternalVisibility { get; set; }
33+
#endregion
34+
35+
#region List Settings
36+
public OutputCollectionType CollectionType { get; set; }
37+
#endregion
38+
39+
}
40+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Xamasoft.JsonClassGenerator.Models;
8+
9+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
10+
{
11+
public class DartCodeWriterConfig : CodeWriterConfigurationBase
12+
{
13+
/// <summary>
14+
/// The default constructor with default property values
15+
/// </summary>
16+
public DartCodeWriterConfig()
17+
{
18+
this.RemoveToJson = false;
19+
this.RemoveFromJson = false;
20+
this.RemoveConstructors = false;
21+
this.OutputMembers = OutputMembers.AsPublicFields;
22+
CollectionType = OutputCollectionType.MutableList;
23+
}
24+
25+
public DartCodeWriterConfig(
26+
bool removeToJson,
27+
bool removeFromJson,
28+
bool removeConstructors,
29+
OutputMembers outputMembers,
30+
OutputCollectionType collectionType)
31+
{
32+
this.RemoveToJson = removeToJson;
33+
this.RemoveFromJson = removeFromJson;
34+
this.RemoveConstructors = removeConstructors;
35+
this.OutputMembers = outputMembers;
36+
CollectionType = collectionType;
37+
}
38+
39+
public OutputMembers OutputMembers { get; set; }
40+
public bool RemoveToJson { get; set; }
41+
public bool RemoveFromJson { get; set; }
42+
public bool RemoveConstructors { get; set; }
43+
}
44+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Xamasoft.JsonClassGenerator.Models;
9+
10+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
11+
{
12+
public class JavaCodeWriterConfig : CodeWriterConfigurationBase
13+
{
14+
/// <summary>
15+
/// The default constructor with default property values
16+
/// </summary>
17+
public JavaCodeWriterConfig()
18+
{
19+
OutputMembers = OutputMembers.AsPublicFields;
20+
UsePascalCase = false;
21+
UseNestedClasses = false;
22+
CollectionType = OutputCollectionType.MutableList;
23+
}
24+
25+
public JavaCodeWriterConfig(OutputMembers outputMembers, OutputCollectionType collectionType, bool usePascalCase = false, bool useNestedClasses = false)
26+
{
27+
UsePascalCase = usePascalCase;
28+
OutputMembers = outputMembers;
29+
UseNestedClasses = useNestedClasses;
30+
CollectionType = CollectionType;
31+
}
32+
33+
public OutputMembers OutputMembers { get; set; }
34+
public bool UsePascalCase { get; set; }
35+
public bool UseNestedClasses { get; set; }
36+
}
37+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Xamasoft.JsonClassGenerator.Models;
8+
9+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
10+
{
11+
public class PythonCodeWriterConfig : CodeWriterConfigurationBase
12+
{
13+
/// <summary>
14+
/// The default constructor with default property values
15+
/// </summary>
16+
public PythonCodeWriterConfig()
17+
{
18+
OutputMembers = OutputMembers.AsPublicFields;
19+
}
20+
21+
public OutputMembers OutputMembers { get; set; }
22+
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
8+
{
9+
public class TypeScriptCodeWriterConfig : CodeWriterConfigurationBase
10+
{
11+
}
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Xamasoft.JsonClassGenerator.Models;
7+
8+
namespace Xamasoft.JsonClassGenerator.CodeWriterConfiguration
9+
{
10+
public class VisualBasicCodeWriterConfig : CodeWriterConfigurationBase
11+
{
12+
public VisualBasicCodeWriterConfig()
13+
{
14+
UsePascalCase = false;
15+
UseNestedClasses = false;
16+
OutputType = OutputTypes.MutableClass;
17+
OutputMembers = OutputMembers.AsProperties;
18+
ReadOnlyCollectionProperties = false;
19+
CollectionType = OutputCollectionType.MutableList;
20+
}
21+
22+
public VisualBasicCodeWriterConfig(
23+
bool usePascalCase,
24+
bool useNestedClasses,
25+
JsonLibrary attributeLibrary,
26+
JsonPropertyAttributeUsage attributeUsage,
27+
OutputTypes outputType,
28+
OutputMembers members,
29+
bool readOnlyCollectionProperties,
30+
OutputCollectionType collectionType)
31+
{
32+
this.UsePascalCase = usePascalCase;
33+
this.UseNestedClasses = useNestedClasses;
34+
this.AttributeLibrary = attributeLibrary;
35+
this.AttributeUsage = attributeUsage;
36+
this.OutputType = outputType;
37+
this.OutputMembers = members;
38+
this.ReadOnlyCollectionProperties = readOnlyCollectionProperties;
39+
CollectionType = collectionType;
40+
}
41+
42+
internal bool UsePascalCase { get; set; }
43+
internal bool UseNestedClasses { get; set; }
44+
internal JsonLibrary AttributeLibrary { get; set; }
45+
internal JsonPropertyAttributeUsage AttributeUsage { get; set; }
46+
internal OutputTypes OutputType { get; set; }
47+
internal OutputMembers OutputMembers { get; set; }
48+
internal bool ReadOnlyCollectionProperties { get; set; }
49+
}
50+
}

0 commit comments

Comments
 (0)