A game framework written with osu! in mind.
at master 48 lines 1.5 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using osu.Framework.Extensions.TypeExtensions; 6 7namespace osu.Framework.Allocation 8{ 9 public readonly struct CacheInfo : IEquatable<CacheInfo> 10 { 11 /// <summary> 12 /// The name of the cached member. 13 /// </summary> 14 public readonly string Name; 15 16 /// <summary> 17 /// The type containing the cached member. 18 /// </summary> 19 public readonly Type Parent; 20 21 /// <summary> 22 /// The type of the cached member. 23 /// </summary> 24 internal readonly Type Type; 25 26 public CacheInfo(string name = null, Type parent = null) 27 : this(null, name, parent) 28 { 29 } 30 31 private CacheInfo(Type type, string name, Type parent) 32 { 33 Type = type; 34 Name = name; 35 Parent = parent; 36 } 37 38 internal CacheInfo WithType(Type type) => new CacheInfo(type, Name, Parent); 39 40 public override string ToString() => $"{nameof(Type)} = {Type?.ReadableName()}, {nameof(Name)} = {Name}, {nameof(Parent)} = {Parent?.ReadableName()}"; 41 42 public override bool Equals(object obj) => obj is CacheInfo cacheInfo && Equals(cacheInfo); 43 44 public bool Equals(CacheInfo other) => Name == other.Name && Parent == other.Parent && Type == other.Type; 45 46 public override int GetHashCode() => HashCode.Combine(Name, Parent, Type); 47 } 48}