/// <summary> /// Un-decorates <see cref="LessEngine" /> from <paramref name="engine" />. Can process only /// <see cref="CacheDecorator" /> and <see cref="ParameterDecorator" />, otherwise raises exception. /// </summary> /// <param name="engine">Possibly decorated <see cref="ILessEngine" /></param> /// <exception cref="ArgumentException">Unexpected type of <paramref name="engine" /></exception> /// <returns><see cref="LessEngine" /> instance.</returns> internal static LessEngine ResolveLessEngine(this ILessEngine engine) { if (engine == null) { throw new ArgumentNullException("engine"); } while (true) { var lessEngine = engine as LessEngine; if (lessEngine != null) { return(lessEngine); } var cacheDecorator = engine as CacheDecorator; if (cacheDecorator != null) { engine = cacheDecorator.Underlying; } else { var parameterDecorator = engine as ParameterDecorator; if (parameterDecorator == null) { throw new ArgumentException(string.Format("Cannot resolve {0} to LessEngine", engine.GetType())); } engine = parameterDecorator.Underlying; } } }