Пример #1
0
        /// <summary>
        /// looks for the "As face" by walking down the decorations
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="decorationType"></param>
        /// <param name="exactTypeMatch"></param>
        /// <returns></returns>
        public static object AsBelow(this object obj, Type decorationType, bool exactTypeMatch = true)
        {
            if (obj == null)
            {
                return(null);
            }

            var match = IDecorationExtensions.WalkDecorationsToCore(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);
        }
Пример #2
0
        /// <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);
        }