diff --git a/Examples/MultiProject/ClassLibrary/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs b/Examples/MultiProject/ClassLibrary/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs index 9e24fa5..770d959 100644 --- a/Examples/MultiProject/ClassLibrary/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs +++ b/Examples/MultiProject/ClassLibrary/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs @@ -8,13 +8,31 @@ namespace AspectGenerator { #if !AG_NOT_GENERATE_API - [Aspect] + /// + /// Defines an aspect. + /// Create a new attribute decorated with this attribute to define an aspect. + /// [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] #if AG_PUBLIC public #endif sealed class AspectAttribute : Attribute { + /// + /// + /// Defines method(s) name that initializes target method interception. + /// You can define multiple method overloads for different generic parameters. + /// + /// + /// The OnInit method should have the following signature: + /// + /// + /// public static InterceptInfo OnInit(InterceptInfo info) + /// { + /// return info; + /// } + /// + /// public string? OnInit { get; set; } public string? OnUsing { get; set; } public string? OnUsingAsync { get; set; } diff --git a/Examples/MultiProject/Directory.Build.props b/Examples/MultiProject/Directory.Build.props index 73ccd13..cafbaa0 100644 --- a/Examples/MultiProject/Directory.Build.props +++ b/Examples/MultiProject/Directory.Build.props @@ -8,6 +8,6 @@ - + diff --git a/Examples/MultiProject/MainApp/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs b/Examples/MultiProject/MainApp/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs index 9e24fa5..770d959 100644 --- a/Examples/MultiProject/MainApp/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs +++ b/Examples/MultiProject/MainApp/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs @@ -8,13 +8,31 @@ namespace AspectGenerator { #if !AG_NOT_GENERATE_API - [Aspect] + /// + /// Defines an aspect. + /// Create a new attribute decorated with this attribute to define an aspect. + /// [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] #if AG_PUBLIC public #endif sealed class AspectAttribute : Attribute { + /// + /// + /// Defines method(s) name that initializes target method interception. + /// You can define multiple method overloads for different generic parameters. + /// + /// + /// The OnInit method should have the following signature: + /// + /// + /// public static InterceptInfo OnInit(InterceptInfo info) + /// { + /// return info; + /// } + /// + /// public string? OnInit { get; set; } public string? OnUsing { get; set; } public string? OnUsingAsync { get; set; } diff --git a/Examples/OpenTelemetryAspect/OpenTelemetryAspect.csproj b/Examples/OpenTelemetryAspect/OpenTelemetryAspect.csproj index 6242c75..2b87f52 100644 --- a/Examples/OpenTelemetryAspect/OpenTelemetryAspect.csproj +++ b/Examples/OpenTelemetryAspect/OpenTelemetryAspect.csproj @@ -12,7 +12,7 @@ - + diff --git a/Examples/OpenTelemetryAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs b/Examples/OpenTelemetryAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs index c194faa..770d959 100644 --- a/Examples/OpenTelemetryAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs +++ b/Examples/OpenTelemetryAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs @@ -6,24 +6,51 @@ namespace AspectGenerator { - [Aspect] +#if !AG_NOT_GENERATE_API + + /// + /// Defines an aspect. + /// Create a new attribute decorated with this attribute to define an aspect. + /// [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] +#if AG_PUBLIC + public +#endif sealed class AspectAttribute : Attribute { - public string? OnInit { get; set; } - public string? OnUsing { get; set; } - public string? OnUsingAsync { get; set; } - public string? OnBeforeCall { get; set; } - public string? OnBeforeCallAsync { get; set; } - public string? OnAfterCall { get; set; } - public string? OnAfterCallAsync { get; set; } - public string? OnCatch { get; set; } - public string? OnCatchAsync { get; set; } - public string? OnFinally { get; set; } - public string? OnFinallyAsync { get; set; } - public bool PassArguments { get; set; } + /// + /// + /// Defines method(s) name that initializes target method interception. + /// You can define multiple method overloads for different generic parameters. + /// + /// + /// The OnInit method should have the following signature: + /// + /// + /// public static InterceptInfo OnInit(InterceptInfo info) + /// { + /// return info; + /// } + /// + /// + public string? OnInit { get; set; } + public string? OnUsing { get; set; } + public string? OnUsingAsync { get; set; } + public string? OnBeforeCall { get; set; } + public string? OnBeforeCallAsync { get; set; } + public string? OnAfterCall { get; set; } + public string? OnAfterCallAsync { get; set; } + public string? OnCatch { get; set; } + public string? OnCatchAsync { get; set; } + public string? OnFinally { get; set; } + public string? OnFinallyAsync { get; set; } + public string[]? InterceptedMethods { get; set; } + public bool PassArguments { get; set; } } +#if AG_PUBLIC + public +#endif enum InterceptType { OnInit, @@ -33,6 +60,9 @@ enum InterceptType OnFinally } +#if AG_PUBLIC + public +#endif enum InterceptResult { Continue, @@ -41,10 +71,16 @@ enum InterceptResult IgnoreThrow = Return } +#if AG_PUBLIC + public +#endif struct Void { } +#if AG_PUBLIC + public +#endif abstract class InterceptInfo { public object? Tag; @@ -59,12 +95,19 @@ abstract class InterceptInfo public System.Collections.Generic.Dictionary AspectArguments; } +#if AG_PUBLIC + public +#endif class InterceptInfo : InterceptInfo { public T ReturnValue; } } +#endif + +#if !AG_NOT_GENERATE_InterceptsLocationAttribute + namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] @@ -72,3 +115,5 @@ sealed class InterceptsLocationAttribute(string filePath, int line, int characte { } } + +#endif diff --git a/Examples/TransactionAspect/TransactionAspect.csproj b/Examples/TransactionAspect/TransactionAspect.csproj index 6db61ee..e0b25a5 100644 --- a/Examples/TransactionAspect/TransactionAspect.csproj +++ b/Examples/TransactionAspect/TransactionAspect.csproj @@ -16,7 +16,7 @@ - + diff --git a/Examples/TransactionAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs b/Examples/TransactionAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs index c194faa..770d959 100644 --- a/Examples/TransactionAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs +++ b/Examples/TransactionAspect/obj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs @@ -6,24 +6,51 @@ namespace AspectGenerator { - [Aspect] +#if !AG_NOT_GENERATE_API + + /// + /// Defines an aspect. + /// Create a new attribute decorated with this attribute to define an aspect. + /// [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] +#if AG_PUBLIC + public +#endif sealed class AspectAttribute : Attribute { - public string? OnInit { get; set; } - public string? OnUsing { get; set; } - public string? OnUsingAsync { get; set; } - public string? OnBeforeCall { get; set; } - public string? OnBeforeCallAsync { get; set; } - public string? OnAfterCall { get; set; } - public string? OnAfterCallAsync { get; set; } - public string? OnCatch { get; set; } - public string? OnCatchAsync { get; set; } - public string? OnFinally { get; set; } - public string? OnFinallyAsync { get; set; } - public bool PassArguments { get; set; } + /// + /// + /// Defines method(s) name that initializes target method interception. + /// You can define multiple method overloads for different generic parameters. + /// + /// + /// The OnInit method should have the following signature: + /// + /// + /// public static InterceptInfo OnInit(InterceptInfo info) + /// { + /// return info; + /// } + /// + /// + public string? OnInit { get; set; } + public string? OnUsing { get; set; } + public string? OnUsingAsync { get; set; } + public string? OnBeforeCall { get; set; } + public string? OnBeforeCallAsync { get; set; } + public string? OnAfterCall { get; set; } + public string? OnAfterCallAsync { get; set; } + public string? OnCatch { get; set; } + public string? OnCatchAsync { get; set; } + public string? OnFinally { get; set; } + public string? OnFinallyAsync { get; set; } + public string[]? InterceptedMethods { get; set; } + public bool PassArguments { get; set; } } +#if AG_PUBLIC + public +#endif enum InterceptType { OnInit, @@ -33,6 +60,9 @@ enum InterceptType OnFinally } +#if AG_PUBLIC + public +#endif enum InterceptResult { Continue, @@ -41,10 +71,16 @@ enum InterceptResult IgnoreThrow = Return } +#if AG_PUBLIC + public +#endif struct Void { } +#if AG_PUBLIC + public +#endif abstract class InterceptInfo { public object? Tag; @@ -59,12 +95,19 @@ abstract class InterceptInfo public System.Collections.Generic.Dictionary AspectArguments; } +#if AG_PUBLIC + public +#endif class InterceptInfo : InterceptInfo { public T ReturnValue; } } +#endif + +#if !AG_NOT_GENERATE_InterceptsLocationAttribute + namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] @@ -72,3 +115,5 @@ sealed class InterceptsLocationAttribute(string filePath, int line, int characte { } } + +#endif diff --git a/README.md b/README.md index 343dfe7..7e1a478 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Aspect Generator -[![NuGet Version and Downloads count](https://buildstats.info/nuget/AspectGenerator?includePreReleases=true)](https://www.nuget.org/packages/AspectGenerator) +[![NuGet Version and Downloads count](https://buildstats.info/nuget/AspectGenerator?includePreReleases=true)](https://www.nuget.org/packages/AspectGenerator) [![Test workflow](https://img.shields.io/github/actions/workflow/status/igor-tkachev/AspectGenerator/dotnet.yml?branch=master&label=test&logo=github&style=flat-square)](https://github.com/igor-tkachev/AspectGenerator/actions?workflow=.NET) The Aspect Generator can help you easily create your own aspects.