internal static ScreenshotMaker.ScreenshotMaker GetScrenshotMakerStrategy(BaseScreenshotDecorator strategy) { var nestedStrategies = GetNestedStrategies(strategy).ToList(); if (nestedStrategies.Any()) { var sm = nestedStrategies.FirstOrDefault(q => q.GetType() == typeof(ScreenshotMaker.ScreenshotMaker)); if (sm != null) { return(sm as ScreenshotMaker.ScreenshotMaker); } } return(null); }
private static IEnumerable <IScreenshotStrategy> GetNestedStrategies(BaseScreenshotDecorator strategy) { var nestedStrategy = strategy.NestedStrategy; if (nestedStrategy == null) { yield break; } do { yield return(nestedStrategy); strategy = nestedStrategy as BaseScreenshotDecorator; nestedStrategy = strategy?.NestedStrategy; } while (nestedStrategy != null); }