Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StructLayout(LayoutKind.Auto)]
- private readonly struct ReflectionCacheKey :
- IEquatable<ReflectionCacheKey>
- {
- private const bool Intern = false;
- internal readonly int Hash;
- internal readonly Type MemberType { get; init; }
- internal readonly bool IsStatic { get; init; }
- internal readonly Type Type { get; init; }
- internal readonly string MemberName { get; init; }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal ReflectionCacheKey(Type memberType, bool isStatic, Type type, string memberName)
- {
- if (ReflectionCacheKey.Intern)
- {
- memberName = string.Intern(memberName);
- }
- this.MemberType = memberType;
- this.IsStatic = isStatic;
- this.Type = type;
- this.MemberName = memberName;
- this.Hash = HashCode.Combine(
- memberType,
- isStatic,
- type,
- memberName
- );
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- readonly bool IEquatable<ReflectionCacheKey>.Equals(ReflectionCacheKey other) => this.Equals(in other);
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal readonly bool Equals(in ReflectionCacheKey other)
- {
- return
- this.Hash == other.Hash &&
- this.MemberType == other.MemberType &&
- this.IsStatic == other.IsStatic &&
- this.Type == other.Type &&
- this.MemberName == other.MemberName;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly override bool Equals(object? other)
- {
- if (other is ReflectionCacheKey otherKey)
- {
- return this.Equals(otherKey);
- }
- return false;
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator ==(in ReflectionCacheKey lhs, in ReflectionCacheKey rhs) => lhs.Equals(rhs);
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static bool operator !=(in ReflectionCacheKey lhs, in ReflectionCacheKey rhs) => !lhs.Equals(rhs);
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly override int GetHashCode() => this.Hash;
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly override string ToString() =>
- $"{this.MemberType}{(this.IsStatic ? 's' : 'i')}{this.Type.FullName}:{this.MemberName}";
- }
Advertisement
Add Comment
Please, Sign In to add comment