Skip to content

Commit

Permalink
0.7.3: Ability to export an inline attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-st committed Jun 24, 2024
1 parent bd10bd3 commit 7d9d2cf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/InlineMethod.Fody/InlineMethodWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 6 additions & 2 deletions src/InlineMethod.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/InlineMethod/InlineAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ public class InlineAttribute : Attribute
/// </summary>
public InlineBehavior Behavior { get; }

/// <summary>
/// Export attribute
/// </summary>
public bool Export { get; }

/// <summary>
/// Initialize a new instance
/// </summary>
/// <param name="behavior"></param>
public InlineAttribute(InlineBehavior behavior = InlineBehavior.RemovePrivate)
/// <param name="export"></param>
public InlineAttribute(InlineBehavior behavior = InlineBehavior.RemovePrivate, bool export = false)
{
Behavior = behavior;
Export = export;
}
}
}
2 changes: 1 addition & 1 deletion src/InlineMethod/InlineMethod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageOutputPath>$(SolutionDir)/../nugets</PackageOutputPath>
<PackageProjectUrl>https://github.com/oleg-st/InlineMethod.Fody</PackageProjectUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>0.7.2</Version>
<Version>0.7.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 7d9d2cf

Please sign in to comment.