コード例 #1
0
 /// <summary>
 /// Obtains the parent in the selection path for given item</summary>
 /// <param name="selectionPathProvider">Selection path provider</param>
 /// <param name="item">Item whose parent path is obtained</param>
 /// <returns>Parent path of given item</returns>
 public static object Parent(this ISelectionPathProvider selectionPathProvider, object item)
 {
     if (selectionPathProvider != null)
     {
         var selectionPath = selectionPathProvider.GetSelectionPath(item);
         if ((selectionPath != null) && selectionPath.Count > 1)
         {
             return(selectionPath[selectionPath.Count - 2]);
         }
     }
     return(null);
 }
コード例 #2
0
 /// <summary>
 /// Gets the ancestry of the item in selection path,
 /// starting with the item's parent and ending with the top level</summary>
 /// <param name="selectionPathProvider">Selection path provider</param>
 /// <param name="item">Item whose ancestry is obtained</param>
 /// <returns>Ancestry of the item in selection path</returns>
 public static IEnumerable <object> Ancestry(this ISelectionPathProvider selectionPathProvider, object item)
 {
     if (selectionPathProvider != null)
     {
         var selectionPath = selectionPathProvider.GetSelectionPath(item);
         if ((selectionPath != null) && selectionPath.Count > 1)
         {
             for (int i = selectionPath.Count - 2; i >= 0; --i)
             {
                 yield return(selectionPath[i]);
             }
         }
     }
 }