private void PostInitialize(
     GeneratorPostInitializationContext context)
 {
     context.AddSource("EquatableAttribute.cs", Attributes.EquatableAttributeSource);
     context.AddSource("ComparableAttribute.cs", Attributes.ComparableAttributeSource);
     context.AddSource("CompareByAttribute.cs", Attributes.CompareByAttributeSource);
 }
Example #2
0
        public static GeneratorPostInitializationContext AddAttribute(this GeneratorPostInitializationContext context, string attributeNamespace, string name, params AttributeTargets[] targets)
        {
            context.AddSource(name, $@"
using System;
namespace {attributeNamespace}
{{
    [AttributeUsage({string.Join(" | ", targets.Select(t => $"AttributeTargets.{t}"))}, Inherited = false, AllowMultiple = false)]
    internal sealed class {name} : Attribute {{ }}
}}
");
            return(context);
        }
        internal static void AddLibraryFilesToContext(GeneratorPostInitializationContext context)
        {
            var libraryPath = "MvvmGen.SourceGenerators.MvvmGenLib";
            var assembly    = typeof(PureCodeGenerationLibraryLoader).Assembly;
            var embeddedLibraryCodeFiles = assembly.GetManifestResourceNames().Where(x => x.StartsWith(libraryPath));

            foreach (var codeFile in embeddedLibraryCodeFiles)
            {
                var codeFileContent = GetContentOfEmbeddedResource(assembly, codeFile);
                var fileNameHint    = codeFile.Replace(libraryPath, "MvvmGen").Replace(".cs", ".g.cs");
                context.AddSource(fileNameHint, codeFileContent);
            }
        }
Example #4
0
    private void GenerateAttribute(GeneratorPostInitializationContext context)
    {
        string source = @"using System;

namespace Godot.SourceGenerators.Internal
{
internal class GenerateUnmanagedCallbacksAttribute : Attribute
{
    public Type FuncStructType { get; }

    public GenerateUnmanagedCallbacksAttribute(Type funcStructType)
    {
        FuncStructType = funcStructType;
    }
}
}";

        context.AddSource("GenerateUnmanagedCallbacksAttribute.generated",
                          SourceText.From(source, Encoding.UTF8));
    }
Example #5
0
        private void SetDefaultAttribute(GeneratorPostInitializationContext context)
        {
            var attrCode = new UnitOfAttributeTemplate().TransformText();

            context.AddSource("UnitOfAttribute.cs", attrCode);
        }
 private static void PostInitializationCallback(GeneratorPostInitializationContext context)
 {
     context.AddSource("HelloWorldAttribute.g.cs", SourceText.From(HelloWorldAttribute, Encoding.UTF8));
 }
 public void PostInititialize(GeneratorPostInitializationContext context)
 {
     context.AddSource("CreatePropertyAttribute.g.cs", attributeContext);
 }
 private void AddAttribute(GeneratorPostInitializationContext context, GeneratorAttributeDefinition attributeDefinition)
 {
     if (attributeTemplate is { })