Skip to content

Commit cbafc5a

Browse files
committed
Attempt to fix #217
1 parent 36423da commit cbafc5a

File tree

11 files changed

+64
-41
lines changed

11 files changed

+64
-41
lines changed

src/AspectInjector.Core.Advice/Weavers/Processes/AdviceAroundProcess.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using AspectInjector.Core.Advice.Effects;
1+
using AspectInjector.Core.Advice.Effects;
22
using AspectInjector.Core.Extensions;
33
using AspectInjector.Core.Models;
44
using FluentIL;
@@ -82,7 +82,7 @@ private void RedirectPreviousWrapper(MethodDefinition prev, MethodDefinition nex
8282
{
8383
var unwrapper = GetOrCreateUnwrapper();
8484

85-
var instructions = prev.Body.Instructions.Where(i => i.Operand is MethodReference && ((MethodReference)i.Operand).Resolve() == unwrapper).ToList();
85+
var instructions = prev.Body.Instructions.Where(i => i.Operand is MethodReference reference && reference.Resolve() == unwrapper).ToList();
8686

8787
var nextRef = CreateRef(next, prev);
8888

@@ -238,7 +238,9 @@ private void MoveBody(MethodDefinition from, MethodDefinition to)
238238
var fbProc = from.Body.GetILProcessor();
239239
var fdbg = from.DebugInformation;
240240
var fsp = from.DebugInformation.SequencePoints;
241-
var tsp = to.DebugInformation.SequencePoints;
241+
var tsp = to.DebugInformation.SequencePoints;
242+
243+
to.HasThis = from.HasThis;
242244

243245
var codeStart = from.Body.GetUserCodeStart();
244246
var init = codeStart == null ? 0 : frb.IndexOf(codeStart);
@@ -261,18 +263,34 @@ private void MoveBody(MethodDefinition from, MethodDefinition to)
261263
}
262264
}
263265

264-
to.DebugInformation.Scope = new ScopeDebugInformation(to.Body.Instructions.First(), to.Body.Instructions.Last());
265-
266-
if (from.DebugInformation.Scope != null)
267-
to.DebugInformation.Scope.Import = from.DebugInformation.Scope.Import;
266+
if (from.DebugInformation.Scope != null)
267+
{
268+
to.DebugInformation.Scope = from.DebugInformation.Scope;
269+
to.DebugInformation.Scope.Start = new InstructionOffset(to.Body.Instructions[0].Offset);
270+
to.DebugInformation.Scope.End = new InstructionOffset(to.Body.Instructions[to.Body.Instructions.Count - 1].Offset);
271+
from.DebugInformation.Scope = null;
272+
}
273+
274+
275+
//to.DebugInformation.StateMachineKickOffMethod = from;
276+
277+
if (from.DebugInformation.StateMachineKickOffMethod != null)
278+
{
279+
to.DebugInformation.StateMachineKickOffMethod = from.DebugInformation.StateMachineKickOffMethod;
280+
from.DebugInformation.StateMachineKickOffMethod = null;
281+
}
268282

269283
if (from.DebugInformation.HasCustomDebugInformations)
270284
foreach (var cdi in from.DebugInformation.CustomDebugInformations.ToArray())
271285
{
272286
from.DebugInformation.CustomDebugInformations.Remove(cdi);
273287
to.DebugInformation.CustomDebugInformations.Add(cdi);
274-
}
275-
288+
}
289+
290+
//var cstm = new StateMachineScopeDebugInformation();
291+
//cstm.Scopes.Add(new StateMachineScope(to.Body.Instructions[0], to.Body.Instructions[to.Body.Instructions.Count - 1]));
292+
//to.CustomDebugInformations.Add(cstm);
293+
276294
var to_vars = to.Body.Variables;
277295
foreach (var var in from.Body.Variables)
278296
to_vars.Add(new VariableDefinition(to.Module.ImportReference(var.VariableType)));
@@ -323,4 +341,4 @@ private static string GetAroundMethodPrefix(MethodDefinition target)
323341
return $"{Constants.Prefix}around_{target.Name}_{target.MetadataToken.ToUInt32()}_";
324342
}
325343
}
326-
}
344+
}

src/AspectInjector.Core/AspectInjector.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
9-
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
9+
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<ProjectReference Include="..\FluentIL\FluentIL.csproj" />

src/AspectInjector/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
@@ -18,7 +18,7 @@ private static int Main(string[] args)
1818

