Skip to content

Commit 4a53635

Browse files
committed
Fixed nullability warnings
1 parent 11784bb commit 4a53635

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

src/Framework/Framework/Compilation/DotHtmlFileInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class DotHtmlFileInfo
1414
public ImmutableArray<CompilationDiagnosticViewModel> Warnings { get; internal set; } = ImmutableArray<CompilationDiagnosticViewModel>.Empty;
1515

1616
/// <summary>Gets or sets the virtual path to the view.</summary>
17-
public string VirtualPath { get; }
17+
public string? VirtualPath { get; }
1818

1919
public string? TagName { get; }
2020
public string? Namespace { get; }
@@ -25,7 +25,7 @@ public sealed class DotHtmlFileInfo
2525
public ImmutableArray<string>? DefaultValues { get; }
2626
public bool? HasParameters { get; }
2727

28-
public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray<string>? defaultValues = null, bool? hasParameters = null)
28+
public DotHtmlFileInfo(string? virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray<string>? defaultValues = null, bool? hasParameters = null)
2929
{
3030
VirtualPath = virtualPath;
3131
Status = IsDothtmlFile(virtualPath) ? CompilationState.None : CompilationState.NonCompilable;
@@ -40,7 +40,7 @@ public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameS
4040
HasParameters = hasParameters;
4141
}
4242

43-
private static bool IsDothtmlFile(string virtualPath)
43+
private static bool IsDothtmlFile(string? virtualPath)
4444
{
4545
return !string.IsNullOrWhiteSpace(virtualPath) &&
4646
(

src/Framework/Framework/Compilation/DotvvmViewCompilationService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async Task<bool> CompileAll(bool buildInParallel = true, bool forceRecomp
122122
var compilationTaskFactory = (DotHtmlFileInfo t) => () => {
123123
BuildView(t, forceRecompile, out var masterPage);
124124
if (masterPage != null && masterPage.Status == CompilationState.None)
125-
discoveredMasterPages.TryAdd(masterPage.VirtualPath, masterPage);
125+
discoveredMasterPages.TryAdd(masterPage.VirtualPath!, masterPage);
126126
};
127127

128128
var compileTasks = filesToCompile.Select(compilationTaskFactory).ToArray();
@@ -185,9 +185,9 @@ public bool BuildView(DotHtmlFileInfo file, bool forceRecompile, out DotHtmlFile
185185
{
186186
if (forceRecompile)
187187
// TODO: next major version - add method to interface
188-
(controlBuilderFactory as DefaultControlBuilderFactory)?.InvalidateCache(file.VirtualPath);
188+
(controlBuilderFactory as DefaultControlBuilderFactory)?.InvalidateCache(file.VirtualPath!);
189189

190-
var pageBuilder = controlBuilderFactory.GetControlBuilder(file.VirtualPath);
190+
var pageBuilder = controlBuilderFactory.GetControlBuilder(file.VirtualPath!);
191191

192192
using var scopedServices = dotvvmConfiguration.ServiceProvider.CreateScope(); // dependencies that are configured as scoped cannot be resolved from root service provider
193193
scopedServices.ServiceProvider.GetRequiredService<DotvvmRequestContextStorage>().Context = new ViewCompilationFakeRequestContext(scopedServices.ServiceProvider);

src/Framework/Framework/Compilation/Static/StaticViewCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using DotVVM.Framework.Configuration;
1111
using DotVVM.Framework.Hosting;
1212
using DotVVM.Framework.Security;
13+
using DotVVM.Framework.Utils;
1314
using Microsoft.CodeAnalysis;
1415
using Microsoft.Extensions.DependencyInjection;
1516
using Microsoft.Extensions.DependencyInjection.Extensions;
@@ -33,7 +34,7 @@ public static ImmutableArray<DotvvmCompilationDiagnostic> CompileAll(
3334
diagnostics.AddRange(CompileNoThrow(configuration, markupControl!));
3435
}
3536

36-
var views = configuration.RouteTable.Select(r => r.VirtualPath).ToImmutableArray();
37+
var views = configuration.RouteTable.Select(r => r.VirtualPath).WhereNotNull().ToImmutableArray();
3738
foreach(var view in views)
3839
{
3940
diagnostics.AddRange(CompileNoThrow(configuration, view));

src/Framework/Framework/Hosting/AggregateMarkupFileLoader.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using DotVVM.Framework.Configuration;
6+
using DotVVM.Framework.Utils;
67

78
namespace DotVVM.Framework.Hosting
89
{
@@ -39,7 +40,8 @@ public AggregateMarkupFileLoader()
3940
/// </summary>
4041
public string GetMarkupFileVirtualPath(IDotvvmRequestContext context)
4142
{
42-
return context.Route!.VirtualPath;
43+
return context.Route!.VirtualPath
44+
?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path.");
4345
}
4446
}
4547
}

src/Framework/Framework/Hosting/DefaultMarkupFileLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class DefaultMarkupFileLoader : IMarkupFileLoader
3838
/// </summary>
3939
public string GetMarkupFileVirtualPath(IDotvvmRequestContext context)
4040
{
41-
return context.Route!.VirtualPath;
41+
return context.Route!.VirtualPath
42+
?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path.");
4243
}
4344
}
4445
}

src/Framework/Framework/Hosting/EmbeddedMarkupFileLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public class EmbeddedMarkupFileLoader : IMarkupFileLoader
5858
/// </summary>
5959
public string GetMarkupFileVirtualPath(IDotvvmRequestContext context)
6060
{
61-
return context.Route!.VirtualPath;
61+
return context.Route!.VirtualPath
62+
?? throw new Exception($"The route {context.Route.RouteName} must have a non-null virtual path.");
6263
}
6364
}
6465
}

src/Framework/Framework/Routing/RouteHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void AssertConfigurationIsValid(this DotvvmConfiguration config)
5252
invalidRoutes.Add(new DotvvmConfigurationAssertResult<RouteBase>(route, DotvvmConfigurationAssertReason.MissingRouteName));
5353
}
5454

55-
var content = loader.GetMarkup(config, route.VirtualPath);
55+
var content = loader.GetMarkup(config, route.VirtualPath!);
5656
if (content == null)
5757
{
5858
invalidRoutes.Add(new DotvvmConfigurationAssertResult<RouteBase>(route, DotvvmConfigurationAssertReason.MissingFile));

0 commit comments

Comments
 (0)