// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using osu.Framework.Extensions.TypeExtensions; namespace osu.Framework.Allocation { public readonly struct CacheInfo : IEquatable { /// /// The name of the cached member. /// public readonly string Name; /// /// The type containing the cached member. /// public readonly Type Parent; /// /// The type of the cached member. /// internal readonly Type Type; public CacheInfo(string name = null, Type parent = null) : this(null, name, parent) { } private CacheInfo(Type type, string name, Type parent) { Type = type; Name = name; Parent = parent; } internal CacheInfo WithType(Type type) => new CacheInfo(type, Name, Parent); public override string ToString() => $"{nameof(Type)} = {Type?.ReadableName()}, {nameof(Name)} = {Name}, {nameof(Parent)} = {Parent?.ReadableName()}"; public override bool Equals(object obj) => obj is CacheInfo cacheInfo && Equals(cacheInfo); public bool Equals(CacheInfo other) => Name == other.Name && Parent == other.Parent && Type == other.Type; public override int GetHashCode() => HashCode.Combine(Name, Parent, Type); } }