1.6 to main #1
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,9 @@ using System.Collections.Concurrent;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
|
using Verse;
|
||||||
|
|
||||||
namespace FisheryLib.FunctionPointers;
|
namespace FisheryLib.FunctionPointers;
|
||||||
|
|
||||||
@@ -64,12 +66,18 @@ public abstract class MethodFactory(MethodInfo[] methods, string namePrefix, boo
|
|||||||
=> type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly)
|
=> type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly)
|
||||||
.Where(predicate).ToArray();
|
.Where(predicate).ToArray();
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected static bool UseReferenceIdentity(Type type)
|
||||||
|
=> !type.IsValueType && typeof(Thing).IsAssignableFrom(type);
|
||||||
|
|
||||||
public new class Equals(Type type, string dynamicMethodNamePrefix, bool byRef)
|
public new class Equals(Type type, string dynamicMethodNamePrefix, bool byRef)
|
||||||
: MethodFactory(GetMethodInfoArraySafely(type), dynamicMethodNamePrefix, byRef)
|
: MethodFactory(GetMethodInfoArraySafely(type), dynamicMethodNamePrefix, byRef)
|
||||||
{
|
{
|
||||||
protected override MethodInfo GetOrMakeMethodForType(Type type)
|
protected override MethodInfo GetOrMakeMethodForType(Type type)
|
||||||
=> GetSpecializedMethod(type)
|
=> GetSpecializedMethod(type)
|
||||||
?? (type.IsAssignableTo(typeof(IEquatable<>), type)
|
?? (UseReferenceIdentity(type)
|
||||||
|
? GetGeneric(nameof(FunctionPointers.Equals.Methods.Reference), type)
|
||||||
|
: type.IsAssignableTo(typeof(IEquatable<>), type)
|
||||||
? GetGeneric(type.IsValueType
|
? GetGeneric(type.IsValueType
|
||||||
? nameof(FunctionPointers.Equals.Methods.EquatableValueType)
|
? nameof(FunctionPointers.Equals.Methods.EquatableValueType)
|
||||||
: nameof(FunctionPointers.Equals.Methods.EquatableReferenceType), type)
|
: nameof(FunctionPointers.Equals.Methods.EquatableReferenceType), type)
|
||||||
@@ -235,7 +243,9 @@ public abstract class MethodFactory(MethodInfo[] methods, string namePrefix, boo
|
|||||||
{
|
{
|
||||||
protected override MethodInfo GetOrMakeMethodForType(Type type)
|
protected override MethodInfo GetOrMakeMethodForType(Type type)
|
||||||
=> GetSpecializedMethod(type)
|
=> GetSpecializedMethod(type)
|
||||||
?? (type.IsNullable(out var genericArgument)
|
?? (UseReferenceIdentity(type)
|
||||||
|
? GetGeneric(nameof(FunctionPointers.GetHashCode.Methods.Reference), type)
|
||||||
|
: type.IsNullable(out var genericArgument)
|
||||||
&& genericArgument.IsAssignableTo(typeof(IEquatable<>), genericArgument)
|
&& genericArgument.IsAssignableTo(typeof(IEquatable<>), genericArgument)
|
||||||
? GetGeneric(nameof(FunctionPointers.GetHashCode.Methods.Nullable), genericArgument)
|
? GetGeneric(nameof(FunctionPointers.GetHashCode.Methods.Nullable), genericArgument)
|
||||||
: type.IsEnum
|
: type.IsEnum
|
||||||
|
|||||||
Reference in New Issue
Block a user