/// <summary> /// looks for the "As face" by walking up the decorators /// </summary> /// <param name="obj"></param> /// <param name="decorationType"></param> /// <param name="exactTypeMatch"></param> /// <returns></returns> public static object AsAbove(this object obj, Type decorationType, bool exactTypeMatch = true) { if (obj == null) { return(null); } var match = IDecoratorAwareDecorationExtensions.WalkDecoratorsToOuter(obj, (dec) => { //do type level filtering first //if we're exact matching, the decoration has to be the same type if (exactTypeMatch && decorationType.Equals(dec.GetType()) == false) { return(false); } //if we're not exact matching, the decoration has to be Of the same type if (exactTypeMatch == false && (!(decorationType.IsAssignableFrom(dec.GetType())))) { return(false); } return(true); }); return(match); }
/// <summary> /// looks for the "As face" by walking ALL the decorations. If DecoratorAware, walks down from Outer. If not /// DecoratorAware, walks down from Self /// </summary> /// <param name="obj"></param> /// <param name="decorationType"></param> /// <param name="exactTypeMatch"></param> /// <returns></returns> public static object As(this object obj, Type decorationType, bool exactTypeMatch) { if (obj == null) { return(null); } //if decorator aware get the outer object topMost = obj; if (IDecoratorAwareDecorationExtensions.IsADecoratorAwareDecoration(obj)) { topMost = IDecoratorAwareDecorationExtensions.GetOuterDecorator(obj); } return(AsBelow(topMost, decorationType, exactTypeMatch)); }
/// <summary> /// If DecoratorAware, walks down from Outer. If not DecoratorAware, walks down from Self /// </summary> public static List <object> GetAllDecorations(this object obj) { List <object> rv = new List <object>(); if (obj == null) { return(rv); } //if decorator aware get the outer object topMost = obj; if (IDecoratorAwareDecorationExtensions.IsADecoratorAwareDecoration(obj)) { topMost = IDecoratorAwareDecorationExtensions.GetOuterDecorator(obj); } rv = IDecorationExtensions.GetSelfAndAllDecorationsBelow(topMost); return(rv); }