Skip to content

Commit

Permalink
Fixed github build.
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-tkachev committed Dec 5, 2023
1 parent 11c3646 commit 97dc9b6
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 10 deletions.
9 changes: 9 additions & 0 deletions Examples/MultiProject/ClassLibrary/ClassLibrary.csproj
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>
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
{
}
}
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;
}
}
}
9 changes: 0 additions & 9 deletions Examples/MultiProject/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>

<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);MultiProjectAspectGenerator</InterceptorsPreviewNamespaces>

<EmitCompilerGeneratedFiles Condition="'$(Configuration)'=='Debug'">true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath Condition="'$(Configuration)'=='Debug'">$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>

<AspectGenerator_InterceptorsNamespace>MultiProjectAspectGenerator</AspectGenerator_InterceptorsNamespace>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="AspectGenerator_InterceptorsNamespace" />

<Compile Include="..\Aspects\*.cs" />

<PackageReference Include="AspectGenerator" Version="0.0.5-preview" />
Expand Down
9 changes: 9 additions & 0 deletions Examples/MultiProject/MainApp/MainApp.csproj
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>
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
{
}
}
1 change: 1 addition & 0 deletions UnitTests/Tests/Aspects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public static void OnAfterCall(InterceptInfo<string> info)
InterceptedMethods = new[]
{
"AspectGenerator.Tests.UnitTests.InterceptedMethod(string)",
"AspectGenerator.Tests.UnitTests.InterceptedGenericMethod<string>(string)",
"System.String.Substring(int)",
"string.Substring(int)"
}
Expand Down
20 changes: 20 additions & 0 deletions UnitTests/Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ public void InterceptedMethodTest()
Assert.AreEqual("Intercepted InterceptedMethod + InterceptMethods aspect.", s);
}

public static T InterceptedGenericMethod<T>(T p)
{
return p;
}

[TestMethod]
public void InterceptedGenericMethodTest()
{
var s = InterceptedGenericMethod("Intercepted");

Console.WriteLine(s);
Assert.AreEqual("Intercepted + InterceptMethods aspect.", s);

var i = InterceptedGenericMethod(10);

Console.WriteLine(i);

Assert.AreEqual(10, i);
}

[TestMethod]
public void SubstringInterceptTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,39 @@ public static int InitMethod_Interceptor()
return __info__0.ReturnValue;
}

static SR. MemberInfo InterceptedGenericMethod_Interceptor_MemberInfo = MethodOf(() => AspectGenerator.Tests.UnitTests.InterceptedGenericMethod(default(string)));
static SCG.Dictionary<string,object?> InterceptedGenericMethod_Interceptor_AspectArguments_0 = new()
{
};
//
/// <summary>
/// Intercepts AspectGenerator.Tests.UnitTests.InterceptedGenericMethod<string>(string).
/// </summary>
//
// Intercepts InterceptedGenericMethod("Intercepted").
[System.Runtime.CompilerServices.InterceptsLocation(@"P:\AspectGenerator\UnitTests\Tests\UnitTests.cs", line: 437, character: 12)]
//
[System.Runtime.CompilerServices.CompilerGenerated]
//[System.Diagnostics.DebuggerStepThrough]
public static string InterceptedGenericMethod_Interceptor(string p)
{
// Aspects.InterceptMethodsAttribute
//
var __info__0 = new AspectGenerator.InterceptInfo<string>
{
MemberInfo = InterceptedGenericMethod_Interceptor_MemberInfo,
AspectType = typeof(Aspects.InterceptMethodsAttribute),
AspectArguments = InterceptedGenericMethod_Interceptor_AspectArguments_0,
};

__info__0.ReturnValue = AspectGenerator.Tests.UnitTests.InterceptedGenericMethod(p);

__info__0.InterceptType = AspectGenerator.InterceptType.OnAfterCall;
Aspects.InterceptMethodsAttribute.OnAfterCall(__info__0);

return __info__0.ReturnValue;
}

static SR. MemberInfo InterceptedMethod_Interceptor_MemberInfo = MethodOf(() => AspectGenerator.Tests.UnitTests.InterceptedMethod(default(string)));
static SCG.Dictionary<string,object?> InterceptedMethod_Interceptor_AspectArguments_0 = new()
{
Expand Down Expand Up @@ -1356,7 +1389,7 @@ public static string StaticMethod_Interceptor_6(string name)
/// </summary>
//
// Intercepts "test string".Substring(5).
[System.Runtime.CompilerServices.InterceptsLocation(@"P:\AspectGenerator\UnitTests\Tests\UnitTests.cs", line: 432, character: 26)]
[System.Runtime.CompilerServices.InterceptsLocation(@"P:\AspectGenerator\UnitTests\Tests\UnitTests.cs", line: 452, character: 26)]
//
[System.Runtime.CompilerServices.CompilerGenerated]
//[System.Diagnostics.DebuggerStepThrough]
Expand Down

0 comments on commit 97dc9b6

Please sign in to comment.