-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBaseFileGenerator.cs
More file actions
46 lines (41 loc) · 1.57 KB
/
BaseFileGenerator.cs
File metadata and controls
46 lines (41 loc) · 1.57 KB
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
43
44
45
46
using Scriban;
namespace DataverseProxyGenerator.Core.Generation.Common;
/// <summary>
/// Base class for file generators providing common functionality.
/// </summary>
public abstract class BaseFileGenerator
{
/// <summary>
/// Validates the generation context.
/// </summary>
/// <param name="context">The generation context to validate.</param>
/// <exception cref="ArgumentNullException">Thrown when context is null.</exception>
protected static void ValidateContext(GenerationContext context)
{
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(context.Templates);
if (string.IsNullOrWhiteSpace(context.Namespace))
{
throw new ArgumentException("Namespace cannot be null or empty", nameof(context));
}
if (string.IsNullOrWhiteSpace(context.Version))
{
throw new ArgumentException("Version cannot be null or empty", nameof(context));
}
}
/// <summary>
/// Creates a template context with standard settings.
/// </summary>
/// <param name="model">The model to use for rendering.</param>
/// <returns>A configured template context.</returns>
protected static TemplateContext CreateTemplateContext(object model)
{
var templateContext = new TemplateContext(StringComparer.InvariantCulture)
{
LoopLimit = 0, // No limit
MemberRenamer = member => member.Name,
};
templateContext.PushGlobal(Scriban.Runtime.ScriptObject.From(model));
return templateContext;
}
}