forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHbmCodeGenerator.cs
42 lines (38 loc) · 1.48 KB
/
HbmCodeGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.CodeDom;
using System.IO;
using System.Xml.Schema;
namespace NHibernate.Tool.HbmXsd
{
/// <summary>
/// Responsible for generating the NHibernate.Cfg.MappingSchema.Hbm* classes from nhibernate-mapping.xsd.
/// </summary>
public class HbmCodeGenerator : XsdCodeGenerator
{
private const string GeneratedCodeNamespace = "NHibernate.Cfg.MappingSchema";
private const string MappingSchemaResourceName = "NHibernate.Tool.HbmXsd.nhibernate-mapping.xsd";
/// <summary>Generates C# classes.</summary>
/// <param name="outputFileName">The file to which the generated code is written.</param>
public void Execute(string outputFileName)
{
using (Stream stream = GetType().Assembly.GetManifestResourceStream(MappingSchemaResourceName))
{
if (stream == null)
throw new InvalidOperationException($"Unable to load resource {MappingSchemaResourceName}");
XmlSchema schema = XmlSchema.Read(stream, null);
Execute(outputFileName, GeneratedCodeNamespace, schema);
}
}
/// <summary>
/// Customizes the generated code to better conform to the NHibernate's coding conventions.
/// </summary>
/// <param name="code">The customizable code DOM.</param>
/// <param name="sourceSchema">The source XML Schema.</param>
protected override void CustomizeGeneratedCode(CodeNamespace code, XmlSchema sourceSchema)
{
new ImproveHbmTypeNamesCommand(code).Execute();
new ImproveEnumFieldsCommand(code).Execute();
// TODO: Rename class fields?
}
}
}