-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11c3646
commit 97dc9b6
Showing
9 changed files
with
283 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);MultiProjectAspectGenerator</InterceptorsPreviewNamespaces> | ||
|
||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath> | ||
|
||
<AspectGenerator_InterceptorsNamespace>MultiProjectAspectGenerator</AspectGenerator_InterceptorsNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<CompilerVisibleProperty Include="AspectGenerator_InterceptorsNamespace" /> | ||
</ItemGroup> | ||
</Project> |
74 changes: 74 additions & 0 deletions
74
...GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
#nullable enable | ||
|
||
using System; | ||
|
||
namespace AspectGenerator | ||
{ | ||
[Aspect] | ||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | ||
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; } | ||
} | ||
|
||
enum InterceptType | ||
{ | ||
OnInit, | ||
OnBeforeCall, | ||
OnAfterCall, | ||
OnCatch, | ||
OnFinally | ||
} | ||
|
||
enum InterceptResult | ||
{ | ||
Continue, | ||
Return, | ||
ReThrow = Continue, | ||
IgnoreThrow = Return | ||
} | ||
|
||
struct Void | ||
{ | ||
} | ||
|
||
abstract class InterceptInfo | ||
{ | ||
public object? Tag; | ||
public InterceptType InterceptType; | ||
public InterceptResult InterceptResult; | ||
public Exception? Exception; | ||
|
||
public InterceptInfo? PreviousInfo; | ||
public System.Reflection.MemberInfo MemberInfo; | ||
public object?[]? MethodArguments; | ||
public Type AspectType; | ||
public System.Collections.Generic.Dictionary<string,object?> AspectArguments; | ||
} | ||
|
||
class InterceptInfo<T> : InterceptInfo | ||
{ | ||
public T ReturnValue; | ||
} | ||
} | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
sealed class InterceptsLocationAttribute(string filePath, int line, int character) : Attribute | ||
{ | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...bj/GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/Interceptors.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
#nullable enable | ||
|
||
using System; | ||
|
||
using SR = System.Reflection; | ||
using SLE = System.Linq.Expressions; | ||
using SCG = System.Collections.Generic; | ||
|
||
namespace MultiProjectAspectGenerator | ||
{ | ||
using AspectGenerator = AspectGenerator; | ||
|
||
static partial class Interceptors | ||
{ | ||
static SR.MethodInfo GetMethodInfo(SLE.Expression expr) | ||
{ | ||
return expr switch | ||
{ | ||
SLE.MethodCallExpression mc => mc.Method, | ||
_ => throw new InvalidOperationException() | ||
}; | ||
} | ||
|
||
static SR.MethodInfo MethodOf<T>(SLE.Expression<Func<T>> func) => GetMethodInfo(func.Body); | ||
static SR.MethodInfo MethodOf (SLE.Expression<Action> func) => GetMethodInfo(func.Body); | ||
|
||
static SR. MemberInfo TestMethod_Interceptor_MemberInfo = MethodOf(() => ClassLibrary.TestClass.TestMethod(default(string))); | ||
static SCG.Dictionary<string,object?> TestMethod_Interceptor_AspectArguments_0 = new() | ||
{ | ||
}; | ||
// | ||
/// <summary> | ||
/// Intercepts ClassLibrary.TestClass.TestMethod(string). | ||
/// </summary> | ||
// | ||
// Intercepts TestMethod(str + " MainMethod"). | ||
[System.Runtime.CompilerServices.InterceptsLocation(@"P:\AspectGenerator\Examples\MultiProject\ClassLibrary\TestClass.cs", line: 17, character: 11)] | ||
// | ||
[System.Runtime.CompilerServices.CompilerGenerated] | ||
//[System.Diagnostics.DebuggerStepThrough] | ||
public static string TestMethod_Interceptor(string str) | ||
{ | ||
// Aspects.CrossProjectAttribute | ||
// | ||
var __info__0 = new AspectGenerator.InterceptInfo<string> | ||
{ | ||
MemberInfo = TestMethod_Interceptor_MemberInfo, | ||
AspectType = typeof(Aspects.CrossProjectAttribute), | ||
AspectArguments = TestMethod_Interceptor_AspectArguments_0, | ||
}; | ||
|
||
__info__0.ReturnValue = ClassLibrary.TestClass.TestMethod(str); | ||
|
||
__info__0.InterceptType = AspectGenerator.InterceptType.OnAfterCall; | ||
Aspects.CrossProjectAttribute.OnAfterCall(__info__0); | ||
|
||
return __info__0.ReturnValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
|
||
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);MultiProjectAspectGenerator</InterceptorsPreviewNamespaces> | ||
|
||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath> | ||
|
||
<AspectGenerator_InterceptorsNamespace>MultiProjectAspectGenerator</AspectGenerator_InterceptorsNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<CompilerVisibleProperty Include="AspectGenerator_InterceptorsNamespace" /> | ||
|
||
<ProjectReference Include="..\ClassLibrary\ClassLibrary.csproj" /> | ||
</ItemGroup> | ||
</Project> |
74 changes: 74 additions & 0 deletions
74
...GeneratedFiles/AspectGenerator/AspectGenerator.AspectSourceGenerator/AspectAttribute.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
#nullable enable | ||
|
||
using System; | ||
|
||
namespace AspectGenerator | ||
{ | ||
[Aspect] | ||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | ||
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; } | ||
} | ||
|
||
enum InterceptType | ||
{ | ||
OnInit, | ||
OnBeforeCall, | ||
OnAfterCall, | ||
OnCatch, | ||
OnFinally | ||
} | ||
|
||
enum InterceptResult | ||
{ | ||
Continue, | ||
Return, | ||
ReThrow = Continue, | ||
IgnoreThrow = Return | ||
} | ||
|
||
struct Void | ||
{ | ||
} | ||
|
||
abstract class InterceptInfo | ||
{ | ||
public object? Tag; | ||
public InterceptType InterceptType; | ||
public InterceptResult InterceptResult; | ||
public Exception? Exception; | ||
|
||
public InterceptInfo? PreviousInfo; | ||
public System.Reflection.MemberInfo MemberInfo; | ||
public object?[]? MethodArguments; | ||
public Type AspectType; | ||
public System.Collections.Generic.Dictionary<string,object?> AspectArguments; | ||
} | ||
|
||
class InterceptInfo<T> : InterceptInfo | ||
{ | ||
public T ReturnValue; | ||
} | ||
} | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
sealed class InterceptsLocationAttribute(string filePath, int line, int character) : Attribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters