forked from dnSpy/ICSharpCode.TreeView
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExtensionMethods.cs
More file actions
37 lines (33 loc) · 910 Bytes
/
ExtensionMethods.cs
File metadata and controls
37 lines (33 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows;
using System.Collections;
using System.Windows.Input;
namespace ICSharpCode.TreeView
{
static class ExtensionMethods
{
public static T FindAncestor<T>(this DependencyObject d) where T : class
{
return AncestorsAndSelf(d).OfType<T>().FirstOrDefault();
}
public static IEnumerable<DependencyObject> AncestorsAndSelf(this DependencyObject d)
{
while (d != null) {
yield return d;
d = VisualTreeHelper.GetParent(d);
}
}
public static void AddOnce(this IList list, object item)
{
if (!list.Contains(item)) {
list.Add(item);
}
}
}
}