|
@@ -69,6 +69,11 @@ namespace InABox.Core
|
|
|
public static bool HasAttribute<TAttribute>(this IProperty property) where TAttribute : Attribute
|
|
|
=> property.GetAttribute<TAttribute>() != null;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Get the outermost parent property which has an editor.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="property"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public static IProperty? GetParentWithEditor(this IProperty property)
|
|
|
{
|
|
|
if (property.Parent == null) return null;
|
|
@@ -82,6 +87,34 @@ namespace InABox.Core
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the outermost parent property which matches the predicate.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="property"></param>
|
|
|
+ /// <param name="predicate"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static IProperty? GetOuterParent(this IProperty property, Func<IProperty, bool> predicate)
|
|
|
+ {
|
|
|
+ if (property.Parent == null) return null;
|
|
|
+
|
|
|
+ return property.Parent.GetOuterParent(predicate)
|
|
|
+ ?? (predicate(property.Parent) ? property.Parent : null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets the innermost parent property which matches the predicate.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="property"></param>
|
|
|
+ /// <param name="predicate"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static IProperty? GetParent(this IProperty property, Func<IProperty, bool> predicate)
|
|
|
+ {
|
|
|
+ if (property.Parent == null) return null;
|
|
|
+
|
|
|
+ if(predicate(property.Parent)) return property.Parent;
|
|
|
+ return property.Parent.GetParent(predicate);
|
|
|
+ }
|
|
|
+
|
|
|
public static bool HasParentEditor(this IProperty property)
|
|
|
{
|
|
|
return property.Parent != null && (property.Parent.HasEditor || property.Parent.HasParentEditor());
|