V10: Build warnings in Web.Website (#12332)
* add new rule to globalconfig * Fix warnings in Web.Website * Fix more warnings in Web.Website * Fix more build warnings in Web.Website * Fix more warnings in Web.Website * Fix tests * Fix proper constructor call * Fix not being able to run project * Fix Obsolete method Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
This commit is contained in:
@@ -1,51 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
|
||||
namespace Umbraco.Cms.Web.Website.ViewEngines
|
||||
namespace Umbraco.Cms.Web.Website.ViewEngines;
|
||||
|
||||
/// <summary>
|
||||
/// Wraps all view engines with a <see cref="ProfilingViewEngine" />
|
||||
/// </summary>
|
||||
public class ProfilingViewEngineWrapperMvcViewOptionsSetup : IConfigureOptions<MvcViewOptions>
|
||||
{
|
||||
private readonly IProfiler _profiler;
|
||||
|
||||
/// <summary>
|
||||
/// Wraps all view engines with a <see cref="ProfilingViewEngine"/>
|
||||
/// Initializes a new instance of the <see cref="ProfilingViewEngineWrapperMvcViewOptionsSetup" /> class.
|
||||
/// </summary>
|
||||
public class ProfilingViewEngineWrapperMvcViewOptionsSetup : IConfigureOptions<MvcViewOptions>
|
||||
/// <param name="profiler">The <see cref="IProfiler" /></param>
|
||||
public ProfilingViewEngineWrapperMvcViewOptionsSetup(IProfiler profiler) =>
|
||||
_profiler = profiler ?? throw new ArgumentNullException(nameof(profiler));
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Configure(MvcViewOptions options)
|
||||
{
|
||||
private readonly IProfiler _profiler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProfilingViewEngineWrapperMvcViewOptionsSetup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="profiler">The <see cref="IProfiler"/></param>
|
||||
public ProfilingViewEngineWrapperMvcViewOptionsSetup(IProfiler profiler) => _profiler = profiler ?? throw new ArgumentNullException(nameof(profiler));
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Configure(MvcViewOptions options)
|
||||
if (options == null)
|
||||
{
|
||||
if (options == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
WrapViewEngines(options.ViewEngines);
|
||||
throw new ArgumentNullException(nameof(options));
|
||||
}
|
||||
|
||||
private void WrapViewEngines(IList<IViewEngine> viewEngines)
|
||||
{
|
||||
if (viewEngines == null || viewEngines.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
WrapViewEngines(options.ViewEngines);
|
||||
}
|
||||
|
||||
var originalEngines = viewEngines.ToList();
|
||||
viewEngines.Clear();
|
||||
foreach (IViewEngine engine in originalEngines)
|
||||
{
|
||||
IViewEngine wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine, _profiler);
|
||||
viewEngines.Add(wrappedEngine);
|
||||
}
|
||||
private void WrapViewEngines(IList<IViewEngine> viewEngines)
|
||||
{
|
||||
if (viewEngines.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var originalEngines = viewEngines.ToList();
|
||||
viewEngines.Clear();
|
||||
foreach (IViewEngine engine in originalEngines)
|
||||
{
|
||||
IViewEngine wrappedEngine =
|
||||
engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine, _profiler);
|
||||
viewEngines.Add(wrappedEngine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user