示例#1
0
        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);
        }
示例#2
0
        public static Game TryGame(this IDataObjectChild obj)
        {
            if (obj is IRootDataObject root)
            {
                return(root.Game);
            }

            root = obj.Ancestor <IRootDataObject>();
            return(root?.Game);
        }
示例#3
0
 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);
 }
示例#4
0
 public static bool IsInCollection(this IDataObjectChild obj) =>
 obj.Parent is ICollection;