- 1
static bool AlwaysTrue<T>(T obj) { return true; }
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+135
static bool AlwaysTrue<T>(T obj) { return true; }
ыыы
{
static bool AlwaysTrue<T>(T obj) { return true; }
/// <summary>
/// Finds a parent of a given item on the visual tree. If the element is a ContentElement or FrameworkElement
/// it will use the logical tree to jump the gap.
/// If not matching item can be found, a null reference is returned.
/// </summary>
/// <typeparam name="T">The type of the element to be found</typeparam>
/// <param name="child">A direct or indirect child of the wanted item.</param>
/// <returns>The first parent item that matches the submitted type parameter. If not matching item can be found, a null reference is returned.</returns>
public static T FindParent<T>(DependencyObject child) where T : DependencyObject
{
return FindParent<T>(child, AlwaysTrue<T>);
}
public static T FindParent<T>(DependencyObject child, Predicate<T> predicate) where T : DependencyObject
{
DependencyObject parent = GetParent(child);
if (parent == null)
return null;
// check if the parent matches the type and predicate we're looking for
if ((parent is T) && (predicate((T)parent)))
return parent as T;
else
return FindParent<T>(parent);
}
static DependencyObject GetParent(DependencyObject child)
{
DependencyObject parent = null;
if (child is Visual || child is Visual3D)
parent = VisualTreeHelper.GetParent(child);
// if fails to find a parent via the visual tree, try to logical tree.
return parent ?? LogicalTreeHelper.GetParent(child);
}
}
New Achievement Unlocked: BBCode.
Team Bonus: +10% prettier posts.
не мне одному.
Может вы опишите?
Примерно вот так это выглядело:
РульныйDSL +1
Только это EDSL, а не DSL
PS
У вас там очепяточка в togehter в конце предложения.
Т.е. это развоначно лямбдоподобному синтаксису типа \lambda x => true.
Автор мудак как и все заплюсовавшие и большинство завсегдатаев сего сайта.
Спасибо, кеп.
>мудак как и все заплюсовавшие и большинство завсегдатаев сего сайта.
Ну да. Один ты дАртаньян.