using System; namespace Vellum.Generator { /// /// Describes one type inside a saved type, as plain data an incremental generator step can compare between runs. /// public sealed class TypePart : IEquatable { /// /// Holds how C# spells the type, without a Nullable around it. /// public readonly string Name; /// /// Holds how C# spells the generic type this one is built from, or null if it isn't generic. /// public readonly string OpenName; public readonly PartKind Kind; /// /// Holds where this part's own parts start in the shape, which keeps them next to each other. /// public readonly int FirstChild; public readonly int ChildCount; /// /// Holds the name of the type and of each class it derives from, which a family converter of any of them /// saves. It's empty for a part that isn't a class. /// public readonly EquatableArray FamilyNames; /// /// Holds where the type arguments of the type and of each generic class it derives from are in the shape, /// which a family converter that marks one of its type parameters [Saveable] needs to check. /// public readonly EquatableArray BaseArguments; public TypePart(string name, string openName, PartKind kind, int firstChild, int childCount, EquatableArray familyNames = default, EquatableArray baseArguments = default) { FamilyNames = familyNames; BaseArguments = baseArguments; Name = name; OpenName = openName; Kind = kind; FirstChild = firstChild; ChildCount = childCount; } public bool Equals(TypePart other) { return other != null && Name == other.Name && OpenName == other.OpenName && Kind == other.Kind && FirstChild == other.FirstChild && ChildCount == other.ChildCount && FamilyNames.Equals(other.FamilyNames) && BaseArguments.Equals(other.BaseArguments); } public override bool Equals(object obj) { return Equals(obj as TypePart); } public override int GetHashCode() { return (Name.GetHashCode() * 31 + (int)Kind) * 31 + FirstChild; } } }