Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 30, 2024
1 parent 847653c commit b3eb7cb
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 49 deletions.
1 change: 1 addition & 0 deletions Equals.Fody/Extensions/MethodReferenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static OpCode GetCallForMethod(this MethodReference methodReference)
{
return OpCodes.Call;
}

return OpCodes.Callvirt;
}
}
14 changes: 5 additions & 9 deletions Equals.Fody/Extensions/TypeDefinitionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@

static class TypeDefinitionExtensions
{
public static MethodDefinition FindMethod(this TypeDefinition typeDefinition, string method, params string[] paramTypes)
{
return typeDefinition.Methods
public static MethodDefinition FindMethod(this TypeDefinition typeDefinition, string method, params string[] paramTypes) =>
typeDefinition.Methods
.First(_ => _.Name == method &&
_.IsMatch(paramTypes));
}

public static bool IsCollection(this TypeDefinition type)
{
return !type.Name.Equals("String") &&
type.Interfaces.Any(_ => _.InterfaceType.Name.Equals("IEnumerable"));
}
public static bool IsCollection(this TypeDefinition type) =>
!type.Name.Equals("String") &&
type.Interfaces.Any(_ => _.InterfaceType.Name.Equals("IEnumerable"));

public static PropertyDefinition[] GetPropertiesWithoutIgnores(this TypeDefinition type, string ignoreAttributeName)
{
Expand Down
33 changes: 18 additions & 15 deletions Equals.Fody/Injectors/EqualsInjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ public partial class ModuleWeaver
const int ExactlyOfType = 1;
const int EqualsOrSubtype = 2;

static HashSet<string> simpleTypes = new(new[]
{
"System.Boolean",
"System.Byte",
"System.SByte",
"System.Char",
"System.Double",
"System.Single",
"System.Int32",
"System.UInt32",
"System.Int64",
"System.UInt64",
"System.Int16",
"System.UInt16"
});
static HashSet<string> simpleTypes =
[
..new[]
{
"System.Boolean",
"System.Byte",
"System.SByte",
"System.Char",
"System.Double",
"System.Single",
"System.Int32",
"System.UInt32",
"System.Int64",
"System.UInt64",
"System.Int16",
"System.UInt16"
}
];

void InjectEqualsObject(TypeDefinition type, TypeReference typeRef, MethodReference newEquals, int typeCheck)
{
Expand Down
6 changes: 2 additions & 4 deletions Equals.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ public partial class ModuleWeaver :
public const string DoNotAddEquals = "DoNotAddEquals";
public const string IgnoreBaseClassProperties = "IgnoreBaseClassProperties";

public IEnumerable<TypeDefinition> GetMatchingTypes()
{
return ModuleDefinition.GetTypes()
public IEnumerable<TypeDefinition> GetMatchingTypes() =>
ModuleDefinition.GetTypes()
.Where(_ => _.CustomAttributes.Any(a => a.AttributeType.Name == attributeName));
}

static TypeReference GetGenericType(TypeReference type)
{
Expand Down
15 changes: 3 additions & 12 deletions Equals.Fody/WeavingInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@
using Mono.Cecil;
using Mono.Cecil.Cil;

public class WeavingInstruction
public class WeavingInstruction(MethodDefinition weaveMethod)
{
MethodDefinition weaveMethod;

public WeavingInstruction(MethodDefinition weaveMethod)
{
this.weaveMethod = weaveMethod;
}

public MethodDefinition RetrieveOperatorAndAssertHasWeavingInstruction(TypeDefinition type, Operator @operator)
{
if (!@operator.TryGetOperator(type, out var operatorMethod))
Expand Down Expand Up @@ -75,8 +68,6 @@ bool IsOperatorWeaveTarget(object operand)
return false;
}

static WeavingException CreateException(FormattableString message)
{
return new(FormattableString.Invariant(message));
}
static WeavingException CreateException(FormattableString message) =>
new(FormattableString.Invariant(message));
}
3 changes: 1 addition & 2 deletions Tests/AssemblyWithoutReferenceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Fody;
using Xunit;
using Xunit;

public class AssemblyWithoutReferenceTests
{
Expand Down
3 changes: 1 addition & 2 deletions Tests/BadCaseIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Fody;
using Xunit;
using Xunit;

public class OperatorBadCaseIntegrationTests
{
Expand Down
3 changes: 3 additions & 0 deletions Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Global using directives

global using Fody;
6 changes: 1 addition & 5 deletions Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Fody;
using VerifyXunit;

[UsesVerify]
public partial class IntegrationTests
public partial class IntegrationTests
{
static IntegrationTests()
{
Expand Down

0 comments on commit b3eb7cb

Please sign in to comment.