Skip to content

Commit 6809ed0

Browse files
committed
code generation improvements
1 parent 84aa8cf commit 6809ed0

File tree

8 files changed

+325
-167
lines changed

8 files changed

+325
-167
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
7+
namespace SharpGLTF.CodeGen
8+
{
9+
partial class CSharpEmitter
10+
{
11+
/// <summary>
12+
/// Represents an enum within <see cref="_RuntimeType"/>
13+
/// </summary>
14+
[System.Diagnostics.DebuggerDisplay("Enum: {_Name}")]
15+
class _RuntimeEnum
16+
{
17+
internal _RuntimeEnum(string name) { _Name = name; }
18+
19+
private readonly string _Name;
20+
}
21+
}
22+
}
23+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
7+
namespace SharpGLTF.CodeGen
8+
{
9+
using SchemaReflection;
10+
11+
partial class CSharpEmitter
12+
{
13+
/// <summary>
14+
/// Represents an field within <see cref="_RuntimeType"/>
15+
/// </summary>
16+
[System.Diagnostics.DebuggerDisplay("Enum: {_Name}")]
17+
class _RuntimeField
18+
{
19+
#region lifecycle
20+
internal _RuntimeField(FieldInfo f) { _PersistentField = f; }
21+
#endregion
22+
23+
#region data
24+
25+
private readonly FieldInfo _PersistentField;
26+
27+
#endregion
28+
29+
#region properties
30+
31+
public string PrivateField { get; set; }
32+
public string PublicProperty { get; set; }
33+
34+
public string CollectionContainer { get; set; }
35+
36+
// MinVal, MaxVal, readonly, static
37+
38+
// serialization sections
39+
// deserialization sections
40+
// validation sections
41+
// clone sections
42+
43+
#endregion
44+
}
45+
}
46+
}
47+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
7+
namespace SharpGLTF.CodeGen
8+
{
9+
using SchemaReflection;
10+
11+
partial class CSharpEmitter
12+
{
13+
/// <summary>
14+
/// Represents the runtime information associated to a given <see cref="SchemaType"/>
15+
/// </summary>
16+
[System.Diagnostics.DebuggerDisplay("{RuntimeNamespace}.{RuntimeName}")]
17+
class _RuntimeType
18+
{
19+
#region lifecycle
20+
internal _RuntimeType(SchemaType t) { _PersistentType = t; }
21+
22+
#endregion
23+
24+
#region data
25+
26+
/// <summary>
27+
/// Schema type used for serialization
28+
/// </summary>
29+
private readonly SchemaType _PersistentType;
30+
31+
/// <summary>
32+
/// Namespace in which the source code will be generated.
33+
/// </summary>
34+
public string RuntimeNamespace { get; set; }
35+
36+
/// <summary>
37+
/// The name of the type used to generate the source code.
38+
/// </summary>
39+
public string RuntimeName { get; set; }
40+
41+
/// <summary>
42+
/// Additional comments added to the generated source code.
43+
/// </summary>
44+
public List<string> RuntimeComments { get; } = new List<string>();
45+
46+
/// <summary>
47+
/// Fields of this type.
48+
/// </summary>
49+
private readonly Dictionary<string, _RuntimeField> _Fields = new Dictionary<string, _RuntimeField>();
50+
51+
/// <summary>
52+
/// Enums of this type.
53+
/// </summary>
54+
private readonly Dictionary<string, _RuntimeEnum> _Enums = new Dictionary<string, _RuntimeEnum>();
55+
56+
#endregion
57+
58+
#region API
59+
60+
public _RuntimeField UseField(FieldInfo finfo)
61+
{
62+
var key = $"{finfo.PersistentName}";
63+
64+
if (_Fields.TryGetValue(key, out _RuntimeField rfield)) return rfield;
65+
66+
rfield = new _RuntimeField(finfo);
67+
68+
_Fields[key] = rfield;
69+
70+
return rfield;
71+
}
72+
73+
public _RuntimeEnum UseEnum(string name)
74+
{
75+
var key = name;
76+
77+
if (_Enums.TryGetValue(key, out _RuntimeEnum renum)) return renum;
78+
79+
renum = new _RuntimeEnum(name);
80+
81+
_Enums[key] = renum;
82+
83+
return renum;
84+
}
85+
86+
#endregion
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)