-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDomainModelConfiguratorGenerator.WrapperValueObjects.cs
49 lines (40 loc) · 1.96 KB
/
DomainModelConfiguratorGenerator.WrapperValueObjects.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
43
44
45
46
47
48
49
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
namespace Architect.DomainModeling.Generator.Configurators;
public partial class DomainModelConfiguratorGenerator
{
internal static void GenerateSourceForWrapperValueObjects(SourceProductionContext context, (ImmutableArray<WrapperValueObjectGenerator.Generatable> Generatables, (bool HasConfigureConventions, string AssemblyName) Metadata) input)
{
context.CancellationToken.ThrowIfCancellationRequested();
// Generate the method only if we have any generatables, or if we are an assembly in which ConfigureConventions() is called
if (!input.Generatables.Any() && !input.Metadata.HasConfigureConventions)
return;
var targetNamespace = input.Metadata.AssemblyName;
var configurationText = String.Join($"{Environment.NewLine}\t\t\t", input.Generatables.Select(generatable => $"""
configurator.ConfigureWrapperValueObject<{generatable.ContainingNamespace}.{generatable.TypeName}, {generatable.UnderlyingTypeFullyQualifiedName}>({Environment.NewLine} new {Constants.DomainModelingNamespace}.Configuration.IWrapperValueObjectConfigurator.Args());
"""));
var source = $@"
using {Constants.DomainModelingNamespace};
#nullable enable
namespace {targetNamespace}
{{
public static class WrapperValueObjectDomainModelConfigurator
{{
/// <summary>
/// <para>
/// Invokes a callback on the given <paramref name=""configurator""/> for each marked <see cref=""IWrapperValueObject{{TValue}}""/> type in the current assembly.
/// </para>
/// <para>
/// For example, this can be used to have Entity Framework configure a convention for every matching type in the domain model, in a trim-safe way.
/// </para>
/// </summary>
public static void ConfigureWrapperValueObjects({Constants.DomainModelingNamespace}.Configuration.IWrapperValueObjectConfigurator configurator)
{{
{configurationText}
}}
}}
}}
";
AddSource(context, source, "WrapperValueObjectDomainModelConfigurator", targetNamespace);
}
}