public static Game Game(this IDataObjectChild obj) { var game = obj.TryGame(); if (game == null) { throw new InvalidOperationException("Data object is not part of the object tree"); } return(game); }
public static Game TryGame(this IDataObjectChild obj) { if (obj is IRootDataObject root) { return(root.Game); } root = obj.Ancestor <IRootDataObject>(); return(root?.Game); }
public static T Ancestor <T>(this IDataObjectChild child) where T : class { for (var obj = child.Parent; obj != null; obj = obj.Parent) { if (obj is T x) { return(x); } } return(null); }
public static bool IsInCollection(this IDataObjectChild obj) => obj.Parent is ICollection;