45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
|
using static MapTo.Sources.Constants;
|
||
|
|
||
|
|
||
|
namespace MapTo.Sources
|
||
|
{
|
||
|
internal static class EfAddMethodsAttributeSource
|
||
|
{
|
||
|
internal const string AttributeName = "EfAddMethods";
|
||
|
internal const string AttributeClassName = AttributeName + "Attribute";
|
||
|
internal const string FullyQualifiedName = RootNamespace + "." + AttributeClassName;
|
||
|
|
||
|
internal static SourceCode Generate(SourceGenerationOptions options)
|
||
|
{
|
||
|
using var builder = new SourceBuilder()
|
||
|
.WriteLine(GeneratedFilesHeader)
|
||
|
.WriteLine("using System;")
|
||
|
.WriteLine()
|
||
|
.WriteLine($"namespace {RootNamespace}")
|
||
|
.WriteOpeningBracket();
|
||
|
|
||
|
if (options.GenerateXmlDocument)
|
||
|
{
|
||
|
builder
|
||
|
.WriteLine("/// <summary>")
|
||
|
.WriteLine("/// Generate Add methods for interacting with the entity")
|
||
|
.WriteLine("/// </summary>");
|
||
|
}
|
||
|
|
||
|
builder
|
||
|
.WriteLine("[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]")
|
||
|
.WriteLine($"public sealed class {AttributeName}Attribute : Attribute")
|
||
|
.WriteOpeningBracket();
|
||
|
|
||
|
builder
|
||
|
.WriteLine($"public {AttributeName}Attribute(Type createType = null, Type returnType = null){"{}"}")
|
||
|
.WriteLine();
|
||
|
|
||
|
builder
|
||
|
.WriteClosingBracket() // class
|
||
|
.WriteClosingBracket(); // namespace
|
||
|
|
||
|
return new(builder.ToString(), $"{AttributeName}Attribute.g.cs");
|
||
|
}
|
||
|
}
|
||
|
}
|