Skip to content

Commit

Permalink
addressing #220 and #221
Browse files Browse the repository at this point in the history
  • Loading branch information
pamidur committed Jul 14, 2023
1 parent cbafc5a commit bc1bc51
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nuget/AspectInjector.Package.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>AspectInjector</PackageId>
Expand Down Expand Up @@ -100,7 +100,7 @@
<Target Name="SignOSXBinaries" DependsOnTargets="ConfigurePublish" Condition=" '$(Configuration)' == 'Release' AND '$(OSXCertPath)' != '' ">

<ItemGroup>
<PublishOSXRids Include="@(PublishRids)" Condition="$([System.String]::Copy(%(Identity)).StartsWith('osx-'))"/>
<PublishOSXRids Include="@(PublishRids)" Condition="$([System.String]::Copy(%(Identity)).StartsWith('osx-arm'))"/>
</ItemGroup>

<Exec Command="$(MSBuildThisFileDirectory)/rcodesign sign --pem-source $(OSXCertPath) $(PublishMain)%(PublishOSXRids.Identity)/AspectInjector" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AspectInjector.Core.Advice.Effects;
using AspectInjector.Core.Advice.Effects;
using AspectInjector.Core.Extensions;
using AspectInjector.Core.Models;
using FluentIL;
Expand All @@ -16,11 +16,12 @@ public AdviceBeforeProcess(ILogger log, MethodDefinition target, InjectionDefini

public override void Execute()
{
_method.EnsureAspectInitialized(_aspect);
_method.Body.OnAspectsInitialized(
(in Cut e) => e
.LoadAspect(_aspect)
.Call(_effect.Method, LoadAdviceArgs)
);
}
}
}
}
10 changes: 9 additions & 1 deletion src/AspectInjector.Core/Extensions/FluentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AspectInjector.Broker;
using AspectInjector.Broker;
using AspectInjector.Core.Models;
using FluentIL;
using FluentIL.Extensions;
Expand Down Expand Up @@ -77,6 +77,14 @@ public static Cut CreateAspectInstance(this in Cut cut, AspectDefinition aspect)
call = call.Cast(call.TypeSystem.Object, aspect.Host);

return call;
}

public static void EnsureAspectInitialized(this MethodDefinition target, AspectDefinition aspect)
{
if (target.IsStatic || aspect.Scope == Scope.Global)
_ = GetGlobalAspectField(aspect);
else
_ = GetInstanceAspectField(aspect, target.DeclaringType, new Cut(target.Body, target.Body.Instructions[0]));
}

private static FieldReference GetInstanceAspectField(AspectDefinition aspect, TypeDefinition source, in Cut cut)
Expand Down

0 comments on commit bc1bc51

Please sign in to comment.