Skip to content

Commit

Permalink
Merge branch 'issues/i72' into issues/hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
inversionhourglass committed Jul 4, 2024
2 parents 238659b + 1003e8e commit 23ebe3c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- [[#71](https://github.com/inversionhourglass/Rougamo/issues/71)] 修复blazor项目在发布时illink对程序集做裁减优化时产生的异常
> 程序集主要描述信息基本存储在ModuleDefinition的MetadataSystem字段中,各类型的原数据也基本从该对象中读取。然而通过删除/清空MethodDefinition的CustomDebugInformation并不会影响MetadataSystem中的数据,同时,在将修改写入程序集时,MetadataSystem中绝大部分数据都将直接清空后重新写入,然而CustomDebugInformation是个例外,这就导致MethodDefinition上对CustomDebugInformations的删除/清空操作无效。所以对CustomDebugInformation的删除操作还需要从MetadataSystem中的删除。参考 [MetadataSystem.Clear()](https://github.com/jbevain/cecil/blob/8e1ae7b4ea67ccc38cb8db3ded6802643109ffd7/Mono.Cecil/MetadataSystem.cs#L137)
- [[#72](https://github.com/inversionhourglass/Rougamo/issues/72)] 修复Feature属性直接设置初始值的方式无效的问题

---
1 change: 1 addition & 0 deletions src/Rougamo.Fody/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal static class Constants
public const string TYPE_IgnoreMoAttribute = "Rougamo.IgnoreMoAttribute";
public const string TYPE_MoRepulsion = "Rougamo.MoRepulsion";
public const string TYPE_AccessFlags = "Rougamo.AccessFlags";
public const string TYPE_Feature = "Rougamo.Feature";
public const string TYPE_Omit = "Rougamo.Context.Omit";
public const string TYPE_IRougamo_1 = "Rougamo.IRougamo`1";
public const string TYPE_IRougamo_2 = "Rougamo.IRougamo`2";
Expand Down
2 changes: 1 addition & 1 deletion src/Rougamo.Fody/Extensions/ModelExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static int ExtractFeatures(this Mo mo)
}
typeDef = mo.Attribute.AttributeType.Resolve();
}
var features = ExtractFromIl(typeDef!, Constants.PROP_Features, Constants.TYPE_Int32, ParseFeatures);
var features = ExtractFromIl(typeDef!, Constants.PROP_Features, Constants.TYPE_Feature, ParseFeatures);
return features ?? (int)Feature.All;
}

Expand Down
14 changes: 12 additions & 2 deletions test/Rougamo.Fody.Tests/IssueTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task Issue8Test()
instance.Command1();

instance.Execute();

await Task.Delay(1000);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public async Task Issue32Test()
{
var instance = GetInstance(nameof(Issue32));

var r1 = await(Task<int>)instance.WithoutAsync();
var r1 = await (Task<int>)instance.WithoutAsync();
var r2 = await (Task<int>)instance.WithAsync();

Assert.Equal(_32_Attribute.IntValue, r1);
Expand Down Expand Up @@ -199,5 +199,15 @@ public void Issue66Test()
var instance = GetInstance("Issue66`2", false, t => t.MakeGenericType(typeof(int), typeof(int)));
instance.M();
}

[Fact]
public void Issue72Test()
{
var instance = GetInstance(nameof(Issue72));
var logs = new List<string>();
instance.Plus(logs, 1, 2);

Assert.Equal(["OnEntry"], logs);
}
}
}
45 changes: 45 additions & 0 deletions test/TestAssemblies/Issues/Attributes/_72_.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Rougamo;
using Rougamo.Context;
using System.Collections.Generic;

namespace Issues.Attributes
{
public struct _72_ : IMo
{
public _72_() { }

public AccessFlags Flags { get; } = AccessFlags.All;

public string Pattern { get; } = null;

public Feature Features { get; } = Feature.OnEntry;

public double Order { get; } = 1;

public Omit MethodContextOmits { get; } = Omit.None;

public void OnEntry(MethodContext context)
{
var list = (List<string>)context.Arguments[0];
list.Add(nameof(OnEntry));
}

public void OnException(MethodContext context)
{
var list = (List<string>)context.Arguments[0];
list.Add(nameof(OnException));
}

public void OnExit(MethodContext context)
{
var list = (List<string>)context.Arguments[0];
list.Add(nameof(OnExit));
}

public void OnSuccess(MethodContext context)
{
var list = (List<string>)context.Arguments[0];
list.Add(nameof(OnSuccess));
}
}
}
12 changes: 12 additions & 0 deletions test/TestAssemblies/Issues/Issue72.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Issues.Attributes;
using Rougamo;
using System.Collections.Generic;

namespace Issues
{
public class Issue72
{
[Rougamo<_72_>]
public int Plus(List<string> logs, int x, int y) => x + y;
}
}

0 comments on commit 23ebe3c

Please sign in to comment.