diff --git a/Equals.Fody/Extensions/MethodReferenceExtensions.cs b/Equals.Fody/Extensions/MethodReferenceExtensions.cs index bd96725..b0dc8ee 100644 --- a/Equals.Fody/Extensions/MethodReferenceExtensions.cs +++ b/Equals.Fody/Extensions/MethodReferenceExtensions.cs @@ -29,6 +29,7 @@ public static OpCode GetCallForMethod(this MethodReference methodReference) { return OpCodes.Call; } + return OpCodes.Callvirt; } } \ No newline at end of file diff --git a/Equals.Fody/Extensions/TypeDefinitionExtensions.cs b/Equals.Fody/Extensions/TypeDefinitionExtensions.cs index e255505..31f73bb 100644 --- a/Equals.Fody/Extensions/TypeDefinitionExtensions.cs +++ b/Equals.Fody/Extensions/TypeDefinitionExtensions.cs @@ -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) { diff --git a/Equals.Fody/Injectors/EqualsInjector.cs b/Equals.Fody/Injectors/EqualsInjector.cs index 9ae7781..7419192 100644 --- a/Equals.Fody/Injectors/EqualsInjector.cs +++ b/Equals.Fody/Injectors/EqualsInjector.cs @@ -13,21 +13,24 @@ public partial class ModuleWeaver const int ExactlyOfType = 1; const int EqualsOrSubtype = 2; - static HashSet 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 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) { diff --git a/Equals.Fody/ModuleWeaver.cs b/Equals.Fody/ModuleWeaver.cs index 894fe34..43ee175 100644 --- a/Equals.Fody/ModuleWeaver.cs +++ b/Equals.Fody/ModuleWeaver.cs @@ -16,11 +16,9 @@ public partial class ModuleWeaver : public const string DoNotAddEquals = "DoNotAddEquals"; public const string IgnoreBaseClassProperties = "IgnoreBaseClassProperties"; - public IEnumerable GetMatchingTypes() - { - return ModuleDefinition.GetTypes() + public IEnumerable GetMatchingTypes() => + ModuleDefinition.GetTypes() .Where(_ => _.CustomAttributes.Any(a => a.AttributeType.Name == attributeName)); - } static TypeReference GetGenericType(TypeReference type) { diff --git a/Equals.Fody/WeavingInstruction.cs b/Equals.Fody/WeavingInstruction.cs index 3f34f5f..0610f55 100644 --- a/Equals.Fody/WeavingInstruction.cs +++ b/Equals.Fody/WeavingInstruction.cs @@ -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)) @@ -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)); } diff --git a/Tests/AssemblyWithoutReferenceTests.cs b/Tests/AssemblyWithoutReferenceTests.cs index d54ee5e..29b37dd 100644 --- a/Tests/AssemblyWithoutReferenceTests.cs +++ b/Tests/AssemblyWithoutReferenceTests.cs @@ -1,5 +1,4 @@ -using Fody; -using Xunit; +using Xunit; public class AssemblyWithoutReferenceTests { diff --git a/Tests/BadCaseIntegrationTests.cs b/Tests/BadCaseIntegrationTests.cs index 0d832d9..038e020 100644 --- a/Tests/BadCaseIntegrationTests.cs +++ b/Tests/BadCaseIntegrationTests.cs @@ -1,5 +1,4 @@ -using Fody; -using Xunit; +using Xunit; public class OperatorBadCaseIntegrationTests { diff --git a/Tests/GlobalUsings.cs b/Tests/GlobalUsings.cs new file mode 100644 index 0000000..aeeb0bc --- /dev/null +++ b/Tests/GlobalUsings.cs @@ -0,0 +1,3 @@ +// Global using directives + +global using Fody; \ No newline at end of file diff --git a/Tests/IntegrationTests.cs b/Tests/IntegrationTests.cs index c49c3be..407739b 100644 --- a/Tests/IntegrationTests.cs +++ b/Tests/IntegrationTests.cs @@ -1,8 +1,4 @@ -using Fody; -using VerifyXunit; - -[UsesVerify] -public partial class IntegrationTests +public partial class IntegrationTests { static IntegrationTests() {