1919
var optimize = false;
2020
var verbose = false;
21-
List<string> references = new List<string>();
21+
List<string> references = new();
2222

2323
for (int i = 0; i < args.Length; i++)
2424
{

src/FluentIL/FluentIL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
10-
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
10+
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

src/FluentIL/MethodEditor.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using FluentIL.Extensions;
1+
using FluentIL.Extensions;
22
using Mono.Cecil;
33
using Mono.Cecil.Cil;
44
using System;
@@ -64,15 +64,20 @@ public static void Instead(this MethodBody body, PointCut action)
6464
.Here(action);
6565
}
6666

67-
public static void Mark(this MethodDefinition method, TypeReference attribute)
67+
public static void Mark(this MethodDefinition method, TypeReference attribute, params CustomAttributeArgument[] args)
6868
{
6969
if (method.CustomAttributes.Any(ca => ca.AttributeType.FullName == attribute.FullName))
7070
return;
7171

7272
var constructor = method.Module.ImportReference(attribute).Resolve()
7373
.Methods.First(m => m.IsConstructor && !m.IsStatic);
7474

75-
method.CustomAttributes.Add(new CustomAttribute(method.Module.ImportReference(constructor)));
75+
var attr = new CustomAttribute(method.Module.ImportReference(constructor));
76+
77+
foreach (var arg in args)
78+
attr.ConstructorArguments.Add(arg);
79+
80+
method.CustomAttributes.Add(attr);
7681
}
7782

7883
public static Instruction GetCodeStart(this MethodBody body)
@@ -146,4 +151,4 @@ public static void OnEveryOccasionOf(this MethodBody body, Func<Instruction, boo
146151
new Cut(body, curi).Here(pc);
147152
}
148153
}
149-
}
154+
}

tests/AspectInjector.Analyzer.Tests/AspectInjector.Analyzer.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
1010
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1313
</PackageReference>
1414
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.10.0" />
15-
<PackageReference Include="xunit" Version="2.4.1" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15+
<PackageReference Include="xunit" Version="2.4.2" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1919
</PackageReference>

tests/AspectInjector.Tests.Generics/AspectInjector.Tests.Generics.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net6.0</TargetFrameworks>
55
<LangVersion>7.1</LangVersion>
66
<Configurations>Debug;Release;DebugTests</Configurations>
77
</PropertyGroup>

tests/AspectInjector.Tests.Integrity/AspectInjector.Tests.Integrity.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
<ItemGroup>
99
<PackageReference Include="Unofficial.CoreRT.ILVerify" Version="0.0.1" />
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
11-
<PackageReference Include="xunit" Version="2.4.1" />
12-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
11+
<PackageReference Include="xunit" Version="2.4.2" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1515
</PackageReference>

tests/AspectInjector.Tests.Runtime/AspectInjector.Tests.Runtime.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp3.1;net6.0;net471;net461</TargetFrameworks>
3+
<TargetFrameworks>net6.0;net462;net470;net480</TargetFrameworks>
44
<LangVersion>7.3</LangVersion>
55
<Configurations>Debug;Release;DebugTests</Configurations>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
9-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
8+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
9+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
1010
<PrivateAssets>all</PrivateAssets>
1111
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1212
</PackageReference>
13-
<PackageReference Include="xunit" Version="2.4.1" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<PackageReference Include="xunit" Version="2.4.2" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1515
<PrivateAssets>all</PrivateAssets>
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1717
</PackageReference>

tests/AspectInjector.Tests.RuntimeAssets/AspectInjector.Tests.RuntimeAssets.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Configurations>Debug;Release;DebugTests</Configurations>
4-
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0;net471;net461</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net6.0;net462;net470;net480</TargetFrameworks>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
7+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
88
<PrivateAssets>all</PrivateAssets>
99
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1010
</PackageReference>

tests/AspectInjector.Tests.VBRuntime/AspectInjector.Tests.VBRuntime.vbproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp3.1;net6.0;net471;net461</TargetFrameworks>
3+
<TargetFrameworks>net6.0;net462;net470;net480</TargetFrameworks>
44
<Configurations>Debug;Release;DebugTests</Configurations>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
8-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
7+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
8+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
99
<PrivateAssets>all</PrivateAssets>
1010
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1111
</PackageReference>
12-
<PackageReference Include="xunit" Version="2.4.1" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
12+
<PackageReference Include="xunit" Version="2.4.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1616
</PackageReference>

0 commit comments

Comments
 (0)