From 7d9d2cf0cd40b095966d736a1d3fd0f737aaca5b Mon Sep 17 00:00:00 2001 From: Oleg Stepanischev Date: Tue, 25 Jun 2024 00:09:38 +0300 Subject: [PATCH] 0.7.3: Ability to export an inline attribute --- src/InlineMethod.Fody/InlineMethodWeaver.cs | 14 ++++++++++++++ src/InlineMethod.Fody/ModuleWeaver.cs | 8 ++++++-- src/InlineMethod/InlineAttribute.cs | 9 ++++++++- src/InlineMethod/InlineMethod.csproj | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/InlineMethod.Fody/InlineMethodWeaver.cs b/src/InlineMethod.Fody/InlineMethodWeaver.cs index daea79e..91fc91a 100644 --- a/src/InlineMethod.Fody/InlineMethodWeaver.cs +++ b/src/InlineMethod.Fody/InlineMethodWeaver.cs @@ -233,6 +233,20 @@ private void FixInstructions() while (instruction != null) { var nextInstruction = instruction.Next; + if (instruction.Operand is FieldReference opFieldReference) + { + instruction.Operand = _moduleWeaver.ModuleDefinition.ImportReference(opFieldReference); + } + + if (instruction.Operand is MethodReference opMethodReference) + { + instruction.Operand = _moduleWeaver.ModuleDefinition.ImportReference(opMethodReference); + } + + if (instruction.Operand is TypeReference opTypeReference) + { + instruction.Operand = _moduleWeaver.ModuleDefinition.ImportReference(opTypeReference); + } if (instruction.Operand is Instruction opInstruction) { diff --git a/src/InlineMethod.Fody/ModuleWeaver.cs b/src/InlineMethod.Fody/ModuleWeaver.cs index ea6af5f..351d183 100644 --- a/src/InlineMethod.Fody/ModuleWeaver.cs +++ b/src/InlineMethod.Fody/ModuleWeaver.cs @@ -74,7 +74,7 @@ public override void Execute() var attr = GetInlineAttribute(method); if (attr != null) { - var value = attr.ConstructorArguments.Single().Value; + var value = attr.ConstructorArguments.First().Value; if (value is bool boolValue) { value = boolValue ? InlineBehavior.RemovePrivate : InlineBehavior.Keep; @@ -88,8 +88,12 @@ public override void Execute() } else { + var export = (bool)(attr.ConstructorArguments.Skip(1).FirstOrDefault().Value ?? false); // consume attribute - method.CustomAttributes.Remove(attr); + if (!export) + { + method.CustomAttributes.Remove(attr); + } } } } diff --git a/src/InlineMethod/InlineAttribute.cs b/src/InlineMethod/InlineAttribute.cs index ed2282a..9e7ea9b 100644 --- a/src/InlineMethod/InlineAttribute.cs +++ b/src/InlineMethod/InlineAttribute.cs @@ -13,13 +13,20 @@ public class InlineAttribute : Attribute /// public InlineBehavior Behavior { get; } + /// + /// Export attribute + /// + public bool Export { get; } + /// /// Initialize a new instance /// /// - public InlineAttribute(InlineBehavior behavior = InlineBehavior.RemovePrivate) + /// + public InlineAttribute(InlineBehavior behavior = InlineBehavior.RemovePrivate, bool export = false) { Behavior = behavior; + Export = export; } } } diff --git a/src/InlineMethod/InlineMethod.csproj b/src/InlineMethod/InlineMethod.csproj index 5cf7dd3..506de7b 100644 --- a/src/InlineMethod/InlineMethod.csproj +++ b/src/InlineMethod/InlineMethod.csproj @@ -12,7 +12,7 @@ $(SolutionDir)/../nugets https://github.com/oleg-st/InlineMethod.Fody false - 0.7.2 + 0.7.3