2021-12-24 20:06:06 +03:00
|
|
|
|
using static MapTo.Sources.Constants;
|
|
|
|
|
|
|
|
|
|
namespace MapTo.Sources
|
|
|
|
|
{
|
|
|
|
|
internal static class ReadOnlyPropertyAttributeSource
|
|
|
|
|
{
|
|
|
|
|
internal const string AttributeName = "ReadOnlyProperty";
|
|
|
|
|
internal const string AttributeClassName = AttributeName + "Attribute";
|
|
|
|
|
internal const string FullyQualifiedName = RootNamespace + "." + AttributeClassName;
|
|
|
|
|
|
|
|
|
|
internal static SourceCode Generate(SourceGenerationOptions options)
|
|
|
|
|
{
|
|
|
|
|
var builder = new SourceBuilder()
|
|
|
|
|
.WriteLine(GeneratedFilesHeader)
|
|
|
|
|
.WriteLine("using System;")
|
|
|
|
|
.WriteLine()
|
|
|
|
|
.WriteLine($"namespace {RootNamespace}")
|
|
|
|
|
.WriteOpeningBracket();
|
|
|
|
|
|
|
|
|
|
if (options.GenerateXmlDocument)
|
|
|
|
|
{
|
|
|
|
|
builder
|
|
|
|
|
.WriteLine("/// <summary>")
|
|
|
|
|
.WriteLine("/// Specifies that the annotated property should be excluded.")
|
|
|
|
|
.WriteLine("/// </summary>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder
|
|
|
|
|
.WriteLine("[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]")
|
|
|
|
|
.WriteLine($"public sealed class {AttributeClassName} : Attribute {{ }}")
|
|
|
|
|
.WriteClosingBracket();
|
|
|
|
|
|
|
|
|
|
return new(builder.ToString(), $"{AttributeClassName}.g.cs");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-08 20:58:21 +03:00
|
|
|
|
}
|