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("/// ") .WriteLine("/// Specifies that the annotated property should be excluded.") .WriteLine("/// "); } builder .WriteLine("[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]") .WriteLine($"public sealed class {AttributeClassName} : Attribute {{ }}") .WriteClosingBracket(); return new(builder.ToString(), $"{AttributeClassName}.g.cs"); } } }