Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-tkachev committed Dec 8, 2023
1 parent 7c59303 commit 026d393
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ namespace AspectGenerator
{
#if !AG_NOT_GENERATE_API

[Aspect]
/// <summary>
/// <para>Defines an aspect.</para>
/// <para>Create a new attribute decorated with this attribute to define an aspect.</para>
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
#if AG_PUBLIC
public
#endif
sealed class AspectAttribute : Attribute
{
/// <summary>
/// <para>
/// Defines method(s) name that initializes target method interception.
/// You can define multiple method overloads for different generic parameters.
/// </para>
/// <para>
/// The OnInit method should have the following signature:
/// </para>
/// <code>
/// public static InterceptInfo<T> OnInit<T>(InterceptInfo<T> info)
/// {
/// return info;
/// }
/// </code>
/// </summary>
public string? OnInit { get; set; }
public string? OnUsing { get; set; }
public string? OnUsingAsync { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Examples/MultiProject/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<ItemGroup>
<Compile Include="..\Aspects\*.cs" />

<PackageReference Include="AspectGenerator" Version="0.0.5-preview" />
<PackageReference Include="AspectGenerator" Version="0.0.5.3-preview" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ namespace AspectGenerator
{
#if !AG_NOT_GENERATE_API

[Aspect]
/// <summary>
/// <para>Defines an aspect.</para>
/// <para>Create a new attribute decorated with this attribute to define an aspect.</para>
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
#if AG_PUBLIC
public
#endif
sealed class AspectAttribute : Attribute
{
/// <summary>
/// <para>
/// Defines method(s) name that initializes target method interception.
/// You can define multiple method overloads for different generic parameters.
/// </para>
/// <para>
/// The OnInit method should have the following signature:
/// </para>
/// <code>
/// public static InterceptInfo<T> OnInit<T>(InterceptInfo<T> info)
/// {
/// return info;
/// }
/// </code>
/// </summary>
public string? OnInit { get; set; }
public string? OnUsing { get; set; }
public string? OnUsingAsync { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Examples/OpenTelemetryAspect/OpenTelemetryAspect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspectGenerator" Version="0.0.5-preview" />
<PackageReference Include="AspectGenerator" Version="0.0.5.3-preview" />
<PackageReference Include="OpenTelemetry" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,51 @@

namespace AspectGenerator
{
[Aspect]
#if !AG_NOT_GENERATE_API

/// <summary>
/// <para>Defines an aspect.</para>
/// <para>Create a new attribute decorated with this attribute to define an aspect.</para>
/// </summary>
[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; }
/// <summary>
/// <para>
/// Defines method(s) name that initializes target method interception.
/// You can define multiple method overloads for different generic parameters.
/// </para>
/// <para>
/// The OnInit method should have the following signature:
/// </para>
/// <code>
/// public static InterceptInfo<T> OnInit<T>(InterceptInfo<T> info)
/// {
/// return info;
/// }
/// </code>
/// </summary>
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,
Expand All @@ -33,6 +60,9 @@ enum InterceptType
OnFinally
}

#if AG_PUBLIC
public
#endif
enum InterceptResult
{
Continue,
Expand All @@ -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;
Expand All @@ -59,16 +95,25 @@ abstract class InterceptInfo
public System.Collections.Generic.Dictionary<string,object?> AspectArguments;
}

#if AG_PUBLIC
public
#endif
class InterceptInfo<T> : InterceptInfo
{
public T ReturnValue;
}
}

#endif

#if !AG_NOT_GENERATE_InterceptsLocationAttribute

namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
sealed class InterceptsLocationAttribute(string filePath, int line, int character) : Attribute
{
}
}

#endif
2 changes: 1 addition & 1 deletion Examples/TransactionAspect/TransactionAspect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<CompilerVisibleProperty Include="AspectGenerator_InterceptorsNamespace" />

<PackageReference Include="AspectGenerator" Version="0.0.5-preview" />
<PackageReference Include="AspectGenerator" Version="0.0.5.3-preview" />
<PackageReference Include="linq2db" Version="5.3.2" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,51 @@

namespace AspectGenerator
{
[Aspect]
#if !AG_NOT_GENERATE_API

/// <summary>
/// <para>Defines an aspect.</para>
/// <para>Create a new attribute decorated with this attribute to define an aspect.</para>
/// </summary>
[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; }
/// <summary>
/// <para>
/// Defines method(s) name that initializes target method interception.
/// You can define multiple method overloads for different generic parameters.
/// </para>
/// <para>
/// The OnInit method should have the following signature:
/// </para>
/// <code>
/// public static InterceptInfo<T> OnInit<T>(InterceptInfo<T> info)
/// {
/// return info;
/// }
/// </code>
/// </summary>
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,
Expand All @@ -33,6 +60,9 @@ enum InterceptType
OnFinally
}

#if AG_PUBLIC
public
#endif
enum InterceptResult
{
Continue,
Expand All @@ -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;
Expand All @@ -59,16 +95,25 @@ abstract class InterceptInfo
public System.Collections.Generic.Dictionary<string,object?> AspectArguments;
}

#if AG_PUBLIC
public
#endif
class InterceptInfo<T> : InterceptInfo
{
public T ReturnValue;
}
}

#endif

#if !AG_NOT_GENERATE_InterceptsLocationAttribute

namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
sealed class InterceptsLocationAttribute(string filePath, int line, int character) : Attribute
{
}
}

#endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down

0 comments on commit 026d393

Please sign in to comment.