diff --git a/src/Jab/Attributes.cs b/src/Jab/Attributes.cs index fe28f1e..d015414 100644 --- a/src/Jab/Attributes.cs +++ b/src/Jab/Attributes.cs @@ -13,6 +13,7 @@ namespace Jab #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ServiceProviderAttribute: Attribute @@ -24,6 +25,7 @@ class ServiceProviderAttribute: Attribute #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ServiceProviderModuleAttribute: Attribute @@ -34,6 +36,7 @@ class ServiceProviderModuleAttribute: Attribute #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ImportAttribute: Attribute @@ -50,6 +53,7 @@ public ImportAttribute(Type moduleType) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class SingletonAttribute: Attribute @@ -80,6 +84,7 @@ public SingletonAttribute(Type serviceType, Type implementationType) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class TransientAttribute : Attribute @@ -107,6 +112,7 @@ public TransientAttribute(Type serviceType, Type implementationType) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ScopedAttribute : Attribute @@ -152,6 +158,7 @@ public FromNamedServicesAttribute(string name) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ImportAttribute : ImportAttribute @@ -165,6 +172,7 @@ public ImportAttribute() : base(typeof(TModule)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class TransientAttribute : TransientAttribute @@ -178,6 +186,7 @@ public TransientAttribute() : base(typeof(TService)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class TransientAttribute : TransientAttribute where TImpl: TService @@ -191,6 +200,7 @@ public TransientAttribute() : base(typeof(TService), typeof(TImpl)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ScopedAttribute : ScopedAttribute @@ -204,6 +214,7 @@ public ScopedAttribute() : base(typeof(TService)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class ScopedAttribute : ScopedAttribute where TImpl: TService @@ -218,6 +229,7 @@ public ScopedAttribute() : base(typeof(TService), typeof(TImpl)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class SingletonAttribute : SingletonAttribute @@ -231,6 +243,7 @@ public SingletonAttribute() : base(typeof(TService)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif class SingletonAttribute : SingletonAttribute where TImpl: TService @@ -245,6 +258,7 @@ public SingletonAttribute() : base(typeof(TService), typeof(TImpl)) #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif interface IServiceProvider @@ -255,6 +269,7 @@ interface IServiceProvider #if JAB_ATTRIBUTES_PACKAGE public #else + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Jab", null)] internal #endif interface INamedServiceProvider diff --git a/src/Jab/ContainerGenerator.cs b/src/Jab/ContainerGenerator.cs index 19b29f4..a0657e4 100644 --- a/src/Jab/ContainerGenerator.cs +++ b/src/Jab/ContainerGenerator.cs @@ -5,6 +5,9 @@ public partial class ContainerGenerator : DiagnosticAnalyzer #pragma warning restore RS1001 // We don't want this to be discovered as analyzer but it simplifies testing { + /// Code for a [GeneratedCode] attribute to put on the top-level generated members. + private static readonly string _generatedCodeAttribute = $"[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{typeof(ContainerGenerator).Assembly.GetName().Name}\", \"{typeof(ContainerGenerator).Assembly.GetName().Version}\")]"; + private void GenerateCallSiteWithCache(CodeWriter codeWriter, string rootReference, ServiceCallSite serviceCallSite, Action valueCallback) { if (serviceCallSite is ErrorCallSite errorCallSite) @@ -199,6 +202,7 @@ private void Execute(GeneratorContext context) codeWriter.Scope($"{SyntaxFacts.GetText(containingType.DeclaredAccessibility)} partial class {containingType.Name}") : null; + codeWriter.LineRaw(_generatedCodeAttribute); codeWriter.Append($"{SyntaxFacts.GetText(root.Type.DeclaredAccessibility)} partial class {root.Type.Name}"); WriteInterfaces(codeWriter, root, false); using (codeWriter.Scope())