diff --git a/src/DotVVM.Core/Utils/TextUtils.cs b/src/DotVVM.Core/Utils/TextUtils.cs index ad461b8091..d905cba004 100644 --- a/src/DotVVM.Core/Utils/TextUtils.cs +++ b/src/DotVVM.Core/Utils/TextUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM; +using DotVVM; namespace DotVVM.Core.Utils { diff --git a/src/DotVVM.Framework.Hosting.AspNetCore/Hosting/Middlewares/DotvvmMiddleware.cs b/src/DotVVM.Framework.Hosting.AspNetCore/Hosting/Middlewares/DotvvmMiddleware.cs index ac126219b9..c6b89e5a94 100644 --- a/src/DotVVM.Framework.Hosting.AspNetCore/Hosting/Middlewares/DotvvmMiddleware.cs +++ b/src/DotVVM.Framework.Hosting.AspNetCore/Hosting/Middlewares/DotvvmMiddleware.cs @@ -55,7 +55,9 @@ public async Task Invoke(HttpContext context) if (requestCultureFeature == null) { +#pragma warning disable CS0618 dotvvmContext.ChangeCurrentCulture(Configuration.DefaultCulture); +#pragma warning restore CS0618 } try diff --git a/src/DotVVM.Framework.Testing/BindingTestHelper.cs b/src/DotVVM.Framework.Testing/BindingTestHelper.cs index 0a0d659aef..553e949b2e 100644 --- a/src/DotVVM.Framework.Testing/BindingTestHelper.cs +++ b/src/DotVVM.Framework.Testing/BindingTestHelper.cs @@ -54,10 +54,11 @@ public DataContextStack CreateDataContext(Type[] contexts) public Expression ParseBinding(string expression, DataContextStack context, Type? expectedType = null, NamespaceImport[]? imports = null) { + expectedType ??= typeof(object); var parsedExpression = ExpressionBuilder.ParseWithLambdaConversion(expression, context, BindingParserOptions.Value.AddImports(imports), expectedType); return TypeConversion.MagicLambdaConversion(parsedExpression, expectedType) ?? - TypeConversion.ImplicitConversion(parsedExpression, expectedType, true, true); + TypeConversion.ImplicitConversion(parsedExpression, expectedType, true, true)!; } public ParametrizedCode ValueBindingToParametrizedCode(string expression, Type[] contexts, Type? expectedType = null, NamespaceImport[]? imports = null, bool nullChecks = false, bool niceMode = true) => diff --git a/src/DotVVM.Framework.Testing/ControlTestHelper.cs b/src/DotVVM.Framework.Testing/ControlTestHelper.cs index 38595d5827..0e62a40494 100644 --- a/src/DotVVM.Framework.Testing/ControlTestHelper.cs +++ b/src/DotVVM.Framework.Testing/ControlTestHelper.cs @@ -171,8 +171,8 @@ private PageRunResult CreatePageResult(TestDotvvmRequestContext context) { // order attributes by name var attrs = el.Attributes.OrderBy(a => a.Name).ToArray(); - foreach (var attr in attrs) el.RemoveAttribute(attr.NamespaceUri, attr.LocalName); - foreach (var attr in attrs) el.SetAttribute(attr.NamespaceUri, attr.LocalName, attr.Value); + foreach (var attr in attrs) el.RemoveAttribute(attr.NamespaceUri!, attr.LocalName); + foreach (var attr in attrs) el.SetAttribute(attr.NamespaceUri!, attr.LocalName, attr.Value); } return new PageRunResult( this, diff --git a/src/DotVVM.Framework.Testing/FakeCommandBinding.cs b/src/DotVVM.Framework.Testing/FakeCommandBinding.cs index 4c98730a36..6bd0e3751a 100644 --- a/src/DotVVM.Framework.Testing/FakeCommandBinding.cs +++ b/src/DotVVM.Framework.Testing/FakeCommandBinding.cs @@ -22,7 +22,7 @@ public FakeCommandBinding(ParametrizedCode commandJavascript, BindingDelegate bi public ImmutableArray ActionFilters => ImmutableArray.Empty; - public object GetProperty(Type type, ErrorHandlingMode errorMode = ErrorHandlingMode.ThrowException) + public object? GetProperty(Type type, ErrorHandlingMode errorMode = ErrorHandlingMode.ThrowException) { if (errorMode == ErrorHandlingMode.ReturnNull) return null; diff --git a/src/DotVVM.Framework.Tests/Binding/CustomExtensionMethodTests.cs b/src/DotVVM.Framework.Tests/Binding/CustomExtensionMethodTests.cs index 124be5c8da..6100942f86 100644 --- a/src/DotVVM.Framework.Tests/Binding/CustomExtensionMethodTests.cs +++ b/src/DotVVM.Framework.Tests/Binding/CustomExtensionMethodTests.cs @@ -33,11 +33,10 @@ private Expression CreateCall(MethodGroupExpression target, Expression[] args, N [TestMethod] public void Call_FindCustomExtensionMethod() { - var target = new MethodGroupExpression() - { - MethodName = nameof(TestExtensions.Increment), - Target = Expression.Constant(11) - }; + var target = new MethodGroupExpression( + Expression.Constant(11), + nameof(TestExtensions.Increment) + ); var expression = CreateCall(target, Array.Empty(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") }); var result = Expression.Lambda>(expression).Compile().Invoke(); @@ -48,20 +47,20 @@ public void Call_FindCustomExtensionMethod() [ExpectedException(typeof(InvalidOperationException))] public void Call_AmbiguousExtensionMethodsThrows() { - var nonAmbiguousTarget = new MethodGroupExpression() { - MethodName = nameof(AmbiguousExtensions.Extensions1.Decrement), - Target = Expression.Constant(11) - }; + var nonAmbiguousTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(AmbiguousExtensions.Extensions1.Decrement) + ); // Non-ambiguous var expression = CreateCall(nonAmbiguousTarget, Array.Empty(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding.AmbiguousExtensions") }); var result = Expression.Lambda>(expression).Compile().Invoke(); Assert.AreEqual(10, result); - var ambiguousTarget = new MethodGroupExpression() { - MethodName = nameof(AmbiguousExtensions.Extensions1.Increment), - Target = Expression.Constant(11) - }; + var ambiguousTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(AmbiguousExtensions.Extensions1.Increment) + ); // Ambiguous CreateCall(ambiguousTarget, Array.Empty(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding.AmbiguousExtensions") }); @@ -71,20 +70,20 @@ public void Call_AmbiguousExtensionMethodsThrows() [ExpectedException(typeof(InvalidOperationException))] public void Call_NotImportedExtensionMethodThrows() { - var importedTarget = new MethodGroupExpression() { - MethodName = nameof(AmbiguousExtensions.Extensions1.Decrement), - Target = Expression.Constant(11) - }; + var importedTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(AmbiguousExtensions.Extensions1.Decrement) + ); // Imported extension var expression = CreateCall(importedTarget, Array.Empty(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding.AmbiguousExtensions") }); var result = Expression.Lambda>(expression).Compile().Invoke(); Assert.AreEqual(10, result); - var notImportedTarget = new MethodGroupExpression() { - MethodName = nameof(AmbiguousExtensions.Extensions1.Decrement), - Target = Expression.Constant(11) - }; + var notImportedTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(AmbiguousExtensions.Extensions1.Decrement) + ); // Not imported extension CreateCall(notImportedTarget, Array.Empty(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") }); @@ -93,10 +92,10 @@ public void Call_NotImportedExtensionMethodThrows() [TestMethod] public void Call_ExtensionMethodsWithOptionalArguments_UseDefaultValue() { - var importedTarget = new MethodGroupExpression() { - MethodName = nameof(TestExtensions.ExtensionMethodWithOptionalArgument), - Target = Expression.Constant(11) - }; + var importedTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(TestExtensions.ExtensionMethodWithOptionalArgument) + ); // Imported extension var expression = CreateCall(importedTarget, Array.Empty(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding"), new NamespaceImport("DotVVM.Framework.Tests.Binding") }); @@ -107,10 +106,10 @@ public void Call_ExtensionMethodsWithOptionalArguments_UseDefaultValue() [TestMethod] public void Call_ExtensionMethodsWithOptionalArguments_OverrideDefaultValue() { - var importedTarget = new MethodGroupExpression() { - MethodName = nameof(TestExtensions.ExtensionMethodWithOptionalArgument), - Target = Expression.Constant(11) - }; + var importedTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(TestExtensions.ExtensionMethodWithOptionalArgument) + ); // Imported extension var expression = CreateCall(importedTarget, new[] { Expression.Constant(123) }, new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") }); @@ -121,10 +120,10 @@ public void Call_ExtensionMethodsWithOptionalArguments_OverrideDefaultValue() [TestMethod] public void Call_ExtensionMethods_DuplicitImport_DoesNotThrow() { - var importedTarget = new MethodGroupExpression() { - MethodName = nameof(TestExtensions.Increment), - Target = Expression.Constant(11) - }; + var importedTarget = new MethodGroupExpression( + Expression.Constant(11), + nameof(TestExtensions.Increment) + ); // Imported extension var expression = CreateCall(importedTarget, Array.Empty(), diff --git a/src/DotVVM.Framework.Tests/Binding/ExpressionHelperTests.cs b/src/DotVVM.Framework.Tests/Binding/ExpressionHelperTests.cs index 0d7b19307f..472e813020 100644 --- a/src/DotVVM.Framework.Tests/Binding/ExpressionHelperTests.cs +++ b/src/DotVVM.Framework.Tests/Binding/ExpressionHelperTests.cs @@ -71,10 +71,10 @@ public void Call_FindOverload_Generic_FirstLevel(Type resultIdentifierType, Type private void Call_FindOverload_Generic(Type targetType, string methodName, Type[] argTypes, Type resultIdentifierType, Type[] expectedGenericArgs) { - Expression target = new MethodGroupExpression() { - MethodName = methodName, - Target = new StaticClassIdentifierExpression(targetType) - }; + Expression target = new MethodGroupExpression( + new StaticClassIdentifierExpression(targetType), + methodName + ); var j = 0; var arguments = argTypes.Select(s => Expression.Parameter(s, $"param_{j++}")).ToArray(); @@ -169,10 +169,10 @@ public void Call_FindOverload_Generic_Array_Recursive(Type resultIdentifierType, [DataRow(typeof(GenericTestResult2), new Type[] { typeof(string), typeof(int), typeof(string), typeof(int) }, new Type[] { typeof(string), typeof(object[]) })] public void Call_FindOverload_Params_Array(Type resultIdentifierType, Type[] argTypes, Type[] expectedArgsTypes) { - Expression target = new MethodGroupExpression() { - MethodName = MethodsParamsArgumentsResolvingSampleObject.MethodName, - Target = new StaticClassIdentifierExpression(typeof(MethodsParamsArgumentsResolvingSampleObject)) - }; + Expression target = new MethodGroupExpression( + new StaticClassIdentifierExpression(typeof(MethodsParamsArgumentsResolvingSampleObject)), + MethodsParamsArgumentsResolvingSampleObject.MethodName + ); var j = 0; var arguments = argTypes.Select(s => Expression.Parameter(s, $"param_{j++}")).ToArray(); @@ -195,10 +195,10 @@ public void Call_FindOverload_Params_Array(Type resultIdentifierType, Type[] arg [DataRow(typeof(GenericTestResult4), new Type[] { typeof(float), /* default argument, params empty */ }, new Type[] { typeof(float), typeof(double), typeof(int[]) })] public void Call_FindOverload_Params_Empty(Type resultIdentifierType, Type[] argTypes, Type[] expectedArgsTypes) { - Expression target = new MethodGroupExpression() { - MethodName = MethodsParamsArgumentsResolvingSampleObject.MethodName, - Target = new StaticClassIdentifierExpression(typeof(MethodsParamsArgumentsResolvingSampleObject)) - }; + Expression target = new MethodGroupExpression( + new StaticClassIdentifierExpression(typeof(MethodsParamsArgumentsResolvingSampleObject)), + MethodsParamsArgumentsResolvingSampleObject.MethodName + ); var j = 0; var arguments = argTypes.Select(s => Expression.Parameter(s, $"param_{j++}")).ToArray(); @@ -219,10 +219,10 @@ public void Call_FindOverload_Params_Empty(Type resultIdentifierType, Type[] arg [DataRow(typeof(GenericTestResult3), new Type[] { typeof(bool), typeof(int), typeof(string), typeof(int) }, new Type[] { typeof(bool), typeof(int[]) })] public void Call_FindOverload_Params_Array_Invalid(Type resultIdentifierType, Type[] argTypes, Type[] expectedArgsTypes) { - Expression target = new MethodGroupExpression() { - MethodName = MethodsParamsArgumentsResolvingSampleObject.MethodName, - Target = new StaticClassIdentifierExpression(typeof(MethodsParamsArgumentsResolvingSampleObject)) - }; + Expression target = new MethodGroupExpression( + new StaticClassIdentifierExpression(typeof(MethodsParamsArgumentsResolvingSampleObject)), + MethodsParamsArgumentsResolvingSampleObject.MethodName + ); var j = 0; var arguments = argTypes.Select(s => Expression.Parameter(s, $"param_{j++}")).ToArray(); @@ -245,10 +245,10 @@ public void Call_FindOverload_Params_Array_Invalid(Type resultIdentifierType, Ty [DataRow(new Type[] { typeof(string), typeof(int) }, typeof((string, int[])))] public void Call_FindOverload_DoNotPrioritizeParams(Type[] argTypes, Type resultType) { - Expression target = new MethodGroupExpression() { - MethodName = nameof(ParamsPrioritizationTest.Method), - Target = new StaticClassIdentifierExpression(typeof(ParamsPrioritizationTest)) - }; + Expression target = new MethodGroupExpression( + new StaticClassIdentifierExpression(typeof(ParamsPrioritizationTest)), + nameof(ParamsPrioritizationTest.Method) + ); var j = 0; var arguments = argTypes.Select(s => Expression.Parameter(s, $"param_{j++}")).ToArray(); diff --git a/src/DotVVM.Framework.Tests/DotVVM.Framework.Tests.csproj b/src/DotVVM.Framework.Tests/DotVVM.Framework.Tests.csproj index d71bb4e163..ad22d95f97 100644 --- a/src/DotVVM.Framework.Tests/DotVVM.Framework.Tests.csproj +++ b/src/DotVVM.Framework.Tests/DotVVM.Framework.Tests.csproj @@ -1,6 +1,8 @@ 10.0 + + $(NoWarn);CS1998 True diff --git a/src/DotVVM.Framework.Tests/Runtime/ConfigurationSerializationTests.cs b/src/DotVVM.Framework.Tests/Runtime/ConfigurationSerializationTests.cs index f2d7c7553f..c5d8a1fe69 100644 --- a/src/DotVVM.Framework.Tests/Runtime/ConfigurationSerializationTests.cs +++ b/src/DotVVM.Framework.Tests/Runtime/ConfigurationSerializationTests.cs @@ -157,7 +157,6 @@ public void AuxOptions() c.ApplicationPhysicalPath = "/opt/myApp"; c.ClientSideValidation = false; c.DefaultCulture = "cs-CZ"; - c.UseHistoryApiSpaNavigation = true; checkConfig(c); } diff --git a/src/DotVVM.Framework.Tests/ViewModel/SerializerTests.cs b/src/DotVVM.Framework.Tests/ViewModel/SerializerTests.cs index 068ad1a2cb..a31ea04a76 100644 --- a/src/DotVVM.Framework.Tests/ViewModel/SerializerTests.cs +++ b/src/DotVVM.Framework.Tests/ViewModel/SerializerTests.cs @@ -26,9 +26,7 @@ static ViewModelJsonConverter CreateConverter(bool isPostback, JObject encrypted config.ServiceProvider.GetRequiredService(), config.ServiceProvider, encryptedValues - ) { - UsedSerializationMaps = new HashSet() - }; + ); } static string Serialize(T viewModel, out JObject encryptedValues, bool isPostback = false) diff --git a/src/DotVVM.Framework/Binding/ActiveDotvvmProperty.cs b/src/DotVVM.Framework/Binding/ActiveDotvvmProperty.cs index 975e9ff50c..a86a441194 100644 --- a/src/DotVVM.Framework/Binding/ActiveDotvvmProperty.cs +++ b/src/DotVVM.Framework/Binding/ActiveDotvvmProperty.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Controls; +using DotVVM.Framework.Controls; using DotVVM.Framework.Runtime; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Binding/ActiveDotvvmPropertyGroup.cs b/src/DotVVM.Framework/Binding/ActiveDotvvmPropertyGroup.cs index d8f54ecefb..c246275804 100644 --- a/src/DotVVM.Framework/Binding/ActiveDotvvmPropertyGroup.cs +++ b/src/DotVVM.Framework/Binding/ActiveDotvvmPropertyGroup.cs @@ -10,7 +10,7 @@ namespace DotVVM.Framework.Binding { public abstract class ActiveDotvvmPropertyGroup : DotvvmPropertyGroup { - protected internal ActiveDotvvmPropertyGroup(PrefixArray prefixes, Type valueType, Type declaringType, FieldInfo descriptorField, ICustomAttributeProvider attributeProvider, string name, object defaultValue) : base(prefixes, valueType, declaringType, descriptorField, attributeProvider, name, defaultValue) + protected internal ActiveDotvvmPropertyGroup(PrefixArray prefixes, Type valueType, Type declaringType, FieldInfo descriptorField, ICustomAttributeProvider attributeProvider, string name, object? defaultValue) : base(prefixes, valueType, declaringType, descriptorField, attributeProvider, name, defaultValue) { } diff --git a/src/DotVVM.Framework/Binding/AttachedPropertyAttribute.cs b/src/DotVVM.Framework/Binding/AttachedPropertyAttribute.cs index 06728cfef6..65ee39234e 100644 --- a/src/DotVVM.Framework/Binding/AttachedPropertyAttribute.cs +++ b/src/DotVVM.Framework/Binding/AttachedPropertyAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/BindingCollectionInfo.cs b/src/DotVVM.Framework/Binding/BindingCollectionInfo.cs index c7d93b1588..ed38f55417 100644 --- a/src/DotVVM.Framework/Binding/BindingCollectionInfo.cs +++ b/src/DotVVM.Framework/Binding/BindingCollectionInfo.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; @@ -29,7 +28,7 @@ internal static void RegisterJavascriptTranslations(JavascriptTranslatableMethod IJavascriptMethodTranslator memberAccess(string name) => new GenericMethodCompiler( builder: a => a[0].CastTo().Properties.Single(p => p.Name == name).Expression.Clone(), - check: (_m, a, _a) => a.GetParameterAnnotation() is BindingParameterAnnotation ann && ann.ExtensionParameter is BindingCollectionInfoExtensionParameter + check: (_m, a, _a) => a?.GetParameterAnnotation() is BindingParameterAnnotation ann && ann.ExtensionParameter is BindingCollectionInfoExtensionParameter ); methods.AddPropertyGetterTranslator(typeof(BindingCollectionInfo), nameof(Index), memberAccess(nameof(Index))); methods.AddPropertyGetterTranslator(typeof(BindingCollectionInfo), nameof(IsFirst), memberAccess(nameof(IsFirst))); diff --git a/src/DotVVM.Framework/Binding/BindingCombinator.cs b/src/DotVVM.Framework/Binding/BindingCombinator.cs index 19c5958bf2..146d9afb0d 100644 --- a/src/DotVVM.Framework/Binding/BindingCombinator.cs +++ b/src/DotVVM.Framework/Binding/BindingCombinator.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Runtime.CompilerServices; using System; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/BindingCompilationOptionsAttribute.cs b/src/DotVVM.Framework/Binding/BindingCompilationOptionsAttribute.cs index 91f6b91f75..d04de43a34 100644 --- a/src/DotVVM.Framework/Binding/BindingCompilationOptionsAttribute.cs +++ b/src/DotVVM.Framework/Binding/BindingCompilationOptionsAttribute.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; diff --git a/src/DotVVM.Framework/Binding/BindingCompilationRequirementsAttribute.cs b/src/DotVVM.Framework/Binding/BindingCompilationRequirementsAttribute.cs index 89b6c5dfb7..fa8859f059 100644 --- a/src/DotVVM.Framework/Binding/BindingCompilationRequirementsAttribute.cs +++ b/src/DotVVM.Framework/Binding/BindingCompilationRequirementsAttribute.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Immutable; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/BindingCompilationService.cs b/src/DotVVM.Framework/Binding/BindingCompilationService.cs index ad98273e01..0f92fe4e1b 100644 --- a/src/DotVVM.Framework/Binding/BindingCompilationService.cs +++ b/src/DotVVM.Framework/Binding/BindingCompilationService.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Binding/BindingFactory.cs b/src/DotVVM.Framework/Binding/BindingFactory.cs index a17dc0f67f..c1d7473389 100644 --- a/src/DotVVM.Framework/Binding/BindingFactory.cs +++ b/src/DotVVM.Framework/Binding/BindingFactory.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Binding/BindingHelper.cs b/src/DotVVM.Framework/Binding/BindingHelper.cs index 736b7896fa..09f817157f 100644 --- a/src/DotVVM.Framework/Binding/BindingHelper.cs +++ b/src/DotVVM.Framework/Binding/BindingHelper.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Controls; using System; using System.Collections.Generic; @@ -235,7 +234,7 @@ public static ParametrizedCode GetParametrizedCommandJavascript(this ICommandBin JavascriptTranslator.AdjustKnockoutScriptContext(binding.CommandJavascript, dataContextLevel: FindDataContextTarget(binding, control).stepsUp); - public static object GetBindingValue(this IBinding binding, DotvvmBindableObject control) + public static object? GetBindingValue(this IBinding binding, DotvvmBindableObject control) { if (binding is IStaticValueBinding valueBinding) { @@ -251,7 +250,7 @@ public static object GetBindingValue(this IBinding binding, DotvvmBindableObject /// /// Creates new `TBinding` with the original DataContextStack, LocationInfo, AdditionalResolvers and BindingCompilationService. /// - public static TBinding DeriveBinding(this TBinding binding, DataContextStack newDataContext, Expression expression, params object[] properties) + public static TBinding DeriveBinding(this TBinding binding, DataContextStack newDataContext, Expression expression, params object?[] properties) where TBinding : IBinding { return binding.DeriveBinding( diff --git a/src/DotVVM.Framework/Binding/BindingPageInfo.cs b/src/DotVVM.Framework/Binding/BindingPageInfo.cs index 72d79510b4..f705bd4534 100644 --- a/src/DotVVM.Framework/Binding/BindingPageInfo.cs +++ b/src/DotVVM.Framework/Binding/BindingPageInfo.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/BindingProperties.cs b/src/DotVVM.Framework/Binding/BindingProperties.cs index c36b2d0d5f..4bf7a6a383 100644 --- a/src/DotVVM.Framework/Binding/BindingProperties.cs +++ b/src/DotVVM.Framework/Binding/BindingProperties.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using System.Linq; @@ -193,7 +192,7 @@ public sealed class LocationInfoBindingProperty public readonly Type? ControlType; public readonly DotvvmProperty? RelatedProperty; - public LocationInfoBindingProperty(string fileName, (int, int)[] ranges, int lineNumber, Type controlType, DotvvmProperty? relatedProperty = null) + public LocationInfoBindingProperty(string? fileName, (int, int)[]? ranges, int lineNumber, Type? controlType, DotvvmProperty? relatedProperty = null) { this.FileName = fileName; this.Ranges = ranges; diff --git a/src/DotVVM.Framework/Binding/BindingPropertyException.cs b/src/DotVVM.Framework/Binding/BindingPropertyException.cs index afc6bb33c4..22c77a2880 100644 --- a/src/DotVVM.Framework/Binding/BindingPropertyException.cs +++ b/src/DotVVM.Framework/Binding/BindingPropertyException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/CollectionElementDataContextChangeAttribute.cs b/src/DotVVM.Framework/Binding/CollectionElementDataContextChangeAttribute.cs index e2bd983458..3dadaa94bd 100644 --- a/src/DotVVM.Framework/Binding/CollectionElementDataContextChangeAttribute.cs +++ b/src/DotVVM.Framework/Binding/CollectionElementDataContextChangeAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/CombinedDataContextAttributeProvider.cs b/src/DotVVM.Framework/Binding/CombinedDataContextAttributeProvider.cs index e42bb87382..2ce3d19c48 100644 --- a/src/DotVVM.Framework/Binding/CombinedDataContextAttributeProvider.cs +++ b/src/DotVVM.Framework/Binding/CombinedDataContextAttributeProvider.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/CommonBindings.cs b/src/DotVVM.Framework/Binding/CommonBindings.cs index 71fc6e6c10..ae5e3c9fe4 100644 --- a/src/DotVVM.Framework/Binding/CommonBindings.cs +++ b/src/DotVVM.Framework/Binding/CommonBindings.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using DotVVM.Framework.Binding.Expressions; diff --git a/src/DotVVM.Framework/Binding/CompileTimeOnlyDotvvmProperty.cs b/src/DotVVM.Framework/Binding/CompileTimeOnlyDotvvmProperty.cs index f6dcc049c5..b4a6ee0914 100644 --- a/src/DotVVM.Framework/Binding/CompileTimeOnlyDotvvmProperty.cs +++ b/src/DotVVM.Framework/Binding/CompileTimeOnlyDotvvmProperty.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq.Expressions; using System.Reflection; using DotVVM.Framework.Controls; diff --git a/src/DotVVM.Framework/Binding/ConstantDataContextChangeAttribute.cs b/src/DotVVM.Framework/Binding/ConstantDataContextChangeAttribute.cs index 3d35ba8e53..63c4d4bebb 100644 --- a/src/DotVVM.Framework/Binding/ConstantDataContextChangeAttribute.cs +++ b/src/DotVVM.Framework/Binding/ConstantDataContextChangeAttribute.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Binding/ControlPropertyBindingDataContextChangeAttribute.cs b/src/DotVVM.Framework/Binding/ControlPropertyBindingDataContextChangeAttribute.cs index e98dfb49e7..6a2a97162a 100644 --- a/src/DotVVM.Framework/Binding/ControlPropertyBindingDataContextChangeAttribute.cs +++ b/src/DotVVM.Framework/Binding/ControlPropertyBindingDataContextChangeAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/ControlPropertyTypeDataContextChangeAttribute.cs b/src/DotVVM.Framework/Binding/ControlPropertyTypeDataContextChangeAttribute.cs index 4cf7fc47ee..050ee0294a 100644 --- a/src/DotVVM.Framework/Binding/ControlPropertyTypeDataContextChangeAttribute.cs +++ b/src/DotVVM.Framework/Binding/ControlPropertyTypeDataContextChangeAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/DataContextChangeAttribute.cs b/src/DotVVM.Framework/Binding/DataContextChangeAttribute.cs index ad7c03cdd1..582074f67b 100644 --- a/src/DotVVM.Framework/Binding/DataContextChangeAttribute.cs +++ b/src/DotVVM.Framework/Binding/DataContextChangeAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Controls; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Binding/DelegateActionProperty.cs b/src/DotVVM.Framework/Binding/DelegateActionProperty.cs index b99a4d62f8..e302523294 100644 --- a/src/DotVVM.Framework/Binding/DelegateActionProperty.cs +++ b/src/DotVVM.Framework/Binding/DelegateActionProperty.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Controls; +using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; using DotVVM.Framework.Runtime; using System; diff --git a/src/DotVVM.Framework/Binding/DelegateActionPropertyGroup.cs b/src/DotVVM.Framework/Binding/DelegateActionPropertyGroup.cs index e8429de90e..c84cca0e02 100644 --- a/src/DotVVM.Framework/Binding/DelegateActionPropertyGroup.cs +++ b/src/DotVVM.Framework/Binding/DelegateActionPropertyGroup.cs @@ -17,7 +17,7 @@ public DelegateActionPropertyGroup(PrefixArray prefixes, Type declaringType, FieldInfo descriptorField, string name, - object defaultValue, + object? defaultValue, Action> func) : base(prefixes, valueType, declaringType, descriptorField, descriptorField, name, defaultValue) { @@ -33,7 +33,7 @@ public static DelegateActionPropertyGroup Register( PrefixArray prefixes, string name, Action> func, - TValue defaultValue = default(TValue)) + TValue? defaultValue = default(TValue)) { var descriptorField = DotvvmPropertyGroup.FindDescriptorField(typeof(TDeclaringType), name); return (DelegateActionPropertyGroup)DotvvmPropertyGroup.Register( diff --git a/src/DotVVM.Framework/Binding/DotvvmBindingCacheHelper.cs b/src/DotVVM.Framework/Binding/DotvvmBindingCacheHelper.cs index c374297c52..253791ab12 100644 --- a/src/DotVVM.Framework/Binding/DotvvmBindingCacheHelper.cs +++ b/src/DotVVM.Framework/Binding/DotvvmBindingCacheHelper.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/DotvvmCapabilityProperty.cs b/src/DotVVM.Framework/Binding/DotvvmCapabilityProperty.cs index 915b4f4f15..3255234c1b 100644 --- a/src/DotVVM.Framework/Binding/DotvvmCapabilityProperty.cs +++ b/src/DotVVM.Framework/Binding/DotvvmCapabilityProperty.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Binding/DotvvmProperty.cs b/src/DotVVM.Framework/Binding/DotvvmProperty.cs index bca1b7112f..a3ccd4789e 100644 --- a/src/DotVVM.Framework/Binding/DotvvmProperty.cs +++ b/src/DotVVM.Framework/Binding/DotvvmProperty.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Binding/DotvvmPropertyWithFallback.cs b/src/DotVVM.Framework/Binding/DotvvmPropertyWithFallback.cs index e6f2cdb852..6392953a00 100644 --- a/src/DotVVM.Framework/Binding/DotvvmPropertyWithFallback.cs +++ b/src/DotVVM.Framework/Binding/DotvvmPropertyWithFallback.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq.Expressions; using System.Reflection; using DotVVM.Framework.Controls; diff --git a/src/DotVVM.Framework/Binding/Expressions/BindingDelegates.cs b/src/DotVVM.Framework/Binding/Expressions/BindingDelegates.cs index dcb8ef1857..d1de19accf 100644 --- a/src/DotVVM.Framework/Binding/Expressions/BindingDelegates.cs +++ b/src/DotVVM.Framework/Binding/Expressions/BindingDelegates.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq.Expressions; using DotVVM.Framework.Controls; using DotVVM.Framework.Runtime.Filters; diff --git a/src/DotVVM.Framework/Binding/Expressions/BindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/BindingExpression.cs index 4d328794c1..2514eacf40 100644 --- a/src/DotVVM.Framework/Binding/Expressions/BindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/BindingExpression.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Binding/Expressions/CommandBindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/CommandBindingExpression.cs index 0cac1e0a52..13e9af997b 100644 --- a/src/DotVVM.Framework/Binding/Expressions/CommandBindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/CommandBindingExpression.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Binding/Expressions/ControlCommandBindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/ControlCommandBindingExpression.cs index e8e4da634a..326b673df2 100644 --- a/src/DotVVM.Framework/Binding/Expressions/ControlCommandBindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/ControlCommandBindingExpression.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Compilation; diff --git a/src/DotVVM.Framework/Binding/Expressions/ControlPropertyBindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/ControlPropertyBindingExpression.cs index 9966a4213d..63fe5bcd8b 100644 --- a/src/DotVVM.Framework/Binding/Expressions/ControlPropertyBindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/ControlPropertyBindingExpression.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Compilation; diff --git a/src/DotVVM.Framework/Binding/Expressions/IBinding.cs b/src/DotVVM.Framework/Binding/Expressions/IBinding.cs index b21d879c9a..49405baf02 100644 --- a/src/DotVVM.Framework/Binding/Expressions/IBinding.cs +++ b/src/DotVVM.Framework/Binding/Expressions/IBinding.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; namespace DotVVM.Framework.Binding.Expressions diff --git a/src/DotVVM.Framework/Binding/Expressions/ICommandBinding.cs b/src/DotVVM.Framework/Binding/Expressions/ICommandBinding.cs index 309887871e..77cedd066e 100644 --- a/src/DotVVM.Framework/Binding/Expressions/ICommandBinding.cs +++ b/src/DotVVM.Framework/Binding/Expressions/ICommandBinding.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Immutable; +using System.Collections.Immutable; using DotVVM.Framework.Compilation.Javascript; using DotVVM.Framework.Runtime.Filters; diff --git a/src/DotVVM.Framework/Binding/Expressions/IStaticValueBinding.cs b/src/DotVVM.Framework/Binding/Expressions/IStaticValueBinding.cs index 6b8729d8fe..746dcaad43 100644 --- a/src/DotVVM.Framework/Binding/Expressions/IStaticValueBinding.cs +++ b/src/DotVVM.Framework/Binding/Expressions/IStaticValueBinding.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using DotVVM.Framework.Controls; namespace DotVVM.Framework.Binding.Expressions diff --git a/src/DotVVM.Framework/Binding/Expressions/IUpdatableValueBinding.cs b/src/DotVVM.Framework/Binding/Expressions/IUpdatableValueBinding.cs index 3bd8cafb4a..5c51b5f97b 100644 --- a/src/DotVVM.Framework/Binding/Expressions/IUpdatableValueBinding.cs +++ b/src/DotVVM.Framework/Binding/Expressions/IUpdatableValueBinding.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Controls; namespace DotVVM.Framework.Binding.Expressions diff --git a/src/DotVVM.Framework/Binding/Expressions/IValueBinding.cs b/src/DotVVM.Framework/Binding/Expressions/IValueBinding.cs index add7f2a016..904569b7b2 100644 --- a/src/DotVVM.Framework/Binding/Expressions/IValueBinding.cs +++ b/src/DotVVM.Framework/Binding/Expressions/IValueBinding.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Compilation.Javascript; +using DotVVM.Framework.Compilation.Javascript; namespace DotVVM.Framework.Binding.Expressions { diff --git a/src/DotVVM.Framework/Binding/Expressions/ResourceBindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/ResourceBindingExpression.cs index d910e93891..5869df6721 100644 --- a/src/DotVVM.Framework/Binding/Expressions/ResourceBindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/ResourceBindingExpression.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Binding/Expressions/StaticCommandBindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/StaticCommandBindingExpression.cs index 9e00c373fa..530cfa68e3 100644 --- a/src/DotVVM.Framework/Binding/Expressions/StaticCommandBindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/StaticCommandBindingExpression.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -30,7 +29,7 @@ public class OptionsAttribute : BindingCompilationOptionsAttribute { public override IEnumerable GetResolvers() => new Delegate[] { new Func(js => { - var resources = js.Expression.DescendantNodesAndSelf().Select(n => n.Annotation()).Where(n => n != null).SelectMany(n => n.Resources).ToImmutableArray(); + var resources = js.Expression.DescendantNodesAndSelf().Select(n => n.Annotation()).Where(n => n != null).SelectMany(n => n!.Resources).ToImmutableArray(); return resources.Length == 0 ? RequiredRuntimeResourcesBindingProperty.Empty : new RequiredRuntimeResourcesBindingProperty(resources); }) }; diff --git a/src/DotVVM.Framework/Binding/Expressions/ValueBindingExpression.cs b/src/DotVVM.Framework/Binding/Expressions/ValueBindingExpression.cs index 993dae0454..0ebec9d9dc 100644 --- a/src/DotVVM.Framework/Binding/Expressions/ValueBindingExpression.cs +++ b/src/DotVVM.Framework/Binding/Expressions/ValueBindingExpression.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -55,7 +54,7 @@ public class OptionsAttribute : BindingCompilationOptionsAttribute .DescendantNodesAndSelf() .Select(n => n.Annotation()) .Where(n => n != null) - .SelectMany(n => n.Resources) + .SelectMany(n => n!.Resources) .ToImmutableArray(); return resources.Length == 0 diff --git a/src/DotVVM.Framework/Binding/ExtensionCommands.cs b/src/DotVVM.Framework/Binding/ExtensionCommands.cs index a9ef4fa6a8..8644cf7724 100644 --- a/src/DotVVM.Framework/Binding/ExtensionCommands.cs +++ b/src/DotVVM.Framework/Binding/ExtensionCommands.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using DotVVM.Framework.Binding.Expressions; diff --git a/src/DotVVM.Framework/Binding/GenericTypeDataContextChangeAttribute.cs b/src/DotVVM.Framework/Binding/GenericTypeDataContextChangeAttribute.cs index 02b4d47ab5..939be40868 100644 --- a/src/DotVVM.Framework/Binding/GenericTypeDataContextChangeAttribute.cs +++ b/src/DotVVM.Framework/Binding/GenericTypeDataContextChangeAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/GroupedDotvvmProperty.cs b/src/DotVVM.Framework/Binding/GroupedDotvvmProperty.cs index 182bd057d7..ce3b050129 100644 --- a/src/DotVVM.Framework/Binding/GroupedDotvvmProperty.cs +++ b/src/DotVVM.Framework/Binding/GroupedDotvvmProperty.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Compilation.ControlTree; +using DotVVM.Framework.Compilation.ControlTree; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/HelperNamespace/BindingApi.cs b/src/DotVVM.Framework/Binding/HelperNamespace/BindingApi.cs index ef06a7c816..08c8ce224d 100644 --- a/src/DotVVM.Framework/Binding/HelperNamespace/BindingApi.cs +++ b/src/DotVVM.Framework/Binding/HelperNamespace/BindingApi.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/HelperNamespace/Enums.cs b/src/DotVVM.Framework/Binding/HelperNamespace/Enums.cs index d01b08f5d4..0a89be26e0 100644 --- a/src/DotVVM.Framework/Binding/HelperNamespace/Enums.cs +++ b/src/DotVVM.Framework/Binding/HelperNamespace/Enums.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; namespace DotVVM.Framework.Binding.HelperNamespace diff --git a/src/DotVVM.Framework/Binding/HelperNamespace/JsBindingApi.cs b/src/DotVVM.Framework/Binding/HelperNamespace/JsBindingApi.cs index ef0c4fe37e..fe0c6f53ab 100644 --- a/src/DotVVM.Framework/Binding/HelperNamespace/JsBindingApi.cs +++ b/src/DotVVM.Framework/Binding/HelperNamespace/JsBindingApi.cs @@ -19,7 +19,7 @@ internal static void RegisterJavascriptTranslations(JavascriptTranslatableMethod { collection.AddMethodTranslator(typeof(JsBindingApi), nameof(Invoke), new GenericMethodCompiler( (a, method) => { - var annotation = a[0].Annotation(); + var annotation = a[0].Annotation().NotNull("invalid call of _js.Invoke"); var viewIdOrElementExpr = annotation.IsMarkupControl ? new JsSymbolicParameter(CommandBindingExpression.SenderElementParameter) : (JsExpression)new JsLiteral(annotation.Id); var jsExpression = a[0].Member("call").Invoke(viewIdOrElementExpr, a[1], a[2]); diff --git a/src/DotVVM.Framework/Binding/IExpressionToDelegateCompiler.cs b/src/DotVVM.Framework/Binding/IExpressionToDelegateCompiler.cs index 82f005f813..a1b028cbd4 100644 --- a/src/DotVVM.Framework/Binding/IExpressionToDelegateCompiler.cs +++ b/src/DotVVM.Framework/Binding/IExpressionToDelegateCompiler.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Text; diff --git a/src/DotVVM.Framework/Binding/PropertyGroupAttribute.cs b/src/DotVVM.Framework/Binding/PropertyGroupAttribute.cs index badbc53d08..be07e70188 100644 --- a/src/DotVVM.Framework/Binding/PropertyGroupAttribute.cs +++ b/src/DotVVM.Framework/Binding/PropertyGroupAttribute.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Binding/ValueOrBinding.cs b/src/DotVVM.Framework/Binding/ValueOrBinding.cs index 81bae347e8..6b331df7b0 100644 --- a/src/DotVVM.Framework/Binding/ValueOrBinding.cs +++ b/src/DotVVM.Framework/Binding/ValueOrBinding.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -58,9 +57,9 @@ public static ValueOrBinding FromBoxedValue(object? value) => value is ValueOrBinding vob ? new ValueOrBinding(vob.BindingOrDefault, (T)vob.BoxedValue!) : new ValueOrBinding((T)value!); - + [return: MaybeNull] public T Evaluate(DotvvmBindableObject control) => - binding != null ? (T)binding.GetBindingValue(control) : value; + binding is object ? (T)binding.GetBindingValue(control)! : value; public T ValueOrDefault => value; public IBinding? BindingOrDefault => binding; @@ -122,7 +121,7 @@ public void ProcessValueBinding(DotvvmBindableObject control, Action processV else if (binding is IValueBinding valueBinding) processBinding?.Invoke(valueBinding); else - processValue?.Invoke(this.Evaluate(control)); + processValue?.Invoke(this.Evaluate(control)!); } public TResult ProcessValueBinding(DotvvmBindableObject control, Func processValue, Func processBinding) @@ -132,7 +131,7 @@ public TResult ProcessValueBinding(DotvvmBindableObject control, Func(T val) => new ValueOrBinding(val); @@ -145,10 +144,12 @@ public TResult ProcessValueBinding(DotvvmBindableObject control, Func a, ValueOrBinding b) => throw new NotSupportedException(EqualsDisabledReason); +#pragma warning disable CS0809 [Obsolete(EqualsDisabledReason, error: true)] public override bool Equals(object? obj) => throw new NotSupportedException(EqualsDisabledReason); [Obsolete(EqualsDisabledReason, error: true)] public override int GetHashCode() => throw new NotSupportedException(EqualsDisabledReason); +#pragma warning restore CS0809 } } diff --git a/src/DotVVM.Framework/Binding/ValueOrBindingExtensions.cs b/src/DotVVM.Framework/Binding/ValueOrBindingExtensions.cs index 931f2b76f5..1cde6826cf 100644 --- a/src/DotVVM.Framework/Binding/ValueOrBindingExtensions.cs +++ b/src/DotVVM.Framework/Binding/ValueOrBindingExtensions.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/src/DotVVM.Framework/Binding/ViewModuleReferenceInfo.cs b/src/DotVVM.Framework/Binding/ViewModuleReferenceInfo.cs index 149f26707e..a8c8dccad0 100644 --- a/src/DotVVM.Framework/Binding/ViewModuleReferenceInfo.cs +++ b/src/DotVVM.Framework/Binding/ViewModuleReferenceInfo.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Binding/VirtualPropertyGroupDictionary.cs b/src/DotVVM.Framework/Binding/VirtualPropertyGroupDictionary.cs index 8c24e0bf06..dda3a4040d 100644 --- a/src/DotVVM.Framework/Binding/VirtualPropertyGroupDictionary.cs +++ b/src/DotVVM.Framework/Binding/VirtualPropertyGroupDictionary.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Compilation.ControlTree; +using DotVVM.Framework.Compilation.ControlTree; using DotVVM.Framework.Controls; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/Binding/BindingCompilationException.cs b/src/DotVVM.Framework/Compilation/Binding/BindingCompilationException.cs index 2d0f50a49c..d960e25992 100644 --- a/src/DotVVM.Framework/Compilation/Binding/BindingCompilationException.cs +++ b/src/DotVVM.Framework/Compilation/Binding/BindingCompilationException.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using DotVVM.Framework.Compilation.Parser; using DotVVM.Framework.Compilation.Parser.Binding.Parser; diff --git a/src/DotVVM.Framework/Compilation/Binding/BindingExpressionBuilder.cs b/src/DotVVM.Framework/Compilation/Binding/BindingExpressionBuilder.cs index 003702ed6d..7cf450c3d5 100644 --- a/src/DotVVM.Framework/Compilation/Binding/BindingExpressionBuilder.cs +++ b/src/DotVVM.Framework/Compilation/Binding/BindingExpressionBuilder.cs @@ -18,7 +18,7 @@ public class BindingExpressionBuilder : IBindingExpressionBuilder { private readonly CompiledAssemblyCache compiledAssemblyCache; private readonly ExtensionMethodsCache extensionMethodsCache; - private MemberExpressionFactory memberExpressionFactory; + private MemberExpressionFactory? memberExpressionFactory; public BindingExpressionBuilder(CompiledAssemblyCache compiledAssemblyCache, ExtensionMethodsCache extensionMethodsCache) { @@ -26,7 +26,7 @@ public BindingExpressionBuilder(CompiledAssemblyCache compiledAssemblyCache, Ext this.extensionMethodsCache = extensionMethodsCache; } - public Expression Parse(string expression, DataContextStack dataContexts, BindingParserOptions options, Type expectedType = null, params KeyValuePair[] additionalSymbols) + public Expression Parse(string expression, DataContextStack dataContexts, BindingParserOptions options, Type? expectedType = null, params KeyValuePair[] additionalSymbols) { try { @@ -40,9 +40,10 @@ public Expression Parse(string expression, DataContextStack dataContexts, Bindin var node = parser.ReadExpression(); if (!parser.OnEnd()) { + var bindingToken = parser.Peek().NotNull(); throw new BindingCompilationException( - $"Unexpected token '{expression.Substring(0, parser.Peek().StartPosition)} ---->{parser.Peek().Text}<---- {expression.Substring(parser.Peek().EndPosition)}'", - null, new TokenBase[] { parser.Peek() }); + $"Unexpected token '{expression.Substring(0, bindingToken.StartPosition)} ---->{bindingToken.Text}<---- {expression.Substring(bindingToken.EndPosition)}'", + null, new TokenBase[] { bindingToken }); } foreach (var n in node.EnumerateNodes()) { @@ -86,7 +87,7 @@ public TypeRegistry AddTypeSymbols(TypeRegistry reg, DataContextStack dataContex .AddSymbols(dataContext.Enumerable() .Select((t, i) => new KeyValuePair($"Parent{i}ViewModel", TypeRegistry.CreateStatic(t)))) // import all viewModel namespaces - .AddSymbols(namespaces.Select(ns => (Func)(typeName => TypeRegistry.CreateStatic(compiledAssemblyCache.FindType(ns + "." + typeName))))); + .AddSymbols(namespaces.Select(ns => (Func)(typeName => TypeRegistry.CreateStatic(compiledAssemblyCache.FindType(ns + "." + typeName))))); } public static IEnumerable GetParameters(DataContextStack dataContext) @@ -111,12 +112,12 @@ public static IEnumerable GetParameters(DataContextStack da { yield return CreateParameter(dataContext, "_root"); } - dataContext = dataContext.Parent; + dataContext = dataContext.Parent!; index++; } } - static ParameterExpression CreateParameter(DataContextStack stackItem, string name, BindingExtensionParameter extensionParameter = null) => + static ParameterExpression CreateParameter(DataContextStack stackItem, string name, BindingExtensionParameter? extensionParameter = null) => Expression.Parameter( (extensionParameter == null ? stackItem.DataContextType diff --git a/src/DotVVM.Framework/Compilation/Binding/ExpressionBuildingVisitor.cs b/src/DotVVM.Framework/Compilation/Binding/ExpressionBuildingVisitor.cs index 06cfdd9d82..173998d95b 100644 --- a/src/DotVVM.Framework/Compilation/Binding/ExpressionBuildingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Binding/ExpressionBuildingVisitor.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; using DotVVM.Framework.Compilation.Parser.Binding.Parser; @@ -44,7 +43,7 @@ public ExpressionBuildingVisitor(TypeRegistry registry, MemberExpressionFactory protected T HandleErrors(TNode node, Func action, string defaultErrorMessage = "Binding compilation failed", bool allowResultNull = true) where TNode : BindingParserNode { - T result = default(T); + T result = default!; try { result = action(node); @@ -115,15 +114,15 @@ protected override Expression VisitLiteralExpression(LiteralExpressionBindingPar protected override Expression VisitInterpolatedStringExpression(InterpolatedStringBindingParserNode node) { - var target = new MethodGroupExpression() { - MethodName = nameof(String.Format), - Target = new StaticClassIdentifierExpression(typeof(string)) - }; + var target = new MethodGroupExpression( + new StaticClassIdentifierExpression(typeof(string)), + nameof(String.Format) + ); if (node.Arguments.Any()) { // Translate to a String.Format(...) call - var arguments = node.Arguments.Select((arg, index) => HandleErrors(node.Arguments[index], Visit)).ToArray(); + var arguments = node.Arguments.Select((arg, index) => HandleErrors(node.Arguments[index], Visit)!).ToArray(); return memberExpressionFactory.Call(target, new[] { Expression.Constant(node.Format) }.Concat(arguments).ToArray()); } else @@ -243,7 +242,7 @@ protected override Expression VisitBinaryOperator(BinaryOperatorBindingParserNod } } - return memberExpressionFactory.GetBinaryOperator(left, right, eop); + return memberExpressionFactory.GetBinaryOperator(left!, right!, eop); } protected override Expression VisitArrayAccess(ArrayAccessBindingParserNode node) @@ -252,7 +251,7 @@ protected override Expression VisitArrayAccess(ArrayAccessBindingParserNode node var index = HandleErrors(node.ArrayIndexExpression, Visit); ThrowOnErrors(); - var expression = ExpressionHelper.GetIndexer(target, index); + var expression = ExpressionHelper.GetIndexer(target!, index!); if (expression is IndexExpression indexExpression && !node.Annotations.Contains(WriteAccessAnnotation.Instance)) { // Convert to get_{Indexer}(index, value) call @@ -544,12 +543,12 @@ protected override Expression VisitBlock(BlockBindingParserNode node) protected override Expression VisitFormattedExpression(FormattedBindingParserNode node) { - var target = new MethodGroupExpression() { - MethodName = nameof(String.Format), - Target = new StaticClassIdentifierExpression(typeof(string)) - }; + var target = new MethodGroupExpression( + new StaticClassIdentifierExpression(typeof(string)), + nameof(String.Format) + ); - var nodeObj = HandleErrors(node.Node, Visit); + var nodeObj = Visit(node.Node); return memberExpressionFactory.Call(target, new[] { Expression.Constant(node.Format), nodeObj }); } diff --git a/src/DotVVM.Framework/Compilation/Binding/ExpressionHelper.cs b/src/DotVVM.Framework/Compilation/Binding/ExpressionHelper.cs index f8f7684368..d7b9f4737d 100644 --- a/src/DotVVM.Framework/Compilation/Binding/ExpressionHelper.cs +++ b/src/DotVVM.Framework/Compilation/Binding/ExpressionHelper.cs @@ -81,7 +81,7 @@ public static IEnumerable GetBinderArguments(int count) return arr; } - public static Expression ApplyBinder(DynamicMetaObjectBinder binder, bool throwException, params Expression[] expressions) + public static Expression? ApplyBinder(DynamicMetaObjectBinder binder, bool throwException, params Expression[] expressions) { var result = binder.Bind(DynamicMetaObject.Create(null, expressions[0]), expressions.Skip(1).Select(e => diff --git a/src/DotVVM.Framework/Compilation/Binding/ExpressionNullPropagationVisitor.cs b/src/DotVVM.Framework/Compilation/Binding/ExpressionNullPropagationVisitor.cs index 054e64cf17..5e34abe9d5 100644 --- a/src/DotVVM.Framework/Compilation/Binding/ExpressionNullPropagationVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Binding/ExpressionNullPropagationVisitor.cs @@ -170,10 +170,10 @@ protected Expression UnwrapNullableType(Expression expression, Type expectedType protected Expression CheckForNull(Expression parameter, Func callback, bool checkReferenceTypes = true, bool suppress = false) { if (suppress || parameter == null || (parameter.Type.IsValueType && !parameter.Type.IsNullable()) || !checkReferenceTypes && !parameter.Type.IsValueType) - return callback(parameter); + return callback(parameter!); var p2 = Expression.Parameter(parameter.Type, "tmp" + tmpCounter++); var eresult = callback(p2.Type.IsNullable() ? (Expression)Expression.Property(p2, "Value") : p2); - eresult = TypeConversion.ImplicitConversion(eresult, eresult.Type.MakeNullableType()); + eresult = TypeConversion.ImplicitConversion(eresult, eresult.Type.MakeNullableType())!; return Expression.Block( new[] { p2 }, Expression.Assign(p2, parameter), diff --git a/src/DotVVM.Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs b/src/DotVVM.Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs index 29a323eb77..3fc958fdda 100644 --- a/src/DotVVM.Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs +++ b/src/DotVVM.Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs @@ -57,7 +57,7 @@ public Expression CompileToDelegate( return Expression.Lambda(expr, BindingCompiler.ViewModelsParameter, BindingCompiler.CurrentControlParameter); } - public CastedExpressionBindingProperty ConvertExpressionToType(ParsedExpressionBindingProperty expr, ExpectedTypeBindingProperty expectedType = null) + public CastedExpressionBindingProperty ConvertExpressionToType(ParsedExpressionBindingProperty expr, ExpectedTypeBindingProperty? expectedType = null) { var destType = expectedType?.Type ?? typeof(object); var convertedExpr = TypeConversion.ImplicitConversion(expr.Expression, destType, throwException: false, allowToString: true); @@ -65,11 +65,11 @@ public CastedExpressionBindingProperty ConvertExpressionToType(ParsedExpressionB // if the expression is of type object (i.e. null literal) try the lambda conversion. convertedExpr != null && expr.Expression.Type != typeof(object) ? convertedExpr : TypeConversion.MagicLambdaConversion(expr.Expression, destType) ?? - TypeConversion.ImplicitConversion(expr.Expression, destType, throwException: true, allowToString: true) + TypeConversion.ImplicitConversion(expr.Expression, destType, throwException: true, allowToString: true)! ); } - public Expression CompileToUpdateDelegate(ParsedExpressionBindingProperty binding, DataContextStack dataContext) + public Expression? CompileToUpdateDelegate(ParsedExpressionBindingProperty binding, DataContextStack dataContext) { var valueParameter = Expression.Parameter(typeof(object), "value"); var body = BindingCompiler.ReplaceParameters(binding.Expression, dataContext); @@ -91,7 +91,7 @@ public BindingParserOptions GetDefaultBindingParserOptions(IBinding binding) return new BindingParserOptions(binding.GetType()); } - public ParsedExpressionBindingProperty GetExpression(OriginalStringBindingProperty originalString, DataContextStack dataContext, BindingParserOptions options, ExpectedTypeBindingProperty expectedType = null) + public ParsedExpressionBindingProperty GetExpression(OriginalStringBindingProperty originalString, DataContextStack dataContext, BindingParserOptions options, ExpectedTypeBindingProperty? expectedType = null) { var expr = bindingParser.ParseWithLambdaConversion(originalString.Code, dataContext, options, expectedType?.Type ?? typeof(object)); if (expr is StaticClassIdentifierExpression) @@ -111,7 +111,7 @@ public KnockoutJsExpressionBindingProperty CompileToJavascript(CastedExpressionB public SimplePathExpressionBindingProperty FormatSimplePath(KnockoutJsExpressionBindingProperty expression) { // if contains api parameter, can't use this as a path - if (expression.Expression.DescendantNodes().Any(n => n.TryGetAnnotation(out ViewModelInfoAnnotation vmInfo) && vmInfo.ExtensionParameter is RestApiRegistrationHelpers.ApiExtensionParameter apiParameter)) + if (expression.Expression.DescendantNodes().Any(n => n.TryGetAnnotation(out ViewModelInfoAnnotation? vmInfo) && vmInfo.ExtensionParameter is RestApiRegistrationHelpers.ApiExtensionParameter apiParameter)) throw new Exception($"Can't get a path expression for command binding from binding that is using rest api."); return new SimplePathExpressionBindingProperty(expression.Expression.FormatParametrizedScript()); } @@ -133,7 +133,7 @@ public static ParametrizedCode FormatJavascript(JsExpression node, bool allowObs return (StartsWithStatementLikeExpression(expr.Expression) ? expr : expr.Expression).FormatParametrizedScript(niceMode); } - private static bool StartsWithStatementLikeExpression(JsExpression expression) + private static bool StartsWithStatementLikeExpression(JsExpression? expression) { if (expression is JsFunctionExpression || expression is JsObjectExpression) return true; if (expression == null || !expression.HasChildren || @@ -146,7 +146,7 @@ expression is JsNewExpression || public ResultTypeBindingProperty GetResultType(ParsedExpressionBindingProperty expression) => new ResultTypeBindingProperty(expression.Expression.Type); - public ExpectedTypeBindingProperty GetExpectedType(AssignedPropertyBindingProperty property = null) + public ExpectedTypeBindingProperty GetExpectedType(AssignedPropertyBindingProperty? property = null) { var prop = property?.DotvvmProperty; if (prop == null) return new ExpectedTypeBindingProperty(typeof(object)); @@ -154,7 +154,7 @@ public ExpectedTypeBindingProperty GetExpectedType(AssignedPropertyBindingProper return new ExpectedTypeBindingProperty(prop.IsBindingProperty ? (prop.PropertyType.GenericTypeArguments.SingleOrDefault() ?? typeof(object)) : prop.PropertyType); } - public BindingResolverCollection GetAdditionalResolversFromProperty(AssignedPropertyBindingProperty property = null, DataContextStack stack = null) + public BindingResolverCollection GetAdditionalResolversFromProperty(AssignedPropertyBindingProperty? property = null, DataContextStack? stack = null) { var prop = property?.DotvvmProperty; if (prop == null) return new BindingResolverCollection(Enumerable.Empty()); @@ -162,7 +162,7 @@ public BindingResolverCollection GetAdditionalResolversFromProperty(AssignedProp return new BindingResolverCollection( prop.AttributeProvider.GetCustomAttributes() .SelectMany(o => o.GetResolvers()) - .Concat(stack.EnumerableItems().Reverse().SelectMany(s => s.BindingPropertyResolvers)) + .Concat(stack?.EnumerableItems().Reverse().SelectMany(s => s.BindingPropertyResolvers) ?? Enumerable.Empty()) .ToImmutableArray()); } @@ -181,11 +181,11 @@ public BindingCompilationRequirementsAttribute GetAdditionalResolversFromPropert private ConditionalWeakTable> bindingCounts = new ConditionalWeakTable>(); public IdBindingProperty CreateBindingId( - OriginalStringBindingProperty originalString = null, - ParsedExpressionBindingProperty expression = null, - DataContextStack dataContext = null, - ResolvedBinding resolvedBinding = null, - LocationInfoBindingProperty locationInfo = null) + OriginalStringBindingProperty? originalString = null, + ParsedExpressionBindingProperty? expression = null, + DataContextStack? dataContext = null, + ResolvedBinding? resolvedBinding = null, + LocationInfoBindingProperty? locationInfo = null) { var sb = new StringBuilder(); @@ -199,7 +199,7 @@ public IdBindingProperty CreateBindingId( // don't append expression when original string is present, so it does not have to be always exactly same if (originalString != null) sb.Append(originalString.Code); - else sb.Append(expression.Expression.ToString()); + else sb.Append(expression?.Expression.ToString()); sb.Append(" || "); while (dataContext != null) @@ -292,11 +292,11 @@ public DataSourceLengthBinding GetDataSourceLength(ParsedExpressionBindingProper else throw new NotSupportedException($"Can not find collection length from binding '{expression.Expression}'."); } - public DataSourceCurrentElementBinding GetDataSourceCurrentElement(ParsedExpressionBindingProperty expression, IBinding binding) + public DataSourceCurrentElementBinding? GetDataSourceCurrentElement(ParsedExpressionBindingProperty expression, IBinding binding) { Expression indexParameter() => Expression.Parameter(typeof(int), "_index").AddParameterAnnotation( new BindingParameterAnnotation(extensionParameter: new CurrentCollectionIndexExtensionParameter())); - Expression makeIndexer(Expression expr) => + Expression? makeIndexer(Expression expr) => expr.Type.GetProperty("Item") is PropertyInfo indexer && indexer.GetMethod?.GetParameters()?.Length == 1 ? Expression.MakeIndex(expr, indexer, new[] { indexParameter() }) : expr.Type.IsArray ? @@ -310,7 +310,7 @@ Expression makeIndexer(Expression expr) => else if (typeof(IBaseGridViewDataSet).IsAssignableFrom(expression.Expression.Type)) return new DataSourceCurrentElementBinding(binding.DeriveBinding( - new ParsedExpressionBindingProperty(makeIndexer(Expression.Property(expression.Expression, nameof(IBaseGridViewDataSet.Items)))))); + new ParsedExpressionBindingProperty(makeIndexer(Expression.Property(expression.Expression, nameof(IBaseGridViewDataSet.Items))).NotNull()))); else throw new NotSupportedException($"Can not access current element on binding '{expression.Expression}' of type '{expression.Expression.Type}'."); } @@ -321,7 +321,7 @@ public StaticCommandJsAstProperty CompileStaticCommand(DataContextStack dataCont public StaticCommandJavascriptProperty FormatStaticCommand(StaticCommandJsAstProperty code) => new StaticCommandJavascriptProperty(FormatJavascript(code.Expression, allowObservableResult: false, niceMode: configuration.Debug)); - public LocationInfoBindingProperty GetLocationInfo(ResolvedBinding resolvedBinding, AssignedPropertyBindingProperty assignedProperty = null) + public LocationInfoBindingProperty GetLocationInfo(ResolvedBinding resolvedBinding, AssignedPropertyBindingProperty? assignedProperty = null) { return new LocationInfoBindingProperty( resolvedBinding.TreeRoot?.FileName, @@ -336,13 +336,13 @@ public SelectorItemBindingProperty GetItemLambda(ParsedExpressionBindingProperty { var argument = Expression.Parameter(dataContext.DataContextType, "i"); return new SelectorItemBindingProperty(binding.DeriveBinding( - dataContext.Parent, + dataContext.Parent.NotNull(), Expression.Lambda(expression.Expression.ReplaceAll(e => e?.GetParameterAnnotation() is BindingParameterAnnotation annotation && annotation.DataContext == dataContext && - annotation.ExtensionParameter == null ? - argument : - e), argument) + annotation.ExtensionParameter == null ? argument : e!), + argument + ) )); } @@ -358,7 +358,7 @@ public ThisBindingProperty GetThisBinding(IBinding binding, DataContextStack sta public CollectionElementDataContextBindingProperty GetCollectionElementDataContext(DataContextStack dataContext, ResultTypeBindingProperty resultType) { return new CollectionElementDataContextBindingProperty(DataContextStack.Create( - ReflectionUtils.GetEnumerableType(resultType.Type), + ReflectionUtils.GetEnumerableType(resultType.Type).NotNull(), parent: dataContext, extensionParameters: new CollectionElementDataContextChangeAttribute(0).GetExtensionParameters(new ResolvedTypeDescriptor(dataContext.DataContextType)).ToArray() )); diff --git a/src/DotVVM.Framework/Compilation/Binding/MemberExpressionFactory.cs b/src/DotVVM.Framework/Compilation/Binding/MemberExpressionFactory.cs index 1146a9eb5c..0c4a57f81c 100644 --- a/src/DotVVM.Framework/Compilation/Binding/MemberExpressionFactory.cs +++ b/src/DotVVM.Framework/Compilation/Binding/MemberExpressionFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.Dynamic; using System.Linq; using System.Linq.Expressions; @@ -21,16 +22,13 @@ public class MemberExpressionFactory private readonly ExtensionMethodsCache extensionMethodsCache; private static readonly Type ParamArrayAttributeType = typeof(ParamArrayAttribute); - public MemberExpressionFactory(ExtensionMethodsCache extensionMethodsCache, IReadOnlyList importedNamespaces = null) + public MemberExpressionFactory(ExtensionMethodsCache extensionMethodsCache, IReadOnlyList? importedNamespaces = null) { - if (importedNamespaces == null) - importedNamespaces = ImmutableList.Empty; - this.extensionMethodsCache = extensionMethodsCache; - this.importedNamespaces = importedNamespaces; + this.importedNamespaces = importedNamespaces ?? ImmutableList.Empty; } - public Expression GetMember(Expression target, string name, Type[] typeArguments = null, bool throwExceptions = true, bool onlyMemberTypes = false) + public Expression? GetMember(Expression target, string name, Type[]? typeArguments = null, bool throwExceptions = true, bool onlyMemberTypes = false) { if (target is MethodGroupExpression) throw new Exception("Can not access member on method group."); @@ -41,7 +39,7 @@ public Expression GetMember(Expression target, string name, Type[] typeArguments var isStatic = target is StaticClassIdentifierExpression; var isGeneric = typeArguments != null && typeArguments.Length != 0; - var genericName = isGeneric ? $"{name}`{typeArguments.Length}" : name; + var genericName = isGeneric ? $"{name}`{typeArguments!.Length}" : name; if (!isGeneric && !onlyMemberTypes && typeof(DotvvmBindableObject).IsAssignableFrom(target.Type) && GetDotvvmPropertyMember(target, name) is Expression result) return result; @@ -88,7 +86,7 @@ public Expression GetMember(Expression target, string name, Type[] typeArguments } var candidates = members.Cast().ToList(); - return new MethodGroupExpression() { MethodName = name, Target = target, TypeArgs = typeArguments, Candidates = candidates, HasExtensionCandidates = isExtension }; + return new MethodGroupExpression(target, name, typeArguments, candidates, isExtension); } private bool ExtensionMethodsFilter(Expression target, MethodInfo method) @@ -111,7 +109,7 @@ private bool ExtensionMethodsFilter(Expression target, MethodInfo method) } } - private Expression GetDotvvmPropertyMember(Expression target, string name) + private Expression? GetDotvvmPropertyMember(Expression target, string name) { var property = DotvvmProperty.ResolveProperty(target.Type, name); if (property == null) return null; @@ -138,7 +136,7 @@ private Expression GetDotvvmPropertyMember(Expression target, string name) /// replaced with a /// call. /// - public Expression UpdateMember(Expression node, Expression value) + public Expression? UpdateMember(Expression node, Expression value) { if ((node.NodeType == ExpressionType.MemberAccess && node is MemberExpression member @@ -175,7 +173,7 @@ public Expression UpdateMember(Expression node, Expression value) return null; } - public Expression Call(Expression target, Expression[] arguments) + public Expression Call(Expression? target, Expression[] arguments) { if (target is MethodGroupExpression) { @@ -184,7 +182,7 @@ public Expression Call(Expression target, Expression[] arguments) return Expression.Invoke(target, arguments); } - public Expression CallMethod(Expression target, BindingFlags flags, string name, Type[] typeArguments, Expression[] arguments, IDictionary namedArgs = null) + public Expression CallMethod(Expression target, BindingFlags flags, string name, Type[]? typeArguments, Expression[] arguments, IDictionary? namedArgs = null) { // the following piece of code is nicer and more readable than method recognition done in roslyn, C# dynamic and also expression evaluator :) var method = FindValidMethodOverloads(target, target.Type, name, flags, typeArguments, arguments, namedArgs); @@ -197,7 +195,7 @@ public Expression CallMethod(Expression target, BindingFlags flags, string name, return Expression.Call(target, method.Method, method.Arguments); } - public Expression CallMethod(Type target, BindingFlags flags, string name, Type[] typeArguments, Expression[] arguments, IDictionary namedArgs = null) + public Expression CallMethod(Type target, BindingFlags flags, string name, Type[]? typeArguments, Expression[] arguments, IDictionary? namedArgs = null) { // the following piece of code is nicer and more readable than method recognition done in roslyn, C# dynamic and also expression evaluator :) var method = FindValidMethodOverloads(null, target, name, flags, typeArguments, arguments, namedArgs); @@ -205,7 +203,7 @@ public Expression CallMethod(Type target, BindingFlags flags, string name, Type[ } - private MethodRecognitionResult FindValidMethodOverloads(Expression target, Type type, string name, BindingFlags flags, Type[] typeArguments, Expression[] arguments, IDictionary namedArgs) + private MethodRecognitionResult FindValidMethodOverloads(Expression? target, Type type, string name, BindingFlags flags, Type[]? typeArguments, Expression[] arguments, IDictionary? namedArgs) { var methods = FindValidMethodOverloads(type.GetAllMembers(flags).OfType().Where(m => m.Name == name), typeArguments, arguments, namedArgs).ToList(); @@ -252,7 +250,7 @@ private IEnumerable GetAllExtensionMethods() yield return method; } - private IEnumerable FindValidMethodOverloads(IEnumerable methods, Type[] typeArguments, Expression[] arguments, IDictionary namedArgs) + private IEnumerable FindValidMethodOverloads(IEnumerable methods, Type[]? typeArguments, Expression[] arguments, IDictionary? namedArgs) => from m in methods let r = TryCallMethod(m, typeArguments, arguments, namedArgs) where r != null @@ -261,6 +259,17 @@ private IEnumerable FindValidMethodOverloads(IEnumerabl class MethodRecognitionResult { + public MethodRecognitionResult(int automaticTypeArgCount, int castCount, Expression[] arguments, MethodInfo method, int paramsArrayCount, bool isExtension, bool hasParamsAttribute) + { + AutomaticTypeArgCount = automaticTypeArgCount; + CastCount = castCount; + Arguments = arguments; + Method = method; + ParamsArrayCount = paramsArrayCount; + IsExtension = isExtension; + HasParamsAttribute = hasParamsAttribute; + } + public int AutomaticTypeArgCount { get; set; } public int CastCount { get; set; } public Expression[] Arguments { get; set; } @@ -270,10 +279,10 @@ class MethodRecognitionResult public bool HasParamsAttribute { get; set; } } - private MethodRecognitionResult TryCallMethod(MethodInfo method, Type[] typeArguments, Expression[] positionalArguments, IDictionary namedArguments) + private MethodRecognitionResult? TryCallMethod(MethodInfo method, Type[]? typeArguments, Expression[] positionalArguments, IDictionary? namedArguments) { var parameters = method.GetParameters(); - var hasParamsArrayAttributes = parameters?.LastOrDefault()?.GetCustomAttribute(ParamArrayAttributeType) is object; + var hasParamsArrayAttributes = parameters.LastOrDefault()?.GetCustomAttribute(ParamArrayAttributeType) is object; if (!TryPrepareArguments(parameters, positionalArguments, namedArguments, out var args, out var castCount)) return null; @@ -345,21 +354,22 @@ private MethodRecognitionResult TryCallMethod(MethodInfo method, Type[] typeArgu } } - return new MethodRecognitionResult { - CastCount = castCount, - AutomaticTypeArgCount = automaticTypeArgs, - Method = method, - Arguments = args, - ParamsArrayCount = positionalArguments.Length - args.Length, - HasParamsAttribute = hasParamsArrayAttributes - }; + return new MethodRecognitionResult( + automaticTypeArgCount: automaticTypeArgs, + castCount: castCount, + method: method, + arguments: args, + paramsArrayCount: positionalArguments.Length - args.Length, + hasParamsAttribute: hasParamsArrayAttributes, + isExtension: false + ); } - private static bool TryPrepareArguments(ParameterInfo[] parameters, Expression[] positionalArguments, IDictionary namedArguments, out Expression[] arguments, out int castCount) + private static bool TryPrepareArguments(ParameterInfo[] parameters, Expression[] positionalArguments, IDictionary? namedArguments, [MaybeNullWhen(false)] out Expression[] arguments, out int castCount) { castCount = 0; arguments = null; var addedArguments = 0; - var hasParamsArrayAttribute = parameters?.LastOrDefault()?.GetCustomAttribute(ParamArrayAttributeType) is object; + var hasParamsArrayAttribute = parameters.LastOrDefault()?.GetCustomAttribute(ParamArrayAttributeType) is object; // For methods without `params` arguments count must be at least equal to parameters count if (!hasParamsArrayAttribute && parameters.Length < positionalArguments.Length) @@ -420,7 +430,7 @@ private static bool TryPrepareArguments(ParameterInfo[] parameters, Expression[] return true; } - private Type GetGenericParameterType(Type genericArg, Type[] searchedGenericTypes, Type[] expressionTypes) + private Type? GetGenericParameterType(Type genericArg, Type[] searchedGenericTypes, Type[] expressionTypes) { for (var i = 0; i < searchedGenericTypes.Length; i++) { @@ -441,7 +451,7 @@ private Type GetGenericParameterType(Type genericArg, Type[] searchedGenericType } else if (sgt.IsGenericType) { - Type[] genericArguments = null; + Type[]? genericArguments = null; var expression = expressionTypes[i]; if (expression.IsArray) @@ -495,8 +505,8 @@ private Type GetGenericParameterType(Type genericArg, Type[] searchedGenericType public Expression EqualsMethod(Expression left, Expression right) { - Expression equatable = null; - Expression theOther = null; + Expression? equatable = null; + Expression? theOther = null; if (typeof(IEquatable<>).IsAssignableFrom(left.Type)) { equatable = left; @@ -510,7 +520,7 @@ public Expression EqualsMethod(Expression left, Expression right) if (equatable != null) { - var m = CallMethod(equatable, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy, "Equals", null, new[] { theOther }); + var m = CallMethod(equatable, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy, "Equals", null, new[] { theOther! }); if (m != null) return m; } @@ -527,7 +537,7 @@ public Expression EqualsMethod(Expression left, Expression right) if (equatable != null) { - theOther = TypeConversion.ImplicitConversion(theOther, equatable.Type); + theOther = TypeConversion.ImplicitConversion(theOther!, equatable.Type); if (theOther != null) return Expression.Equal(equatable, theOther); } @@ -537,8 +547,8 @@ public Expression EqualsMethod(Expression left, Expression right) public Expression CompareMethod(Expression left, Expression right) { Type compareType = typeof(object); - Expression equatable = null; - Expression theOther = null; + Expression? equatable = null; + Expression? theOther = null; if (typeof(IComparable<>).IsAssignableFrom(left.Type)) { equatable = left; @@ -562,7 +572,7 @@ public Expression CompareMethod(Expression left, Expression right) if (equatable != null) { - return CallMethod(equatable, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy, "Compare", null, new[] { theOther }); + return CallMethod(equatable, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy, "Compare", null, new[] { theOther! }); } throw new NotSupportedException("IComparable is not implemented on any of specified types"); } @@ -571,7 +581,7 @@ public Expression GetUnaryOperator(Expression expr, ExpressionType operation) { var binder = (DynamicMetaObjectBinder)Microsoft.CSharp.RuntimeBinder.Binder.UnaryOperation( CSharpBinderFlags.None, operation, typeof(object), ExpressionHelper.GetBinderArguments(1)); - return ExpressionHelper.ApplyBinder(binder, true, expr); + return ExpressionHelper.ApplyBinder(binder, true, expr)!; } public Expression GetBinaryOperator(Expression left, Expression right, ExpressionType operation) diff --git a/src/DotVVM.Framework/Compilation/Binding/MethodGroupExpression.cs b/src/DotVVM.Framework/Compilation/Binding/MethodGroupExpression.cs index f08dd93030..8ab261459f 100644 --- a/src/DotVVM.Framework/Compilation/Binding/MethodGroupExpression.cs +++ b/src/DotVVM.Framework/Compilation/Binding/MethodGroupExpression.cs @@ -15,16 +15,25 @@ public class MethodGroupExpression : Expression public override bool CanReduce => GetMethod() != null; - public Expression Target { get; set; } - public string MethodName { get; set; } - public Type[] TypeArgs { get; set; } - public List Candidates { get; set; } - public bool HasExtensionCandidates { get; set; } + public Expression Target { get; } + public string MethodName { get; } + public Type[]? TypeArgs { get; } + public List? Candidates { get; set; } + public bool HasExtensionCandidates { get; } public bool IsStatic => Target is StaticClassIdentifierExpression; private static MethodInfo CreateDelegateMethodInfo = typeof(Delegate).GetMethod("CreateDelegate", new[] { typeof(Type), typeof(object), typeof(MethodInfo) }); - public Expression CreateDelegateExpression(Type delegateType, bool throwException = true) + public MethodGroupExpression(Expression target, string methodName, Type[]? typeArgs = null, List? candidates = null, bool hasExtensionCandidates = false) + { + Target = target; + MethodName = methodName; + TypeArgs = typeArgs; + Candidates = candidates; + HasExtensionCandidates = hasExtensionCandidates; + } + + public Expression? CreateDelegateExpression(Type delegateType, bool throwException = true) { if (delegateType == null || delegateType == typeof(object)) return CreateDelegateExpression(); if (!typeof(Delegate).IsAssignableFrom(delegateType)) if (throwException) throw new Exception("Could not convert method group expression to a non delegate type."); else return null; @@ -79,7 +88,7 @@ public Expression CreateMethodCall(IEnumerable args, MemberExpressio var argsArray = args.ToArray(); if (IsStatic) { - return memberExpressionFactory.CallMethod((Target as StaticClassIdentifierExpression).Type, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy, MethodName, TypeArgs, argsArray); + return memberExpressionFactory.CallMethod(((StaticClassIdentifierExpression)Target).Type, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy, MethodName, TypeArgs, argsArray); } else { diff --git a/src/DotVVM.Framework/Compilation/Binding/StaticCommandBindingCompiler.cs b/src/DotVVM.Framework/Compilation/Binding/StaticCommandBindingCompiler.cs index 6b32233f93..c0a9c0e872 100644 --- a/src/DotVVM.Framework/Compilation/Binding/StaticCommandBindingCompiler.cs +++ b/src/DotVVM.Framework/Compilation/Binding/StaticCommandBindingCompiler.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; @@ -12,15 +11,8 @@ using DotVVM.Framework.Compilation.ControlTree.Resolved; using DotVVM.Framework.Compilation.Javascript; using DotVVM.Framework.Compilation.Javascript.Ast; -using DotVVM.Framework.Hosting; -using DotVVM.Framework.Security; -using DotVVM.Framework.Testing; using DotVVM.Framework.Utils; -using DotVVM.Framework.ViewModel; using DotVVM.Framework.ViewModel.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Bson; -using Newtonsoft.Json.Linq; using Microsoft.Extensions.Options; namespace DotVVM.Framework.Compilation.Binding @@ -46,7 +38,7 @@ private static Expression ReplaceCommandArgs(Expression expression) => _ => new JsSymbolicParameter(CommandBindingExpression.CommandArgumentsParameter) .Indexer(new JsLiteral(extensionParam.ArgumentIndex)) ))) : - e + e! ); public JsExpression CompileToJavascript(DataContextStack dataContext, Expression expression) @@ -125,7 +117,7 @@ public IEnumerable GetAllMethods() yield return Method; foreach (var arg in Arguments) if (arg.Type == StaticCommandParameterType.Invocation) - foreach (var r in arg.Arg.CastTo().GetAllMethods()) + foreach (var r in arg.Arg!.CastTo().GetAllMethods()) yield return r; } } @@ -133,9 +125,9 @@ public IEnumerable GetAllMethods() public class StaticCommandParameterPlan { public StaticCommandParameterType Type { get; } - public object Arg { get; } + public object? Arg { get; } - public StaticCommandParameterPlan(StaticCommandParameterType type, object arg) + public StaticCommandParameterPlan(StaticCommandParameterType type, object? arg) { this.Type = type; this.Arg = arg; diff --git a/src/DotVVM.Framework/Compilation/Binding/StaticCommandExecutionPlanSerializer.cs b/src/DotVVM.Framework/Compilation/Binding/StaticCommandExecutionPlanSerializer.cs index 6010df4452..a63b382085 100644 --- a/src/DotVVM.Framework/Compilation/Binding/StaticCommandExecutionPlanSerializer.cs +++ b/src/DotVVM.Framework/Compilation/Binding/StaticCommandExecutionPlanSerializer.cs @@ -28,7 +28,7 @@ public static JToken SerializePlan(StaticCommandInvocationPlan plan) if ((parameter?.ParameterType ?? plan.Method.DeclaringType).Equals(arg.Arg)) array.Add(JValue.CreateNull()); else - array.Add(new JValue(arg.Arg.CastTo().Apply(GetTypeFullName))); + array.Add(new JValue(arg.Arg!.CastTo().Apply(GetTypeFullName))); } else if (arg.Type == StaticCommandParameterType.Constant) { @@ -43,11 +43,11 @@ public static JToken SerializePlan(StaticCommandInvocationPlan plan) if ((parameter?.ParameterType ?? plan.Method.DeclaringType).Equals(arg.Arg)) array.Add(JValue.CreateNull()); else - array.Add(new JValue(arg.Arg.CastTo().Apply(GetTypeFullName))); + array.Add(new JValue(arg.Arg!.CastTo().Apply(GetTypeFullName))); } else if (arg.Type == StaticCommandParameterType.Invocation) { - array.Add(SerializePlan((StaticCommandInvocationPlan)arg.Arg)); + array.Add(SerializePlan((StaticCommandInvocationPlan)arg.Arg!)); } else throw new NotSupportedException(arg.Type.ToString()); } @@ -108,7 +108,7 @@ public static StaticCommandInvocationPlan DeserializePlan(JToken planInJson) case StaticCommandParameterType.Constant: return new StaticCommandParameterPlan(a.type, a.arg.ToObject(a.parameter?.ParameterType ?? methodFound.DeclaringType)); case StaticCommandParameterType.DefaultValue: - return new StaticCommandParameterPlan(a.type, a.parameter.DefaultValue); + return new StaticCommandParameterPlan(a.type, a.parameter?.DefaultValue); case StaticCommandParameterType.Invocation: return new StaticCommandParameterPlan(a.type, DeserializePlan(a.arg)); default: diff --git a/src/DotVVM.Framework/Compilation/Binding/StaticCommandMethodTranslator.cs b/src/DotVVM.Framework/Compilation/Binding/StaticCommandMethodTranslator.cs index 71a584b5c2..53c2025c9b 100644 --- a/src/DotVVM.Framework/Compilation/Binding/StaticCommandMethodTranslator.cs +++ b/src/DotVVM.Framework/Compilation/Binding/StaticCommandMethodTranslator.cs @@ -25,7 +25,7 @@ public StaticCommandMethodTranslator(IViewModelProtector protector) this.protector = protector; } - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) + public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) { // throw new Exception($"Method '{methodExpression.Method.DeclaringType.Name}.{methodExpression.Method.Name}' used in static command has to be marked with [AllowStaticCommand] attribute."); if (!method.IsDefined(typeof(AllowStaticCommandAttribute))) @@ -46,7 +46,7 @@ public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTrans .WithAnnotation(resultTypeAnn); } - private (StaticCommandInvocationPlan plan, JsExpression[] clientArgs) CreateExecutionPlan(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) + private (StaticCommandInvocationPlan plan, JsExpression[] clientArgs) CreateExecutionPlan(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) { var allArguments = (context?.OriginalExpression is null ? new LazyTranslatedExpression[0] : new[] { context }).Concat(arguments).ToArray(); var clientArgs = new List(); diff --git a/src/DotVVM.Framework/Compilation/Binding/TypeConversions.cs b/src/DotVVM.Framework/Compilation/Binding/TypeConversions.cs index d60bd8e2c3..f5aeaec543 100644 --- a/src/DotVVM.Framework/Compilation/Binding/TypeConversions.cs +++ b/src/DotVVM.Framework/Compilation/Binding/TypeConversions.cs @@ -16,7 +16,7 @@ namespace DotVVM.Framework.Compilation.Binding public class TypeConversion { private static Dictionary> ImplicitNumericConversions = new Dictionary>(); - private static readonly Dictionary typePrecedence = null; + private static readonly Dictionary typePrecedence; /// /// Performs implicit conversion between two expressions depending on their type precedence @@ -89,7 +89,7 @@ internal static int CanConvert(Type from, Type to) // Furthermore an enum-type can be converted to the type System.Enum. // A boxing conversion exists from a nullable-type to a reference type, if and only if a boxing conversion exists from the underlying non-nullable-value-type to the reference type. // A value type has a boxing conversion to an interface type I if it has a boxing conversion to an interface type I0 and I0 has an identity conversion to I. - public static Expression BoxingConversion(Expression src, Type destType) + public static Expression? BoxingConversion(Expression src, Type destType) { if (src.Type.IsValueType && src.Type != typeof(void) && destType == typeof(object)) { @@ -99,7 +99,7 @@ public static Expression BoxingConversion(Expression src, Type destType) } //6.1.4 Nullable Type conversions - public static Expression NullableConversion(Expression src, Type destType) + public static Expression? NullableConversion(Expression src, Type destType) { if (Nullable.GetUnderlyingType(src.Type) == destType) { @@ -123,7 +123,7 @@ public static Expression NullableConversion(Expression src, Type destType) // 6.1.5 Null literal conversions // An implicit conversion exists from the null literal to any nullable type. // This conversion produces the null value (§4.1.10) of the given nullable type. - public static Expression NullLiteralConversion(Expression src, Type destType) + public static Expression? NullLiteralConversion(Expression src, Type destType) { if (src.NodeType == ExpressionType.Constant && src.Type == typeof(object) && ((ConstantExpression)src).Value == null) { @@ -139,7 +139,7 @@ public static Expression NullLiteralConversion(Expression src, Type destType) return null; } - public static Expression ReferenceConversion(Expression src, Type destType) + public static Expression? ReferenceConversion(Expression src, Type destType) { if (destType.IsAssignableFrom(src.Type) && src.Type != typeof(void)) { @@ -149,11 +149,11 @@ public static Expression ReferenceConversion(Expression src, Type destType) } // 6.1 Implicit Conversions - public static Expression ImplicitConversion(Expression src, Type destType, bool throwException = false, bool allowToString = false) + public static Expression? ImplicitConversion(Expression src, Type destType, bool throwException = false, bool allowToString = false) { - if (src is MethodGroupExpression) + if (src is MethodGroupExpression methodGroup) { - return ((MethodGroupExpression)src).CreateDelegateExpression(destType, throwException); + return methodGroup.CreateDelegateExpression(destType, throwException); } if (src.Type == destType) return src; var result = ImplicitConstantConversion(src, destType) ?? @@ -176,7 +176,7 @@ public static bool IsStringConversionAllowed(Type fromType) return fromType.IsPrimitive || typeof(IConvertible).IsAssignableFrom(fromType) || fromType.GetMethod("ToString", Type.EmptyTypes)?.DeclaringType != typeof(object); } - public static Expression ToStringConversion(Expression src) + public static Expression? ToStringConversion(Expression src) { var toStringMethod = src.Type.GetMethod("ToString", Type.EmptyTypes); if (toStringMethod?.DeclaringType == typeof(object)) @@ -200,7 +200,7 @@ public static Expression ToStringConversion(Expression src) // 6.1.9 Implicit constant expression conversions [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] - public static Expression ImplicitConstantConversion(Expression src, Type destType) + public static Expression? ImplicitConstantConversion(Expression src, Type destType) { if (src.NodeType == ExpressionType.Conditional && src is ConditionalExpression conditional && ImplicitConversion(conditional.IfTrue, destType) is Expression ifTrue && @@ -297,38 +297,11 @@ public static Expression ImplicitConstantConversion(Expression src, Type destTyp return null; } - public static Type GetBaseCommonType(IEnumerable expressions) - { - Type baseType = null; - - foreach (var expression in expressions) - { - if (baseType == null) - { - baseType = expression.Type; - } - else - { - switch (CanConvert(expression.Type, baseType)) - { - case 1: - baseType = expression.Type; - break; - - case -1: - throw new Exception(string.Format("Cannot convert between types {0} and {1}", baseType.Name, expression.Type.Name)); - } - } - } - - return baseType; - } - // 6.1.2 Implicit numeric conversions /// /// Tries to perform implicit numeric conversion /// - public static Expression ImplicitNumericConversion(Expression src, Type target) + public static Expression? ImplicitNumericConversion(Expression src, Type target) { List allowed; if (ImplicitNumericConversions.TryGetValue(src.Type, out allowed)) @@ -344,7 +317,7 @@ public static Expression ImplicitNumericConversion(Expression src, Type target) /// This is a strange conversion that wraps the entire expression into a Lambda /// and makes an invocable delegate from a normal expression. /// It also replaces special ExtensionParameters attached to the expression for lambda parameters - public static Expression MagicLambdaConversion(Expression expr, Type expectedType) + public static Expression? MagicLambdaConversion(Expression expr, Type expectedType) { if (expectedType.IsDelegate()) { @@ -366,7 +339,7 @@ public static Expression MagicLambdaConversion(Expression expr, Type expectedTyp arg?.GetParameterAnnotation()?.ExtensionParameter is MagicLambdaConversionExtensionParameter extensionParam ? delegateArgs.Single(a => a.Name == extensionParam.Identifier) .Assert(p => p.Type == ResolvedTypeDescriptor.ToSystemType(extensionParam.ParameterType)) : - arg + arg! ); return Expression.Lambda( expectedType, @@ -401,7 +374,7 @@ private static Type GetTaskType(Type taskType) => taskType.GetProperty("Result")?.PropertyType ?? typeof(void); /// Performs conversions by wrapping or unwrapping results to/from - public static Expression TaskConversion(Expression expr, Type expectedType) + public static Expression? TaskConversion(Expression expr, Type expectedType) { if (typeof(Task).IsAssignableFrom(expectedType)) { diff --git a/src/DotVVM.Framework/Compilation/Binding/TypeRegistry.cs b/src/DotVVM.Framework/Compilation/Binding/TypeRegistry.cs index 4574a3c01d..b105ae96e9 100644 --- a/src/DotVVM.Framework/Compilation/Binding/TypeRegistry.cs +++ b/src/DotVVM.Framework/Compilation/Binding/TypeRegistry.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; using DotVVM.Framework.Utils; @@ -11,16 +12,16 @@ public class TypeRegistry { private readonly CompiledAssemblyCache compiledAssemblyCache; private readonly ImmutableDictionary registry; - private readonly ImmutableList> resolvers; + private readonly ImmutableList> resolvers; - public TypeRegistry(CompiledAssemblyCache compiledAssemblyCache, ImmutableDictionary registry, ImmutableList> resolvers) + public TypeRegistry(CompiledAssemblyCache compiledAssemblyCache, ImmutableDictionary registry, ImmutableList> resolvers) { this.compiledAssemblyCache = compiledAssemblyCache; this.registry = registry; this.resolvers = resolvers; } - public Expression Resolve(string name, bool throwOnNotFound = true) + public Expression? Resolve(string name, bool throwOnNotFound = true) { if (string.IsNullOrWhiteSpace(name)) { @@ -28,7 +29,7 @@ public Expression Resolve(string name, bool throwOnNotFound = true) else return null; } - Expression expr; + Expression? expr; if (registry.TryGetValue(name, out expr)) { return expr; @@ -47,12 +48,13 @@ public TypeRegistry AddSymbols(IEnumerable> sym return new TypeRegistry(compiledAssemblyCache, registry.AddRange(symbols), resolvers); } - public TypeRegistry AddSymbols(IEnumerable> symbols) + public TypeRegistry AddSymbols(IEnumerable> symbols) { return new TypeRegistry(compiledAssemblyCache, registry, resolvers.InsertRange(0, symbols)); } - public static Expression CreateStatic(Type type) + [return: NotNullIfNotNull("type")] + public static Expression? CreateStatic(Type? type) { return type == null ? null : new StaticClassIdentifierExpression(type); } @@ -87,12 +89,12 @@ public static Expression CreateStatic(Type type) .Add("Double", CreateStatic(typeof(Double))) .Add("Single", CreateStatic(typeof(Single))) .Add("String", CreateStatic(typeof(String))), - ImmutableList>.Empty + ImmutableList>.Empty .Add(type => CreateStatic(compiledAssemblyCache.FindType(type))) .Add(type => CreateStatic(compiledAssemblyCache.FindType("System." + type))) ); - public static TypeRegistry DirectivesDefault(CompiledAssemblyCache compiledAssemblyCache, string assemblyName = null) => new TypeRegistry(compiledAssemblyCache, + public static TypeRegistry DirectivesDefault(CompiledAssemblyCache compiledAssemblyCache, string? assemblyName = null) => new TypeRegistry(compiledAssemblyCache, ImmutableDictionary.Empty .Add("object", CreateStatic(typeof(Object))) .Add("bool", CreateStatic(typeof(Boolean))) @@ -122,7 +124,7 @@ public static Expression CreateStatic(Type type) .Add("Double", CreateStatic(typeof(Double))) .Add("Single", CreateStatic(typeof(Single))) .Add("String", CreateStatic(typeof(String))), - ImmutableList>.Empty + ImmutableList>.Empty .Add(type => CreateStatic(compiledAssemblyCache.FindType(type + (assemblyName != null ? $", {assemblyName}" : "")))) ); } diff --git a/src/DotVVM.Framework/Compilation/BindingCompiler.cs b/src/DotVVM.Framework/Compilation/BindingCompiler.cs index 76f8e87fc5..0e7bd9f897 100644 --- a/src/DotVVM.Framework/Compilation/BindingCompiler.cs +++ b/src/DotVVM.Framework/Compilation/BindingCompiler.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/BindingParserException.cs b/src/DotVVM.Framework/Compilation/BindingParserException.cs index 90e59206d8..a77bed1152 100644 --- a/src/DotVVM.Framework/Compilation/BindingParserException.cs +++ b/src/DotVVM.Framework/Compilation/BindingParserException.cs @@ -9,7 +9,7 @@ public class BindingParserException : Exception public Type[] DataContextAncestors { get; set; } public Type ControlType { get; set; } - public BindingParserException(Type dataContext, string bindingExpression, Type[] dataContextAncestors, Type controlType, Exception innerException = null) + public BindingParserException(Type dataContext, string bindingExpression, Type[] dataContextAncestors, Type controlType, Exception? innerException = null) : base($"Failed to parse binding '{ bindingExpression }' in the context of '{ dataContext.Name }' type.", innerException) { DataContext = dataContext; diff --git a/src/DotVVM.Framework/Compilation/BindingParserOptions.cs b/src/DotVVM.Framework/Compilation/BindingParserOptions.cs index 278553723a..cb7d14769b 100644 --- a/src/DotVVM.Framework/Compilation/BindingParserOptions.cs +++ b/src/DotVVM.Framework/Compilation/BindingParserOptions.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq; using System.Linq.Expressions; using DotVVM.Framework.Compilation.Binding; @@ -37,7 +36,7 @@ public virtual TypeRegistry AddImportedTypes(TypeRegistry reg, CompiledAssemblyC private static Func CreateTypeLoader(NamespaceImport import, CompiledAssemblyCache compiledAssemblyCache) { - if (import.HasAlias) + if (import.Alias is not null) return t => { if (t.Length >= import.Alias.Length && t.StartsWith(import.Alias, StringComparison.Ordinal)) { @@ -76,7 +75,7 @@ public static BindingParserOptions Create(Type bindingType, string scopeParamete public static readonly BindingParserOptions StaticCommand = Create(typeof(StaticCommandBindingExpression<>)); public BindingParserOptions AddImports(params NamespaceImport[]? imports) - => AddImports((IEnumerable)imports); + => AddImports((IEnumerable?)imports); public BindingParserOptions AddImports(IEnumerable? imports) => imports == null ? this : new BindingParserOptions(BindingType, ScopeParameter, ImportNamespaces.AddRange(imports), ExtensionParameters); diff --git a/src/DotVVM.Framework/Compilation/BindingRequiredResourceVisitor.cs b/src/DotVVM.Framework/Compilation/BindingRequiredResourceVisitor.cs index b2f5475754..f8392626fd 100644 --- a/src/DotVVM.Framework/Compilation/BindingRequiredResourceVisitor.cs +++ b/src/DotVVM.Framework/Compilation/BindingRequiredResourceVisitor.cs @@ -61,7 +61,7 @@ private void Visit(TNodeType node, List nodeContent, } } - private ResolvedControl CreateRequiredResourceControl(string resource, ResolvedTreeNode parent, Parser.Dothtml.Parser.DothtmlNode node, DataContextStack dataContext) + private ResolvedControl CreateRequiredResourceControl(string resource, ResolvedTreeNode parent, Parser.Dothtml.Parser.DothtmlNode? node, DataContextStack dataContext) { var control = new ResolvedControl(requiredResourceControlMetadata, node, dataContext); control.Parent = parent; @@ -73,7 +73,7 @@ private void AddResourcesFromProperties(ResolvedControl control) { if (control.TryGetProperty(Controls.Styles.RequiredResourcesProperty, out var value)) { - var newResources = (string[])((ResolvedPropertyValue)value).Value; + var newResources = (string[]?)((ResolvedPropertyValue)value).Value; if (newResources != null) requiredResources = requiredResources.Union(newResources); } diff --git a/src/DotVVM.Framework/Compilation/CompiledAssemblyCache.cs b/src/DotVVM.Framework/Compilation/CompiledAssemblyCache.cs index 160b0e0f62..34c318b8ed 100644 --- a/src/DotVVM.Framework/Compilation/CompiledAssemblyCache.cs +++ b/src/DotVVM.Framework/Compilation/CompiledAssemblyCache.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/BindingExtensionParameter.cs b/src/DotVVM.Framework/Compilation/ControlTree/BindingExtensionParameter.cs index 8e090935a2..123f1053ba 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/BindingExtensionParameter.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/BindingExtensionParameter.cs @@ -27,10 +27,10 @@ public abstract class BindingExtensionParameter /// When the extension parameter is introduced in a specific data context, this parameter controls if the parameter will also be valid in child data contexts. public bool Inherit { get; } - public BindingExtensionParameter(string identifier, ITypeDescriptor type, bool inherit) + public BindingExtensionParameter(string identifier, ITypeDescriptor? type, bool inherit) { this.Identifier = identifier; - this.ParameterType = type; + this.ParameterType = type ?? ResolvedTypeDescriptor.Create(typeof(object)); this.Inherit = inherit; } @@ -149,7 +149,7 @@ public override Expression GetServerEquivalent(Expression controlParameter) private object ResolveStaticCommandService(DotvvmBindableObject c, Type type) { - var context = (IDotvvmRequestContext)c.GetValue(Internal.RequestContextProperty, true); + var context = (IDotvvmRequestContext)c.GetValue(Internal.RequestContextProperty, true).NotNull(); #pragma warning disable CS0618 return context.Services.GetRequiredService().GetStaticCommandService(type, context); #pragma warning restore CS0618 diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverBase.cs b/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverBase.cs index e4b19871ed..1ed762e3a1 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverBase.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverBase.cs @@ -20,8 +20,8 @@ public abstract class ControlResolverBase : IControlResolver { private readonly DotvvmMarkupConfiguration configuration; - private readonly ConcurrentDictionary cachedTagMappings = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); - private readonly ConcurrentDictionary cachedMetadata = new ConcurrentDictionary(); + private readonly ConcurrentDictionary cachedTagMappings = new(StringComparer.OrdinalIgnoreCase); + private readonly ConcurrentDictionary cachedMetadata = new(); private readonly Lazy htmlGenericControlMetadata; @@ -37,13 +37,13 @@ public ControlResolverBase(DotvvmMarkupConfiguration configuration) } - htmlGenericControlMetadata = new Lazy(() => ResolveControl(new ResolvedTypeDescriptor(typeof(HtmlGenericControl)))); + htmlGenericControlMetadata = new(() => ResolveControl(new ResolvedTypeDescriptor(typeof(HtmlGenericControl)))); } /// /// Resolves the metadata for specified element. /// - public virtual IControlResolverMetadata ResolveControl(string tagPrefix, string tagName, out object[] activationParameters) + public virtual IControlResolverMetadata? ResolveControl(string? tagPrefix, string tagName, out object[]? activationParameters) { // html element has no prefix if (string.IsNullOrEmpty(tagPrefix)) @@ -93,10 +93,9 @@ public IControlResolverMetadata ResolveControl(IControlType controlType) /// /// Resolves the binding type. /// - public virtual BindingParserOptions ResolveBinding(string bindingType) + public virtual BindingParserOptions? ResolveBinding(string bindingType) { - BindingParserOptions bpo; - if (BindingTypes.TryGetValue(bindingType, out bpo)) + if (BindingTypes.TryGetValue(bindingType, out var bpo)) { return bpo; } @@ -109,7 +108,7 @@ public virtual BindingParserOptions ResolveBinding(string bindingType) /// /// Finds the control metadata. /// - protected virtual IControlType FindControlType(string tagPrefix, string tagName) + protected virtual IControlType? FindControlType(string tagPrefix, string tagName) { // try to match the tag prefix and tag name var rules = configuration.Controls.Where(r => r.IsMatch(tagPrefix, tagName)).ToArray(); @@ -135,14 +134,12 @@ protected virtual IControlType FindControlType(string tagPrefix, string tagName) } } return null; - - throw new Exception($"The control <{tagPrefix}:{tagName}> could not be resolved! Make sure that the tagPrefix is registered in DotvvmConfiguration.Markup.Controls collection!"); } /// /// Finds the property in the control metadata. /// - public IPropertyDescriptor FindProperty(IControlResolverMetadata controlMetadata, string name) + public IPropertyDescriptor? FindProperty(IControlResolverMetadata controlMetadata, string name) { if (name.Contains(".")) { @@ -156,11 +153,10 @@ public IPropertyDescriptor FindProperty(IControlResolverMetadata controlMetadata } } - private IPropertyDescriptor FindControlPropertyOrGroup(IControlResolverMetadata controlMetadata, string name) + private IPropertyDescriptor? FindControlPropertyOrGroup(IControlResolverMetadata controlMetadata, string name) { // try to find the property in metadata - IPropertyDescriptor property; - if (controlMetadata.TryGetProperty(name, out property)) + if (controlMetadata.TryGetProperty(name, out var property)) { return property; } @@ -182,12 +178,12 @@ private IPropertyDescriptor FindControlPropertyOrGroup(IControlResolverMetadata /// /// Finds the DotVVM property in the global property store. /// - protected abstract IPropertyDescriptor FindGlobalPropertyOrGroup(string name); + protected abstract IPropertyDescriptor? FindGlobalPropertyOrGroup(string name); /// /// Finds the compiled control. /// - protected abstract IControlType FindCompiledControl(string tagName, string namespaceName, string assemblyName); + protected abstract IControlType? FindCompiledControl(string tagName, string namespaceName, string assemblyName); /// /// Finds the markup control. diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadata.cs b/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadata.cs index 5c3c6df068..de0a8afe1e 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadata.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadata.cs @@ -15,10 +15,10 @@ public class ControlResolverMetadata : ControlResolverMetadataBase public new Type Type => controlType.Type; [JsonIgnore] - public new DotvvmProperty DefaultContentProperty => (DotvvmProperty) base.DefaultContentProperty; + public new DotvvmProperty? DefaultContentProperty => (DotvvmProperty?) base.DefaultContentProperty; [JsonIgnore] - public new Type DataContextConstraint => controlType.DataContextRequirement; + public new Type? DataContextConstraint => controlType.DataContextRequirement; public ControlResolverMetadata(ControlType controlType) : base(controlType) { @@ -37,7 +37,7 @@ public ControlResolverMetadata(Type type) : this(new ControlType(type)) [JsonIgnore] public override sealed DataContextChangeAttribute[] DataContextChangeAttributes { get; } [JsonIgnore] - public override sealed DataContextStackManipulationAttribute DataContextManipulationAttribute { get; } + public override sealed DataContextStackManipulationAttribute? DataContextManipulationAttribute { get; } protected override void LoadProperties(Dictionary result) @@ -52,10 +52,9 @@ protected override void LoadProperties(Dictionary r /// /// Finds the property. /// - public DotvvmProperty FindProperty(string name) + public DotvvmProperty? FindProperty(string name) { - IPropertyDescriptor result; - return Properties.TryGetValue(name, out result) ? (DotvvmProperty)result : null; + return Properties.TryGetValue(name, out var result) ? (DotvvmProperty)result : null; } protected override void LoadPropertyGroups(List result) diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadataBase.cs b/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadataBase.cs index c488093049..d3403beca8 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadataBase.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ControlResolverMetadataBase.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using DotVVM.Framework.Binding; using DotVVM.Framework.Compilation.ControlTree.Resolved; using DotVVM.Framework.Controls; @@ -10,7 +11,7 @@ namespace DotVVM.Framework.Compilation.ControlTree public abstract class ControlResolverMetadataBase : IControlResolverMetadata { private readonly IControlType controlType; - private readonly ControlMarkupOptionsAttribute attribute; + private readonly ControlMarkupOptionsAttribute? attribute; private readonly Lazy> properties; public IReadOnlyDictionary Properties => properties.Value; @@ -19,7 +20,7 @@ public abstract class ControlResolverMetadataBase : IControlResolverMetadata public IReadOnlyList PropertyGroups => _propertyGroups.Value; - public string Namespace => controlType.Type.Namespace; + public string? Namespace => controlType.Type.Namespace; public string Name => controlType.Type.Name; @@ -31,7 +32,7 @@ public abstract class ControlResolverMetadataBase : IControlResolverMetadata [JsonIgnore] public IEnumerable PropertyNames => Properties.Keys; - public bool TryGetProperty(string name, out IPropertyDescriptor value) + public bool TryGetProperty(string name, [NotNullWhen(true)] out IPropertyDescriptor? value) { return Properties.TryGetValue(name, out value); } @@ -43,7 +44,7 @@ public bool TryGetProperty(string name, out IPropertyDescriptor value) !Type.IsAssignableTo(new ResolvedTypeDescriptor(typeof(CompositeControl))); [JsonIgnore] - public IPropertyDescriptor DefaultContentProperty + public IPropertyDescriptor? DefaultContentProperty { get { @@ -57,22 +58,24 @@ public IPropertyDescriptor DefaultContentProperty return result; } - if (string.IsNullOrEmpty(attribute?.DefaultContentProperty)) + var prop = attribute?.DefaultContentProperty; + + if (string.IsNullOrEmpty(prop)) { return null; } - return Properties.TryGetValue(attribute?.DefaultContentProperty, out result) ? result : null; + return Properties.TryGetValue(prop, out result) ? result : null; } } - public string DefaultContentPropertyName => attribute?.DefaultContentProperty; + public string? DefaultContentPropertyName => attribute?.DefaultContentProperty; [JsonIgnore] - public string VirtualPath => controlType?.VirtualPath; + public string? VirtualPath => controlType?.VirtualPath; [JsonIgnore] - public ITypeDescriptor DataContextConstraint => controlType?.DataContextRequirement; + public ITypeDescriptor? DataContextConstraint => controlType?.DataContextRequirement; [JsonIgnore] public IEnumerable AllProperties => Properties.Values; @@ -80,7 +83,7 @@ public IPropertyDescriptor DefaultContentProperty [JsonIgnore] public abstract DataContextChangeAttribute[] DataContextChangeAttributes { get; } [JsonIgnore] - public abstract DataContextStackManipulationAttribute DataContextManipulationAttribute { get; } + public abstract DataContextStackManipulationAttribute? DataContextManipulationAttribute { get; } public ControlResolverMetadataBase(IControlType controlType) diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeHelper.cs b/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeHelper.cs index 08c0072e50..8639fef1b4 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeHelper.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeHelper.cs @@ -11,22 +11,19 @@ public static bool HasEmptyContent(this IAbstractControl control) public static bool HasProperty(this IAbstractControl control, IPropertyDescriptor property) { - IAbstractPropertySetter blackHole; - return control.TryGetProperty(property, out blackHole); + return control.TryGetProperty(property, out _); } public static bool HasPropertyValue(this IAbstractControl control, IPropertyDescriptor property) { - IAbstractPropertySetter setter; - return control.TryGetProperty(property, out setter) && setter is IAbstractPropertyValue; + return control.TryGetProperty(property, out var setter) && setter is IAbstractPropertyValue; } - public static IAbstractPropertySetter GetHtmlAttribute(this IAbstractControl control, string memberName) => + public static IAbstractPropertySetter? GetHtmlAttribute(this IAbstractControl control, string memberName) => GetPropertyGroupMember(control, "", memberName); - public static IAbstractPropertySetter GetPropertyGroupMember(this IAbstractControl control, string prefix, string memberName) + public static IAbstractPropertySetter? GetPropertyGroupMember(this IAbstractControl control, string prefix, string memberName) { - IAbstractPropertySetter value; - control.TryGetProperty(control.Metadata.GetPropertyGroupMember(prefix, memberName), out value); + control.TryGetProperty(control.Metadata.GetPropertyGroupMember(prefix, memberName), out var value); return value; } diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeResolverBase.cs b/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeResolverBase.cs index a3006cb079..8b841de6b6 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeResolverBase.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ControlTreeResolverBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -179,7 +178,7 @@ protected virtual IReadOnlyDictionary> protected virtual ImmutableList ResolveInjectDirectives(IReadOnlyDictionary> directives) => directives.Values.SelectMany(d => d).OfType() .Where(d => d.Type != null) - .Select(d => new InjectedServiceExtensionParameter(d.NameSyntax.Name, d.Type)) + .Select(d => new InjectedServiceExtensionParameter(d.NameSyntax.Name, d.Type!)) .ToImmutableList(); private (JsExtensionParameter extensionParameter, ViewModuleReferenceInfo resource)? ResolveImportedViewModules(string id, IReadOnlyDictionary> directives, bool isMarkupControl) @@ -355,7 +354,7 @@ private IAbstractControl ProcessObjectElement(DothtmlElementNode element, IDataC var controlMetadata = controlResolver.ResolveControl(element.TagPrefix, element.TagName, out var constructorParameters); if (controlMetadata == null) { - controlMetadata = controlResolver.ResolveControl("", element.TagName, out constructorParameters); + controlMetadata = controlResolver.ResolveControl("", element.TagName, out constructorParameters).NotNull(); constructorParameters = new[] { element.FullTagName }; element.AddError($"The control <{element.FullTagName}> could not be resolved! Make sure that the tagPrefix is registered in DotvvmConfiguration.Markup.Controls collection!"); } @@ -369,13 +368,11 @@ private IAbstractControl ProcessObjectElement(DothtmlElementNode element, IDataC ProcessAttribute(DotvvmBindableObject.DataContextProperty, dataContextAttribute, control, dataContext); } - IAbstractPropertySetter dataContextProperty; - if (control.TryGetProperty(DotvvmBindableObject.DataContextProperty, out dataContextProperty) && dataContextProperty is IAbstractPropertyBinding) + if (control.TryGetProperty(DotvvmBindableObject.DataContextProperty, out var dataContextProperty) && dataContextProperty is IAbstractPropertyBinding { Binding: var dataContextBinding } ) { - var dataContextBinding = ((IAbstractPropertyBinding)dataContextProperty).Binding; if (dataContextBinding?.ResultType != null) { - dataContext = CreateDataContextTypeStack(dataContextBinding?.ResultType, parentDataContextStack: dataContext); + dataContext = CreateDataContextTypeStack(dataContextBinding.ResultType, parentDataContextStack: dataContext); } else { @@ -412,7 +409,7 @@ public IAbstractBinding ProcessBinding(DothtmlBindingNode node, IDataContextStac if (bindingOptions == null) { node.NameNode.AddError($"Binding {node.Name} could not be resolved."); - bindingOptions = controlResolver.ResolveBinding("value"); // just try it as with value binding + bindingOptions = controlResolver.ResolveBinding("value").NotNull(); // just try it as with value binding } if (context?.NamespaceImports.Count > 0) @@ -900,7 +897,7 @@ protected virtual bool IsControlProperty(IPropertyDescriptor property) var manipulationAttribute = property != null ? property.DataContextManipulationAttribute : control.Metadata.DataContextManipulationAttribute; if (manipulationAttribute != null) { - return manipulationAttribute.ChangeStackForChildren(dataContext, control, property, (parent, changeType) => CreateDataContextTypeStack(changeType, parentDataContextStack: parent)); + return manipulationAttribute.ChangeStackForChildren(dataContext, control, property!, (parent, changeType) => CreateDataContextTypeStack(changeType, parentDataContextStack: parent)); } var attributes = property != null ? property.DataContextChangeAttributes : control.Metadata.DataContextChangeAttributes; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/DataContextStack.cs b/src/DotVVM.Framework/Compilation/ControlTree/DataContextStack.cs index bae74e269b..2f29fbe723 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/DataContextStack.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/DataContextStack.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlResolver.cs b/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlResolver.cs index 2fde3e0bf7..2d95998878 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlResolver.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlResolver.cs @@ -151,7 +151,7 @@ public override IControlResolverMetadata ResolveControl(ITypeDescriptor controlT /// /// Finds the compiled control. /// - protected override IControlType FindCompiledControl(string tagName, string namespaceName, string assemblyName) + protected override IControlType? FindCompiledControl(string tagName, string namespaceName, string assemblyName) { var type = compiledAssemblyCache.FindType(namespaceName + "." + tagName + ", " + assemblyName, ignoreCase: true); if (type == null) @@ -181,7 +181,7 @@ public override IControlResolverMetadata BuildControlMetadata(IControlType type) return new ControlResolverMetadata((ControlType)type); } - protected override IPropertyDescriptor FindGlobalPropertyOrGroup(string name) + protected override IPropertyDescriptor? FindGlobalPropertyOrGroup(string name) { // try to find property var property = DotvvmProperty.ResolveProperty(name, caseSensitive: false); diff --git a/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlTreeResolver.cs b/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlTreeResolver.cs index 461e7cd2bf..63f0d5466d 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlTreeResolver.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/DefaultControlTreeResolver.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/DotvvmPropertyGroup.cs b/src/DotVVM.Framework/Compilation/ControlTree/DotvvmPropertyGroup.cs index 579dd3f872..2a78bcfc29 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/DotvvmPropertyGroup.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/DotvvmPropertyGroup.cs @@ -16,9 +16,9 @@ namespace DotVVM.Framework.Compilation.ControlTree { public class DotvvmPropertyGroup : IPropertyGroupDescriptor { - public PropertyInfo PropertyInfo { get; } + public PropertyInfo? PropertyInfo { get; } - public FieldInfo DescriptorField { get; } + public FieldInfo? DescriptorField { get; } public ICustomAttributeProvider AttributeProvider { get; } @@ -30,9 +30,9 @@ public class DotvvmPropertyGroup : IPropertyGroupDescriptor public DataContextChangeAttribute[] DataContextChangeAttributes { get; } - public DataContextStackManipulationAttribute DataContextManipulationAttribute { get; } + public DataContextStackManipulationAttribute? DataContextManipulationAttribute { get; } - public object DefaultValue { get; } + public object? DefaultValue { get; } public Type DeclaringType { get; } ITypeDescriptor IControlAttributeDescriptor.DeclaringType => new ResolvedTypeDescriptor(DeclaringType); @@ -40,14 +40,14 @@ public class DotvvmPropertyGroup : IPropertyGroupDescriptor public Type PropertyType { get; } ITypeDescriptor IControlAttributeDescriptor.PropertyType => new ResolvedTypeDescriptor(PropertyType); - public Type CollectionType { get; } - ITypeDescriptor IPropertyGroupDescriptor.CollectionType => new ResolvedTypeDescriptor(CollectionType); + public Type? CollectionType { get; } + ITypeDescriptor? IPropertyGroupDescriptor.CollectionType => ResolvedTypeDescriptor.Create(CollectionType); public PropertyGroupMode PropertyGroupMode { get; } private ConcurrentDictionary generatedProperties = new ConcurrentDictionary(); - protected DotvvmPropertyGroup (PropertyInfo propertyInfo, PrefixArray prefixes, Type valueType, object defaultValue) + protected DotvvmPropertyGroup (PropertyInfo propertyInfo, PrefixArray prefixes, Type valueType, object? defaultValue) { this.PropertyInfo = propertyInfo; this.AttributeProvider = propertyInfo; @@ -62,7 +62,7 @@ protected DotvvmPropertyGroup (PropertyInfo propertyInfo, PrefixArray prefixes, (this.MarkupOptions, this.DataContextChangeAttributes, this.DataContextManipulationAttribute) = InitFromAttributes(AttributeProvider, Name); } - internal protected DotvvmPropertyGroup(PrefixArray prefixes, Type valueType, Type declaringType, FieldInfo descriptorField, ICustomAttributeProvider attributeProvider, string name, object defaultValue) + internal protected DotvvmPropertyGroup(PrefixArray prefixes, Type valueType, Type declaringType, FieldInfo descriptorField, ICustomAttributeProvider attributeProvider, string name, object? defaultValue) { this.PropertyInfo = null; this.DescriptorField = descriptorField; @@ -76,7 +76,7 @@ internal protected DotvvmPropertyGroup(PrefixArray prefixes, Type valueType, Typ (this.MarkupOptions, this.DataContextChangeAttributes, this.DataContextManipulationAttribute) = InitFromAttributes(attributeProvider, name); } - private static (MarkupOptionsAttribute, DataContextChangeAttribute[], DataContextStackManipulationAttribute) InitFromAttributes(ICustomAttributeProvider attributeProvider, string name) + private static (MarkupOptionsAttribute, DataContextChangeAttribute[], DataContextStackManipulationAttribute?) InitFromAttributes(ICustomAttributeProvider attributeProvider, string name) { var markupOptions = attributeProvider.GetCustomAttribute(true) ?? new MarkupOptionsAttribute(); var dataContextChange = attributeProvider.GetCustomAttributes(true); @@ -113,7 +113,7 @@ where genArguments[0].IsAssignableFrom(typeof(string)) private static ConcurrentDictionary descriptorDictionary = new ConcurrentDictionary(); - public static DotvvmPropertyGroup Create(PropertyInfo propertyInfo, object defaultValue) + public static DotvvmPropertyGroup Create(PropertyInfo propertyInfo, object? defaultValue) { return descriptorDictionary.GetOrAdd(propertyInfo.DeclaringType.Name + "." + propertyInfo.Name, fullName => { @@ -123,10 +123,10 @@ public static DotvvmPropertyGroup Create(PropertyInfo propertyInfo, object defau }); } - public static DotvvmPropertyGroup Register(PrefixArray prefixes, string name, TValue defaultValue = default(TValue)) => + public static DotvvmPropertyGroup Register(PrefixArray prefixes, string name, TValue? defaultValue = default(TValue)) => Register(typeof(TDeclaring), prefixes, name, typeof(TValue), defaultValue); - public static DotvvmPropertyGroup Register(Type declaringType, PrefixArray prefixes, string name, Type valueType, object defaultValue) + public static DotvvmPropertyGroup Register(Type declaringType, PrefixArray prefixes, string name, Type valueType, object? defaultValue) { return descriptorDictionary.GetOrAdd(declaringType.Name + "." + name, fullName => { @@ -153,7 +153,7 @@ internal static FieldInfo FindDescriptorField(Type declaringType, string name) return field; } - public static DotvvmPropertyGroup Register(Type declaringType, PrefixArray prefixes, string name, Type valueType, ICustomAttributeProvider attributeProvider, object defaultValue) + public static DotvvmPropertyGroup Register(Type declaringType, PrefixArray prefixes, string name, Type valueType, ICustomAttributeProvider attributeProvider, object? defaultValue) { return descriptorDictionary.GetOrAdd(declaringType.Name + "." + name, fullName => { @@ -170,7 +170,7 @@ public static IEnumerable FindAttachedPropertyCandidates(st && pg.DeclaringType.Name == typeName); } - public static IPropertyDescriptor ResolvePropertyGroup(string name, bool caseSensitive) + public static IPropertyDescriptor? ResolvePropertyGroup(string name, bool caseSensitive) { var nameParts = name.Split('.'); var groups = FindAttachedPropertyCandidates(nameParts[0]) diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractBinding.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractBinding.cs index e71560b4eb..cb0c4defe8 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractBinding.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractBinding.cs @@ -11,7 +11,7 @@ public interface IAbstractBinding : IAbstractTreeNode IDataContextStack DataContextTypeStack { get; } - ITypeDescriptor ResultType { get; } + ITypeDescriptor? ResultType { get; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractContentNode.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractContentNode.cs index a7857fce27..9fab17e930 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractContentNode.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractContentNode.cs @@ -9,4 +9,4 @@ public interface IAbstractContentNode : IAbstractTreeNode IControlResolverMetadata Metadata { get; } IDataContextStack DataContextTypeStack { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractControl.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractControl.cs index b53d06281c..5431488b32 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractControl.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractControl.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; namespace DotVVM.Framework.Compilation.ControlTree @@ -8,9 +9,9 @@ public interface IAbstractControl : IAbstractContentNode { IEnumerable PropertyNames { get; } - bool TryGetProperty(IPropertyDescriptor property, out IAbstractPropertySetter value); + bool TryGetProperty(IPropertyDescriptor property, [NotNullWhen(true)] out IAbstractPropertySetter? value); - object[] ConstructorParameters { get; set; } + object[]? ConstructorParameters { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractImportDirective.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractImportDirective.cs index 535b534f4c..867e3c8838 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractImportDirective.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractImportDirective.cs @@ -10,7 +10,7 @@ namespace DotVVM.Framework.Compilation.ControlTree { public interface IAbstractImportDirective : IAbstractDirective { - BindingParserNode AliasSyntax { get; } + BindingParserNode? AliasSyntax { get; } BindingParserNode NameSyntax { get; } bool IsNamespace { get; } diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyControl.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyControl.cs index 48ca483102..aea3ff58f0 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyControl.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyControl.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Compilation.ControlTree { public interface IAbstractPropertyControl : IAbstractPropertySetter diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyValue.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyValue.cs index 4ae064b6b5..8d71dcf11b 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyValue.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractPropertyValue.cs @@ -2,6 +2,6 @@ namespace DotVVM.Framework.Compilation.ControlTree { public interface IAbstractPropertyValue : IAbstractPropertySetter { - object Value { get; } + object? Value { get; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractServiceInjectDirective.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractServiceInjectDirective.cs index 471c750b51..66f518a6ff 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractServiceInjectDirective.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractServiceInjectDirective.cs @@ -12,6 +12,6 @@ public interface IAbstractServiceInjectDirective : IAbstractDirective { SimpleNameBindingParserNode NameSyntax { get; } BindingParserNode TypeSyntax { get; } - ITypeDescriptor Type { get; } + ITypeDescriptor? Type { get; } } } diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeBuilder.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeBuilder.cs index cd6ceda181..817534a4a7 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeBuilder.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeBuilder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeNode.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeNode.cs index 6cf8fa017c..d1587753dc 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeNode.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeNode.cs @@ -1,5 +1,4 @@ -#nullable enable - + using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; namespace DotVVM.Framework.Compilation.ControlTree diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeRoot.cs b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeRoot.cs index f0efd5cf16..fea22d83b3 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeRoot.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IAbstractTreeRoot.cs @@ -1,5 +1,4 @@ -#nullable enable - + using System.Collections.Generic; namespace DotVVM.Framework.Compilation.ControlTree diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IControlResolver.cs b/src/DotVVM.Framework/Compilation/ControlTree/IControlResolver.cs index e62049d02e..8611c7e668 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IControlResolver.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IControlResolver.cs @@ -8,7 +8,7 @@ public interface IControlResolver /// /// Resolves the metadata for specified element. /// - IControlResolverMetadata ResolveControl(string tagPrefix, string tagName, out object[] activationParameters); + IControlResolverMetadata? ResolveControl(string? tagPrefix, string tagName, out object[]? activationParameters); /// /// Resolves the control metadata for specified type. @@ -28,11 +28,11 @@ public interface IControlResolver /// /// Resolves the binding type. /// - BindingParserOptions ResolveBinding(string bindingType); + BindingParserOptions? ResolveBinding(string bindingType); /// /// Finds the property in the control metadata. /// - IPropertyDescriptor FindProperty(IControlResolverMetadata controlMetadata, string name); + IPropertyDescriptor? FindProperty(IControlResolverMetadata controlMetadata, string name); } } diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IControlResolverMetadata.cs b/src/DotVVM.Framework/Compilation/ControlTree/IControlResolverMetadata.cs index c3f641c2d7..979b6d8ad0 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IControlResolverMetadata.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IControlResolverMetadata.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using DotVVM.Framework.Binding; namespace DotVVM.Framework.Compilation.ControlTree @@ -11,15 +12,15 @@ public interface IControlResolverMetadata IEnumerable PropertyNames { get; } - bool TryGetProperty(string name, out IPropertyDescriptor value); + bool TryGetProperty(string name, [NotNullWhen(true)] out IPropertyDescriptor? value); bool IsContentAllowed { get; } - IPropertyDescriptor DefaultContentProperty { get; } + IPropertyDescriptor? DefaultContentProperty { get; } - string VirtualPath { get; } + string? VirtualPath { get; } - ITypeDescriptor DataContextConstraint { get; } + ITypeDescriptor? DataContextConstraint { get; } IEnumerable AllProperties { get; } @@ -29,6 +30,6 @@ public interface IControlResolverMetadata IReadOnlyList PropertyGroups { get; } DataContextChangeAttribute[] DataContextChangeAttributes { get; } - DataContextStackManipulationAttribute DataContextManipulationAttribute { get; } + DataContextStackManipulationAttribute? DataContextManipulationAttribute { get; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IControlTreeResolver.cs b/src/DotVVM.Framework/Compilation/ControlTree/IControlTreeResolver.cs index 73808b11bb..47fd82e94d 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IControlTreeResolver.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IControlTreeResolver.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; +using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; namespace DotVVM.Framework.Compilation.ControlTree { diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IDataContextStack.cs b/src/DotVVM.Framework/Compilation/ControlTree/IDataContextStack.cs index 9d19942fad..a45558b96d 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IDataContextStack.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IDataContextStack.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/IPropertyGroupDescriptor.cs b/src/DotVVM.Framework/Compilation/ControlTree/IPropertyGroupDescriptor.cs index 7b11145937..0876400911 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/IPropertyGroupDescriptor.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/IPropertyGroupDescriptor.cs @@ -10,7 +10,7 @@ namespace DotVVM.Framework.Compilation.ControlTree public interface IPropertyGroupDescriptor: IControlAttributeDescriptor { string[] Prefixes { get; } - ITypeDescriptor CollectionType { get; } + ITypeDescriptor? CollectionType { get; } IPropertyDescriptor GetDotvvmProperty(string name); } } diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ITypeDescriptor.cs b/src/DotVVM.Framework/Compilation/ControlTree/ITypeDescriptor.cs index 001e1d48c4..825dfb7012 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ITypeDescriptor.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ITypeDescriptor.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Controls; namespace DotVVM.Framework.Compilation.ControlTree diff --git a/src/DotVVM.Framework/Compilation/ControlTree/PopDataContextManipulationAttribute.cs b/src/DotVVM.Framework/Compilation/ControlTree/PopDataContextManipulationAttribute.cs index e110be09ae..ea99e77425 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/PopDataContextManipulationAttribute.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/PopDataContextManipulationAttribute.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using DotVVM.Framework.Binding; using DotVVM.Framework.Controls; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.ControlTree { @@ -12,12 +13,12 @@ public class PopDataContextManipulationAttribute : DataContextStackManipulationA { public override IDataContextStack ChangeStackForChildren(IDataContextStack original, IAbstractControl control, IPropertyDescriptor property, Func createNewFrame) { - return original.Parent; + return original.Parent!; } public override DataContextStack ChangeStackForChildren(DataContextStack original, DotvvmBindableObject obj, DotvvmProperty property, Func createNewFrame) { - return original.Parent; + return original.Parent!; } } } diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/IResolvedTreeNode.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/IResolvedTreeNode.cs index 42e7706435..2db1dfd812 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/IResolvedTreeNode.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/IResolvedTreeNode.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Compilation.ControlTree.Resolved { diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedBinding.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedBinding.cs index 35c0a10ede..d7054c36d4 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedBinding.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedBinding.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedContentNode.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedContentNode.cs index ccfa84d105..89afab9df7 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedContentNode.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedContentNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedControl.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedControl.cs index dededaecf6..8e8a4fb644 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedControl.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedControl.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -66,8 +65,8 @@ public bool SetProperty(ResolvedPropertySetter value, bool replace, [NotNullWhen { if (!value.Property.MarkupOptions.AllowValueMerging) error = $"Property '{value.Property}' is already set and it's value can't be merged."; var merger = (IAttributeValueMerger)Activator.CreateInstance(value.Property.MarkupOptions.AttributeValueMerger)!; - var mergedValue = (ResolvedPropertySetter)merger.MergeValues(oldValue, value, out error); - if (error != null) + var mergedValue = (ResolvedPropertySetter?)merger.MergeValues(oldValue, value, out error); + if (error is not null || mergedValue is null) { error = $"Could not merge values using {value.Property.MarkupOptions.AttributeValueMerger.Name}: {error}"; return false; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedDirective.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedDirective.cs index 25cfcf7f5c..85b10cb176 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedDirective.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedDirective.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedImportDirective.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedImportDirective.cs index f6ea9a5454..748854d6b8 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedImportDirective.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedImportDirective.cs @@ -10,19 +10,17 @@ namespace DotVVM.Framework.Compilation.ControlTree.Resolved { public class ResolvedImportDirective : ResolvedDirective, IAbstractImportDirective { - public BindingParserNode AliasSyntax { get; } + public BindingParserNode? AliasSyntax { get; } public BindingParserNode NameSyntax { get; } - public ITextRange NameRange { get; } - - public bool HasError => DothtmlNode.HasNodeErrors; - public Type Type { get; } + public bool HasError => DothtmlNode?.HasNodeErrors == true; + public Type? Type { get; } public bool HasAlias => AliasSyntax != null; public bool IsNamespace => Type == null && !HasError; public bool IsType => Type != null; - public ResolvedImportDirective(BindingParserNode aliasSyntax, BindingParserNode nameSyntax, Type type) + public ResolvedImportDirective(BindingParserNode? aliasSyntax, BindingParserNode nameSyntax, Type? type) { AliasSyntax = aliasSyntax; NameSyntax = nameSyntax; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyControl.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyControl.cs index 865bb88d21..3970852a4e 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyControl.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyControl.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; namespace DotVVM.Framework.Compilation.ControlTree.Resolved diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertySetter.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertySetter.cs index 2750018818..de16de6283 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertySetter.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertySetter.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; namespace DotVVM.Framework.Compilation.ControlTree.Resolved diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyTemplate.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyTemplate.cs index 87da17e0bf..ce2e5b078b 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyTemplate.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyTemplate.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyValue.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyValue.cs index 416d3591cd..6c208eca36 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyValue.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedPropertyValue.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedServiceInjectDirective.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedServiceInjectDirective.cs index 725fe28d51..084712caf8 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedServiceInjectDirective.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedServiceInjectDirective.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeBuilder.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeBuilder.cs index d7cf69a376..ad99314d8d 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeBuilder.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeBuilder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -130,13 +129,13 @@ public IAbstractImportDirective BuildImportDirective( public IAbstractViewModelDirective BuildViewModelDirective(DothtmlDirectiveNode directive, BindingParserNode nameSyntax) { var type = ResolveTypeNameDirective(directive, nameSyntax); - return new ResolvedViewModelDirective(nameSyntax, type) { DothtmlNode = directive }; + return new ResolvedViewModelDirective(nameSyntax, type!) { DothtmlNode = directive }; } public IAbstractBaseTypeDirective BuildBaseTypeDirective(DothtmlDirectiveNode directive, BindingParserNode nameSyntax) { var type = ResolveTypeNameDirective(directive, nameSyntax); - return new ResolvedBaseTypeDirective(nameSyntax, type) { DothtmlNode = directive }; + return new ResolvedBaseTypeDirective(nameSyntax, type!) { DothtmlNode = directive }; } public IAbstractDirective BuildViewModuleDirective(DothtmlDirectiveNode directiveNode, string modulePath, string resourceName) => new ResolvedViewModuleDirective(modulePath, resourceName) { DothtmlNode = directiveNode }; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeNode.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeNode.cs index df6b545fee..c867c324f9 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeNode.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeRoot.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeRoot.cs index 513d1b3d4c..80532bd83a 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeRoot.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTreeRoot.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; @@ -7,6 +6,7 @@ using DotVVM.Framework.Binding; using DotVVM.Framework.Controls; using DotVVM.Framework.ResourceManagement; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.ControlTree.Resolved { @@ -18,6 +18,8 @@ public class ResolvedTreeRoot : ResolvedControl, IAbstractTreeRoot IAbstractControlBuilderDescriptor? IAbstractTreeRoot.MasterPage => MasterPage; + public new DothtmlNode DothtmlNode => base.DothtmlNode.NotNull("View must have a DothtmlNode"); + public ControlBuilderDescriptor ControlBuilderDescriptor => new ControlBuilderDescriptor( DataContextTypeStack.DataContextType, diff --git a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTypeDescriptor.cs b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTypeDescriptor.cs index 030b767e8c..c61c29e624 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTypeDescriptor.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/Resolved/ResolvedTypeDescriptor.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Concurrent; diff --git a/src/DotVVM.Framework/Compilation/ControlTree/ResolvedTreeHelpers.cs b/src/DotVVM.Framework/Compilation/ControlTree/ResolvedTreeHelpers.cs index a75d166a26..825829614d 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/ResolvedTreeHelpers.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/ResolvedTreeHelpers.cs @@ -17,16 +17,16 @@ namespace DotVVM.Framework.Compilation.ControlTree { public static class ResolvedTreeHelpers { - public static ResolvedPropertySetter GetValue(this ResolvedControl control, DotvvmProperty property) => + public static ResolvedPropertySetter? GetValue(this ResolvedControl control, DotvvmProperty property) => control.Properties.TryGetValue(property, out var value) ? value : null; public static Type GetResultType(this ResolvedPropertySetter property) => - property is ResolvedPropertyBinding binding ? ResolvedTypeDescriptor.ToSystemType(binding.Binding.ResultType) : - property is ResolvedPropertyValue value ? value.Value?.GetType() ?? property.Property.PropertyType : - property is ResolvedPropertyControl control ? control.Control.Metadata.Type : - property.Property.PropertyType; + (property is ResolvedPropertyBinding binding ? ResolvedTypeDescriptor.ToSystemType(binding.Binding.ResultType) : + property is ResolvedPropertyValue value ? value.Value?.GetType() : + property is ResolvedPropertyControl control ? control.Control?.Metadata.Type : + null) ?? property.Property.PropertyType; - public static object GetValue(this ResolvedPropertySetter setter) => + public static object? GetValue(this ResolvedPropertySetter setter) => setter switch { ResolvedPropertyValue value => value.Value, ResolvedPropertyTemplate value => value.Content, diff --git a/src/DotVVM.Framework/Compilation/ControlTree/TypeDescriptorUtils.cs b/src/DotVVM.Framework/Compilation/ControlTree/TypeDescriptorUtils.cs index 8f81f49848..47c3ae263a 100644 --- a/src/DotVVM.Framework/Compilation/ControlTree/TypeDescriptorUtils.cs +++ b/src/DotVVM.Framework/Compilation/ControlTree/TypeDescriptorUtils.cs @@ -10,7 +10,7 @@ namespace DotVVM.Framework.Compilation.ControlTree public static class TypeDescriptorUtils { - public static bool IsPrimitiveTypeDescriptor(this ITypeDescriptor type) + public static bool IsPrimitiveTypeDescriptor(this ITypeDescriptor? type) { return type is ResolvedTypeDescriptor resolvedType && ReflectionUtils.IsPrimitiveType(resolvedType.Type); @@ -28,7 +28,7 @@ public static ITypeDescriptor GetCollectionItemType(ITypeDescriptor type) // handle GridViewDataSet if (type.IsAssignableTo(new ResolvedTypeDescriptor(typeof(IBaseGridViewDataSet)))) { - var itemsType = type.TryGetPropertyType(nameof(IBaseGridViewDataSet.Items)); + var itemsType = type.TryGetPropertyType(nameof(IBaseGridViewDataSet.Items)).NotNull(); return itemsType.TryGetArrayElementOrIEnumerableType() ?? throw new Exception("This is strange and should not happen. IBaseGridViewDataSet.Items is not IEnumerable."); } diff --git a/src/DotVVM.Framework/Compilation/ControlType.cs b/src/DotVVM.Framework/Compilation/ControlType.cs index df1d8dcb68..23e9742e63 100644 --- a/src/DotVVM.Framework/Compilation/ControlType.cs +++ b/src/DotVVM.Framework/Compilation/ControlType.cs @@ -8,13 +8,13 @@ public class ControlType : IControlType { public Type Type { get; private set; } - public string VirtualPath { get; private set; } + public string? VirtualPath { get; private set; } - public Type DataContextRequirement { get; private set; } + public Type? DataContextRequirement { get; private set; } ITypeDescriptor IControlType.Type => new ResolvedTypeDescriptor(Type); - ITypeDescriptor IControlType.DataContextRequirement => DataContextRequirement != null ? new ResolvedTypeDescriptor(DataContextRequirement) : null; + ITypeDescriptor? IControlType.DataContextRequirement => ResolvedTypeDescriptor.Create(DataContextRequirement); protected static void ValidateControlClass(Type control) { @@ -25,7 +25,7 @@ protected static void ValidateControlClass(Type control) /// /// Initializes a new instance of the class. /// - public ControlType(Type type, string virtualPath = null, Type dataContextRequirement = null) + public ControlType(Type type, string? virtualPath = null, Type? dataContextRequirement = null) { ValidateControlClass(type); Type = type; diff --git a/src/DotVVM.Framework/Compilation/DefaultAttributeValueMerger.cs b/src/DotVVM.Framework/Compilation/DefaultAttributeValueMerger.cs index 76fde5ad23..1c957ad994 100644 --- a/src/DotVVM.Framework/Compilation/DefaultAttributeValueMerger.cs +++ b/src/DotVVM.Framework/Compilation/DefaultAttributeValueMerger.cs @@ -13,6 +13,7 @@ using System.Linq.Expressions; using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; +using System.Diagnostics.CodeAnalysis; namespace DotVVM.Framework.Compilation { @@ -27,7 +28,7 @@ public class DefaultAttributeValueMerger : IAttributeValueMerger const string MergeValuesMethodName = "MergeValues"; const string MergeExpressionsMethodName = "MergeExpressions"; - public virtual ResolvedPropertySetter MergeValues(ResolvedPropertySetter a, ResolvedPropertySetter b, out string error) + public virtual ResolvedPropertySetter? MergeValues(ResolvedPropertySetter a, ResolvedPropertySetter b, out string? error) { var property = a.Property; @@ -43,10 +44,10 @@ public virtual ResolvedPropertySetter MergeValues(ResolvedPropertySetter a, Reso return new ResolvedPropertyTemplate(property, Enumerable.Concat(firstTemplate.Content, secondTemplate.Content).ToList()); } - ResolvedBinding bindingA; - Expression valA = GetExpression(a, out bindingA); - ResolvedBinding bindingB; - Expression valB = GetExpression(b, out bindingB); + ResolvedBinding? bindingA; + var valA = GetExpression(a, out bindingA); + ResolvedBinding? bindingB; + var valB = GetExpression(b, out bindingB); if (valA == null) { error = $"Could not merge with property type '{a.GetType().Name}"; return null; } if (valB == null) { error = $"Could not merge with property type '{b.GetType().Name}"; return null; } @@ -78,23 +79,23 @@ public virtual ResolvedPropertySetter MergeValues(ResolvedPropertySetter a, Reso } else { - return EmitBinding(resultExpression, property, bindingA ?? bindingB, ref error); + return EmitBinding(resultExpression, property, bindingA ?? bindingB!, ref error); } } - protected virtual ResolvedPropertySetter EmitConstant(object value, DotvvmProperty property, ref string error) + protected virtual ResolvedPropertySetter EmitConstant(object value, DotvvmProperty property, ref string? error) { return new ResolvedPropertyValue(property, value); } - protected virtual ResolvedPropertySetter EmitBinding(Expression expression, DotvvmProperty property, ResolvedBinding originalBinding, ref string error) + protected virtual ResolvedPropertySetter? EmitBinding(Expression expression, DotvvmProperty property, ResolvedBinding originalBinding, ref string? error) { if (originalBinding == null) { error = $"Could not merge constant values to binding '{expression}'."; return null; } return new ResolvedPropertyBinding(property, new ResolvedBinding(originalBinding.BindingService, originalBinding.Binding.GetProperty(), originalBinding.DataContextTypeStack, null, expression, property)) { DothtmlNode = originalBinding.DothtmlNode }; } - protected virtual Expression GetExpression(ResolvedPropertySetter a, out ResolvedBinding binding) + protected virtual Expression? GetExpression(ResolvedPropertySetter a, out ResolvedBinding? binding) { binding = null; if (a is ResolvedPropertyValue) @@ -109,7 +110,7 @@ protected virtual Expression GetExpression(ResolvedPropertySetter a, out Resolve else return null; } - protected virtual object TryOptimizeMethodCall(MethodCallExpression methodCall) + protected virtual object? TryOptimizeMethodCall(MethodCallExpression? methodCall) { if (methodCall != null && methodCall.Arguments.All(a => a.NodeType == ExpressionType.Constant) && (methodCall.Object == null || methodCall.Object.NodeType == ExpressionType.Constant)) return methodCall.Method.Invoke(methodCall.Object.CastTo()?.Value, @@ -117,14 +118,14 @@ protected virtual object TryOptimizeMethodCall(MethodCallExpression methodCall) return null; } - protected virtual MethodCallExpression TryFindMergeMethod(DotvvmProperty property, Expression a, Expression b) + protected virtual MethodCallExpression? TryFindMergeMethod(DotvvmProperty property, Expression a, Expression b) { return TryFindMethod(GetType(), MergeValuesMethodName, Expression.Constant(property), a, b) ?? TryFindMethod(GetType(), MergeValuesMethodName, a, b); } - private static MethodCallExpression TryFindMethod(Type context, string name, params Expression[] parameters) + private static MethodCallExpression? TryFindMethod(Type context, string name, params Expression[] parameters) { var binder = (DynamicMetaObjectBinder)Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember( CSharpBinderFlags.None, name, null, context, diff --git a/src/DotVVM.Framework/Compilation/DefaultControlBuilderFactory.cs b/src/DotVVM.Framework/Compilation/DefaultControlBuilderFactory.cs index 9be6341091..0a222643d1 100644 --- a/src/DotVVM.Framework/Compilation/DefaultControlBuilderFactory.cs +++ b/src/DotVVM.Framework/Compilation/DefaultControlBuilderFactory.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/DefaultViewCompiler.cs b/src/DotVVM.Framework/Compilation/DefaultViewCompiler.cs index ede3108665..93a7231d3a 100644 --- a/src/DotVVM.Framework/Compilation/DefaultViewCompiler.cs +++ b/src/DotVVM.Framework/Compilation/DefaultViewCompiler.cs @@ -65,7 +65,7 @@ public virtual (ControlBuilderDescriptor, Func) CompileView(s foreach (var token in tokenizer.Tokens) { - if (token.HasError && token.Error.IsCritical) + if (token.Error is { IsCritical: true }) { throw new DotvvmCompilationException(token.Error.ErrorMessage, new[] { (token.Error as BeginWithLastTokenOfTypeTokenError)?.LastToken ?? token }); } diff --git a/src/DotVVM.Framework/Compilation/DefaultViewCompilerCodeEmitter.cs b/src/DotVVM.Framework/Compilation/DefaultViewCompilerCodeEmitter.cs index 2ce05c8422..58f9fa2bba 100755 --- a/src/DotVVM.Framework/Compilation/DefaultViewCompilerCodeEmitter.cs +++ b/src/DotVVM.Framework/Compilation/DefaultViewCompilerCodeEmitter.cs @@ -19,6 +19,7 @@ using DotVVM.Framework.Controls; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; +using System.Diagnostics.CodeAnalysis; namespace DotVVM.Framework.Compilation { @@ -45,9 +46,9 @@ private List CurrentStatements private ConcurrentDictionary<(Type obj, string argTypes), string> injectionFactoryCache = new ConcurrentDictionary<(Type obj, string argTypes), string>(); private Stack methods = new Stack(); private List outputMethods = new List(); - public SyntaxTree SyntaxTree { get; private set; } - public ControlBuilderDescriptor Descriptor { get; set; } - public TypeSyntax ResultControlTypeSyntax { get; set; } + public SyntaxTree? SyntaxTree { get; private set; } + public ControlBuilderDescriptor? Descriptor { get; set; } + public TypeSyntax? ResultControlTypeSyntax { get; set; } private ConcurrentDictionary usedAssemblies = new ConcurrentDictionary(); private static int assemblyIdCtr = 0; @@ -56,7 +57,8 @@ public IEnumerable> UsedAssemblies get { return usedAssemblies; } } - public string UseType(Type type) + [return: NotNullIfNotNull("type")] + public string? UseType(Type? type) { if (type == null) return null; UseType(type.BaseType); @@ -82,12 +84,12 @@ public string EmitCreateVariable(ExpressionSyntax expression) return name; } - public ExpressionSyntax EmitValue(object value) => valueEmitter.EmitValue(value); + public ExpressionSyntax EmitValue(object? value) => valueEmitter.EmitValue(value); /// /// Emits the create object expression. /// - public string EmitCreateObject(Type type, object[] constructorArguments = null) + public string EmitCreateObject(Type type, object[]? constructorArguments = null) { if (constructorArguments == null) { @@ -158,7 +160,7 @@ public string EmitInjectionFactoryInvocation( /// /// Emits the create object expression. /// - public string EmitCreateObject(TypeSyntax typeSyntax, object[] constructorArguments = null) + public string EmitCreateObject(TypeSyntax typeSyntax, object[]? constructorArguments = null) { if (constructorArguments == null) { @@ -352,7 +354,7 @@ public ExpressionSyntax CreateDotvvmPropertyIdentifier(DotvvmProperty property) private Dictionary> controlProperties = new Dictionary>(); - public void EmitSetDotvvmProperty(string controlName, DotvvmProperty property, object value) => + public void EmitSetDotvvmProperty(string controlName, DotvvmProperty property, object? value) => EmitSetDotvvmProperty(controlName, property, EmitValue(value)); public void EmitSetDotvvmProperty(string controlName, DotvvmProperty property, ExpressionSyntax value) @@ -396,7 +398,7 @@ public void CommitDotvvmProperties(string name) var (hashSeed, keys, values) = PropertyImmutableHashtable.CreateTableWithValues(properties.Select(p => p.prop).ToArray(), properties.Select(p => p.value).ToArray()); - var invertedValues = new object[values.Length]; + var invertedValues = new object?[values.Length]; var successfulInversion = true; for (int i = 0; i < values.Length; i++) { @@ -445,7 +447,7 @@ public void CommitDotvvmProperties(string name) /// /// Emits the code that adds the specified value as a child item in the collection. /// - public void EmitAddCollectionItem(string controlName, string variableName, string collectionPropertyName = "Children") + public void EmitAddCollectionItem(string controlName, string variableName, string? collectionPropertyName = "Children") { ExpressionSyntax collectionExpression; if (string.IsNullOrEmpty(collectionPropertyName)) @@ -774,7 +776,7 @@ public ParameterSyntax[] EmitControlBuilderParameters() /// public void PushNewMethod(string name, Type returnType, params ParameterSyntax[] parameters) { - var emitterMethodInfo = new EmitterMethodInfo(ParseTypeName(returnType), parameters) { Name = name }; + var emitterMethodInfo = new EmitterMethodInfo(ParseTypeName(returnType), name, parameters); methods.Push(emitterMethodInfo); } diff --git a/src/DotVVM.Framework/Compilation/DotHtmlFileInfo.cs b/src/DotVVM.Framework/Compilation/DotHtmlFileInfo.cs index b95ddeab85..6e74d87c7f 100644 --- a/src/DotVVM.Framework/Compilation/DotHtmlFileInfo.cs +++ b/src/DotVVM.Framework/Compilation/DotHtmlFileInfo.cs @@ -7,21 +7,21 @@ namespace DotVVM.Framework.Compilation public sealed class DotHtmlFileInfo { public CompilationState Status { get; internal set; } - public string Exception { get; internal set; } + public string? Exception { get; internal set; } /// Gets or sets the virtual path to the view. public string VirtualPath { get; } - public string TagName { get; } - public string Namespace { get; } - public string Assembly { get; } - public string TagPrefix { get; } - public string Url { get; } - public string RouteName { get; } + public string? TagName { get; } + public string? Namespace { get; } + public string? Assembly { get; } + public string? TagPrefix { get; } + public string? Url { get; } + public string? RouteName { get; } public ImmutableArray? DefaultValues { get; } public bool? HasParameters { get; } - public DotHtmlFileInfo(string virtualPath, string tagName = null, string nameSpace = null, string assembly = null, string tagPrefix = null, string url = null, string routeName = null, ImmutableArray? defaultValues = null, bool? hasParameters = null) + public DotHtmlFileInfo(string virtualPath, string? tagName = null, string? nameSpace = null, string? assembly = null, string? tagPrefix = null, string? url = null, string? routeName = null, ImmutableArray? defaultValues = null, bool? hasParameters = null) { VirtualPath = virtualPath; Status = !string.IsNullOrWhiteSpace(virtualPath) ? CompilationState.None : CompilationState.NonCompilable; diff --git a/src/DotVVM.Framework/Compilation/DotvvmCompilationException.cs b/src/DotVVM.Framework/Compilation/DotvvmCompilationException.cs index eac065cfda..c1c4fef1ac 100644 --- a/src/DotVVM.Framework/Compilation/DotvvmCompilationException.cs +++ b/src/DotVVM.Framework/Compilation/DotvvmCompilationException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Compilation/DotvvmViewCompilationService.cs b/src/DotVVM.Framework/Compilation/DotvvmViewCompilationService.cs index 8b9822ff2f..054b282d24 100644 --- a/src/DotVVM.Framework/Compilation/DotvvmViewCompilationService.cs +++ b/src/DotVVM.Framework/Compilation/DotvvmViewCompilationService.cs @@ -46,7 +46,7 @@ private ImmutableArray InitControls() { return dotvvmConfiguration.Markup.Controls.Where(s => !string.IsNullOrWhiteSpace(s.Src)) - .Select(s => new DotHtmlFileInfo(s.Src, tagPrefix: s.TagPrefix, tagName: s.TagName, + .Select(s => new DotHtmlFileInfo(s.Src!, tagPrefix: s.TagPrefix, tagName: s.TagName, nameSpace: s.Namespace, assembly: s.Assembly)).ToImmutableArray(); } @@ -82,7 +82,7 @@ public async Task CompileAll(bool buildInParallel = true, bool forceRecomp var exclusiveMode = false; try { - IEnumerable filesToCompile = null; + IEnumerable? filesToCompile = null; if (forceRecompile) { filesToCompile = controls.Value.Union(routes.Value); @@ -142,7 +142,7 @@ private async Task ExecuteCompileTasks(Action[] compileTasks, bool buildInParall } } - public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo masterPage) + public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo? masterPage) { masterPage = null; if (file.Status != CompilationState.NonCompilable) @@ -154,7 +154,7 @@ public bool BuildView(DotHtmlFileInfo file, out DotHtmlFileInfo masterPage) var compiledControl = pageBuilder.builder.Value.BuildControl(controlBuilderFactory, dotvvmConfiguration.ServiceProvider); if (compiledControl is DotvvmView view && - view.Directives.TryGetValue(ParserConstants.MasterPageDirective, out var masterPagePath)) + view.Directives!.TryGetValue(ParserConstants.MasterPageDirective, out var masterPagePath)) { masterPage = masterPages.Value.GetOrAdd(masterPagePath, new DotHtmlFileInfo(masterPagePath)); } diff --git a/src/DotVVM.Framework/Compilation/EmitterMethodInfo.cs b/src/DotVVM.Framework/Compilation/EmitterMethodInfo.cs index 53b441f9f1..3625ccfce3 100644 --- a/src/DotVVM.Framework/Compilation/EmitterMethodInfo.cs +++ b/src/DotVVM.Framework/Compilation/EmitterMethodInfo.cs @@ -15,11 +15,12 @@ public class EmitterMethodInfo public TypeSyntax ReturnType { get; set; } - public EmitterMethodInfo(TypeSyntax returnType, params ParameterSyntax[] parameters) + public EmitterMethodInfo(TypeSyntax returnType, string name, params ParameterSyntax[] parameters) { Parameters = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters)); ReturnType = returnType; + Name = name; Statements = new List(); } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/ErrorCheckingVisitor.cs b/src/DotVVM.Framework/Compilation/ErrorCheckingVisitor.cs index 9fc31e4175..8222978c77 100644 --- a/src/DotVVM.Framework/Compilation/ErrorCheckingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/ErrorCheckingVisitor.cs @@ -2,6 +2,7 @@ using System.Linq; using DotVVM.Framework.Compilation.ControlTree.Resolved; using DotVVM.Framework.Compilation.Parser.Dothtml.Parser; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation { @@ -10,7 +11,7 @@ public class ErrorCheckingVisitor : ResolvedControlTreeVisitor public override void VisitControl(ResolvedControl control) { - if (control.DothtmlNode.HasNodeErrors) + if (control.DothtmlNode is { HasNodeErrors: true }) { throw new DotvvmCompilationException(string.Join("\r\n", control.DothtmlNode.NodeErrors), control.DothtmlNode.Tokens); } @@ -26,7 +27,7 @@ public override void VisitPropertyBinding(ResolvedPropertyBinding propertyBindin throw new DotvvmCompilationException( errors.GetErrorMessage(propertyBinding.Binding.Binding), errors.Exceptions.Count() > 1 ? new AggregateException(errors.Exceptions) : errors.Exceptions.SingleOrDefault(), - propertyBinding.Binding.BindingNode.Tokens); + propertyBinding.Binding.BindingNode?.Tokens); } base.VisitPropertyBinding(propertyBinding); } @@ -47,4 +48,4 @@ public override void VisitView(ResolvedTreeRoot view) base.VisitView(view); } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/GlobalizeResourceVisitor.cs b/src/DotVVM.Framework/Compilation/GlobalizeResourceVisitor.cs index 8250fa8848..13c35106ca 100644 --- a/src/DotVVM.Framework/Compilation/GlobalizeResourceVisitor.cs +++ b/src/DotVVM.Framework/Compilation/GlobalizeResourceVisitor.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Compilation/HtmlAttributeValueMerger.cs b/src/DotVVM.Framework/Compilation/HtmlAttributeValueMerger.cs index 9555f30c2b..c8293a4f63 100644 --- a/src/DotVVM.Framework/Compilation/HtmlAttributeValueMerger.cs +++ b/src/DotVVM.Framework/Compilation/HtmlAttributeValueMerger.cs @@ -22,7 +22,7 @@ public static Expression MergeExpressions(GroupedDotvvmProperty property, Expres // return Expression.Call(typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string), typeof(string) }), a, Expression.Constant(separator), b); } - public static string MergeValues(GroupedDotvvmProperty property, string a, string b) => + public static string? MergeValues(GroupedDotvvmProperty property, string? a, string? b) => HtmlWriter.JoinAttributeValues(property.GroupMemberName, a, b); } } diff --git a/src/DotVVM.Framework/Compilation/IAttributeValueMerger.cs b/src/DotVVM.Framework/Compilation/IAttributeValueMerger.cs index dd219b01ac..edc8cd25a4 100644 --- a/src/DotVVM.Framework/Compilation/IAttributeValueMerger.cs +++ b/src/DotVVM.Framework/Compilation/IAttributeValueMerger.cs @@ -10,6 +10,6 @@ namespace DotVVM.Framework.Compilation { public interface IAttributeValueMerger { - ResolvedPropertySetter MergeValues(ResolvedPropertySetter a, ResolvedPropertySetter b, out string error); + ResolvedPropertySetter? MergeValues(ResolvedPropertySetter a, ResolvedPropertySetter b, out string? error); } } diff --git a/src/DotVVM.Framework/Compilation/IBindingCompiler.cs b/src/DotVVM.Framework/Compilation/IBindingCompiler.cs index 0f6f5204ae..735b3810fb 100644 --- a/src/DotVVM.Framework/Compilation/IBindingCompiler.cs +++ b/src/DotVVM.Framework/Compilation/IBindingCompiler.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using DotVVM.Framework.Compilation.ControlTree.Resolved; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/DotVVM.Framework/Compilation/IBindingExpressionBuilder.cs b/src/DotVVM.Framework/Compilation/IBindingExpressionBuilder.cs index 383ae88694..9f3580caac 100644 --- a/src/DotVVM.Framework/Compilation/IBindingExpressionBuilder.cs +++ b/src/DotVVM.Framework/Compilation/IBindingExpressionBuilder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq.Expressions; diff --git a/src/DotVVM.Framework/Compilation/IControlAttributeDescriptor.cs b/src/DotVVM.Framework/Compilation/IControlAttributeDescriptor.cs index bb37d3602a..e9d5d8dca4 100644 --- a/src/DotVVM.Framework/Compilation/IControlAttributeDescriptor.cs +++ b/src/DotVVM.Framework/Compilation/IControlAttributeDescriptor.cs @@ -11,11 +11,11 @@ namespace DotVVM.Framework.Compilation { public interface IControlAttributeDescriptor { - string Name { get; } + string Name { get; } MarkupOptionsAttribute MarkupOptions { get; } DataContextChangeAttribute[] DataContextChangeAttributes { get; } - DataContextStackManipulationAttribute DataContextManipulationAttribute { get; } + DataContextStackManipulationAttribute? DataContextManipulationAttribute { get; } ITypeDescriptor DeclaringType { get; } ITypeDescriptor PropertyType { get; } } diff --git a/src/DotVVM.Framework/Compilation/IControlBuilder.cs b/src/DotVVM.Framework/Compilation/IControlBuilder.cs index 7a1a63821f..48121c030e 100644 --- a/src/DotVVM.Framework/Compilation/IControlBuilder.cs +++ b/src/DotVVM.Framework/Compilation/IControlBuilder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Immutable; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Compilation/IControlBuilderFactory.cs b/src/DotVVM.Framework/Compilation/IControlBuilderFactory.cs index 8ee7f695d0..049d3b3f82 100644 --- a/src/DotVVM.Framework/Compilation/IControlBuilderFactory.cs +++ b/src/DotVVM.Framework/Compilation/IControlBuilderFactory.cs @@ -1,4 +1,3 @@ -#nullable enable using System; namespace DotVVM.Framework.Compilation diff --git a/src/DotVVM.Framework/Compilation/IControlType.cs b/src/DotVVM.Framework/Compilation/IControlType.cs index 36e7508d66..e7700133d4 100644 --- a/src/DotVVM.Framework/Compilation/IControlType.cs +++ b/src/DotVVM.Framework/Compilation/IControlType.cs @@ -7,9 +7,9 @@ public interface IControlType ITypeDescriptor Type { get; } - string VirtualPath { get; } + string? VirtualPath { get; } - ITypeDescriptor DataContextRequirement { get; } + ITypeDescriptor? DataContextRequirement { get; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/IViewCompiler.cs b/src/DotVVM.Framework/Compilation/IViewCompiler.cs index fd55874be4..26d35886cc 100644 --- a/src/DotVVM.Framework/Compilation/IViewCompiler.cs +++ b/src/DotVVM.Framework/Compilation/IViewCompiler.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Compilation.Parser; using DotVVM.Framework.Runtime; diff --git a/src/DotVVM.Framework/Compilation/Inference/ITypeInferer.cs b/src/DotVVM.Framework/Compilation/Inference/ITypeInferer.cs index 750c8ce3fb..229258d9e7 100644 --- a/src/DotVVM.Framework/Compilation/Inference/ITypeInferer.cs +++ b/src/DotVVM.Framework/Compilation/Inference/ITypeInferer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; diff --git a/src/DotVVM.Framework/Compilation/Inference/Inferers/LambdaInferer.cs b/src/DotVVM.Framework/Compilation/Inference/Inferers/LambdaInferer.cs index 8e1b88cfe3..84dde766ca 100644 --- a/src/DotVVM.Framework/Compilation/Inference/Inferers/LambdaInferer.cs +++ b/src/DotVVM.Framework/Compilation/Inference/Inferers/LambdaInferer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -32,7 +31,7 @@ LambdaTypeInferenceResult IFluentInferer.Lambda(int argsCount) var index = context.CurrentArgumentIndex; // Check if we can match any method candidate - foreach (var candidate in context.Target!.Candidates) + foreach (var candidate in context.Target!.Candidates.NotNull("Invalid context.Target without candidates")) { var parameters = candidate.GetParameters(); if (index >= parameters.Length || parameters.Length > context.Arguments.Length) diff --git a/src/DotVVM.Framework/Compilation/Inference/Results/ITypeInferenceResult.cs b/src/DotVVM.Framework/Compilation/Inference/Results/ITypeInferenceResult.cs index 47b9b65889..18a97d5020 100644 --- a/src/DotVVM.Framework/Compilation/Inference/Results/ITypeInferenceResult.cs +++ b/src/DotVVM.Framework/Compilation/Inference/Results/ITypeInferenceResult.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Compilation/Inference/Results/LambdaTypeInferenceResult.cs b/src/DotVVM.Framework/Compilation/Inference/Results/LambdaTypeInferenceResult.cs index 1ba055f47e..60e5617a82 100644 --- a/src/DotVVM.Framework/Compilation/Inference/Results/LambdaTypeInferenceResult.cs +++ b/src/DotVVM.Framework/Compilation/Inference/Results/LambdaTypeInferenceResult.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Compilation/Inference/TypeInferer.cs b/src/DotVVM.Framework/Compilation/Inference/TypeInferer.cs index 6c7ab43817..190bff45cd 100644 --- a/src/DotVVM.Framework/Compilation/Inference/TypeInferer.cs +++ b/src/DotVVM.Framework/Compilation/Inference/TypeInferer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/IAnnotatable.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/IAnnotatable.cs index 5b7889eb90..ec41692161 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/IAnnotatable.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/IAnnotatable.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Text; @@ -27,7 +28,7 @@ public interface IAnnotatable /// /// The type of the annotation. /// - T Annotation() where T : class; + T? Annotation() where T : class; /// /// Gets the first annotation of the specified type. @@ -36,7 +37,7 @@ public interface IAnnotatable /// /// The type of the annotation. /// - object Annotation(Type type); + object? Annotation(Type type); /// /// Adds an annotation to this instance. @@ -73,7 +74,7 @@ public abstract class AbstractAnnotatable : IAnnotatable // or to an AnnotationList. // Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list) - object annotations; + object? annotations; /// /// Clones all annotations. @@ -119,7 +120,7 @@ public virtual T AddAnnotation(T annotation) { return annotation; // we successfully added a single annotation } - AnnotationList list = oldAnnotation as AnnotationList; + AnnotationList? list = oldAnnotation as AnnotationList; if (list == null) { // we need to transform the old annotation into a list @@ -146,7 +147,7 @@ public virtual T AddAnnotation(T annotation) public virtual void RemoveAnnotations() where T : class { retry: // Retry until successful - object oldAnnotations = this.annotations; + var oldAnnotations = this.annotations; if (oldAnnotations is AnnotationList list) { lock (list) @@ -167,7 +168,7 @@ public virtual void RemoveAnnotations(Type type) if (type == null) throw new ArgumentNullException("type"); retry: // Retry until successful - object oldAnnotations = this.annotations; + var oldAnnotations = this.annotations; if (oldAnnotations is AnnotationList list) { lock (list) @@ -183,9 +184,9 @@ public virtual void RemoveAnnotations(Type type) } } - public T Annotation() where T : class + public T? Annotation() where T : class { - object annotations = this.annotations; + var annotations = this.annotations; if (annotations is AnnotationList list) { lock (list) @@ -204,11 +205,11 @@ public T Annotation() where T : class } } - public object Annotation(Type type) + public object? Annotation(Type type) { if (type == null) throw new ArgumentNullException("type"); - object annotations = this.annotations; + var annotations = this.annotations; if (annotations is AnnotationList list) { lock (list) @@ -235,7 +236,7 @@ public IEnumerable Annotations { get { - object annotations = this.annotations; + var annotations = this.annotations; if (annotations is AnnotationList list) { lock (list) @@ -256,7 +257,7 @@ public IEnumerable Annotations public static class AnnotatableUtils { - public static T WithAnnotation(this T node, object annotation, bool append = true) + public static T WithAnnotation(this T node, object? annotation, bool append = true) where T : class, IAnnotatable { if (annotation != null && (append || !node.HasAnnotation())) node.AddAnnotation(annotation); @@ -271,7 +272,7 @@ public static TNode WithoutAnnotation(this TNode node) return node; } - public static T WithAnnotations(this T node, IEnumerable annotations) + public static T WithAnnotations(this T node, IEnumerable annotations) where T : class, IAnnotatable { foreach (var annotation in annotations) if (annotation != null) node.AddAnnotation(annotation); @@ -282,7 +283,7 @@ public static bool HasAnnotation(this IAnnotatable node) where T : class => node.Annotation() != null; - public static bool TryGetAnnotation(this IAnnotatable node, out T annotation) + public static bool TryGetAnnotation(this IAnnotatable node, [NotNullWhen(true)] out T? annotation) where T : class => (annotation = node.Annotation()) != null; diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsArrowFunctionExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsArrowFunctionExpression.cs index e04f9034ff..3dc3444192 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsArrowFunctionExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsArrowFunctionExpression.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.Javascript.Ast { public class JsArrowFunctionExpression: JsBaseFunctionExpression { - public JsExpression ExpressionBody + public JsExpression? ExpressionBody { get { if (Block.Body.Count == 1 && @@ -17,7 +18,7 @@ public JsExpression ExpressionBody else return null; } - set { Block = value.Return().AsBlock(); } + set { Block = value.NotNull().Return().AsBlock(); } } @@ -33,9 +34,9 @@ public JsArrowFunctionExpression(IEnumerable parameters, JsExpress public override void AcceptVisitor(IJsNodeVisitor visitor) => visitor.VisitArrowFunctionExpression(this); - public static JsExpression CreateIIFE(JsExpression expression, IEnumerable<(string name, JsExpression initExpression)> parameters = null, bool isAsync = false) => + public static JsExpression CreateIIFE(JsExpression expression, IEnumerable<(string name, JsExpression initExpression)>? parameters = null, bool isAsync = false) => CreateIIFE(expression.Return().AsBlock(), parameters, isAsync); - public static JsExpression CreateIIFE(JsBlockStatement block, IEnumerable<(string name, JsExpression initExpression)> parameters = null, bool isAsync = false) + public static JsExpression CreateIIFE(JsBlockStatement block, IEnumerable<(string name, JsExpression initExpression)>? parameters = null, bool isAsync = false) { if (parameters == null) parameters = Enumerable.Empty<(string, JsExpression)>(); return new JsArrowFunctionExpression( diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAssignmentExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAssignmentExpression.cs index 80778945c9..ed23026084 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAssignmentExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAssignmentExpression.cs @@ -21,13 +21,13 @@ public BinaryOperatorType? Operator public JsExpression Left { - get { return GetChildByRole(LeftRole); } + get { return GetChildByRole(LeftRole)!; } set { SetChildByRole(LeftRole, value); } } public JsExpression Right { - get { return GetChildByRole(RightRole); } + get { return GetChildByRole(RightRole)!; } set { SetChildByRole(RightRole, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAstHelpers.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAstHelpers.cs index a617c38fcf..f2497621c7 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAstHelpers.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsAstHelpers.cs @@ -49,10 +49,11 @@ public static ParametrizedCode FormatParametrizedScript(this JsNode node, bool n { if (node is null) throw new ArgumentNullException(nameof(node)); - node.FixParenthesis(); + node = node.FixParenthesis(); var visitor = new JsFormattingVisitor(niceMode, indent); node.AcceptVisitor(visitor); - return visitor.GetResult(JsParensFixingVisitor.GetOperatorPrecedence(node as JsExpression)); + var precedence = node is JsExpression expr ? JsParensFixingVisitor.GetOperatorPrecedence(expr) : OperatorPrecedence.Max; + return visitor.GetResult(precedence); } public static JsNode FixParenthesis(this JsNode node) @@ -103,7 +104,7 @@ public static TNewNode ReplaceWith(this TNode node, Func(this TNode node, Func(this TNode node) return (TNode)node.CloneImpl(); } - public static JsNode AssignParameters(this JsNode node, Func parameterAssignment) + public static JsNode AssignParameters(this JsNode node, Func parameterAssignment) { foreach (var sp in node.Descendants.OfType()) { @@ -157,12 +158,12 @@ public static JsNode AssignParameters(this JsNode node, Func + var newDefault = defaultAssignment.AssignParameters(p => parameterAssignment(p)?.FormatParametrizedScript() ); - if (newDefault != defaultAssignment.Code) + if (newDefault != defaultAssignment) sp.DefaultAssignment = new CodeParameterAssignment(newDefault); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBaseFunctionExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBaseFunctionExpression.cs index c12402bf18..a5c994b21d 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBaseFunctionExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBaseFunctionExpression.cs @@ -20,7 +20,7 @@ public bool IsAsync public static JsTreeRole BlockRole = new JsTreeRole("Block"); public JsBlockStatement Block { - get => GetChildByRole(BlockRole); + get => GetChildByRole(BlockRole)!; set => SetChildByRole(BlockRole, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBinaryExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBinaryExpression.cs index f64bddcd93..d1e7d6700b 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBinaryExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsBinaryExpression.cs @@ -22,13 +22,13 @@ public BinaryOperatorType Operator public JsExpression Left { - get { return GetChildByRole(LeftRole); } + get { return GetChildByRole(LeftRole)!; } set { SetChildByRole(LeftRole, value); } } public JsExpression Right { - get { return GetChildByRole(RightRole); } + get { return GetChildByRole(RightRole)!; } set { SetChildByRole(RightRole, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsConditionalExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsConditionalExpression.cs index bb110fbb52..dcb040f356 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsConditionalExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsConditionalExpression.cs @@ -11,18 +11,18 @@ public class JsConditionalExpression: JsExpression public readonly static JsTreeRole FalseRole = new JsTreeRole("False"); public JsExpression Condition { - get { return GetChildByRole(JsTreeRoles.Condition); } + get { return GetChildByRole(JsTreeRoles.Condition)!; } set { SetChildByRole(JsTreeRoles.Condition, value); } } public JsExpression TrueExpression { - get { return GetChildByRole(TrueRole); } + get { return GetChildByRole(TrueRole)!; } set { SetChildByRole(TrueRole, value); } } public JsExpression FalseExpression { - get { return GetChildByRole(FalseRole); } + get { return GetChildByRole(FalseRole)!; } set { SetChildByRole(FalseRole, value); } } public JsConditionalExpression() diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsExpressionStatement.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsExpressionStatement.cs index 84c989b04d..a86e915b3a 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsExpressionStatement.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsExpressionStatement.cs @@ -8,7 +8,7 @@ public class JsExpressionStatement : JsStatement { public JsExpression Expression { - get { return GetChildByRole(JsTreeRoles.Expression); } + get { return GetChildByRole(JsTreeRoles.Expression)!; } set { SetChildByRole(JsTreeRoles.Expression, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsFunctionExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsFunctionExpression.cs index 9160c00f33..6207bf06d7 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsFunctionExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsFunctionExpression.cs @@ -7,19 +7,19 @@ namespace DotVVM.Framework.Compilation.Javascript.Ast { public class JsFunctionExpression: JsBaseFunctionExpression { - public JsIdentifier Identifier + public JsIdentifier? Identifier { get => GetChildByRole(JsTreeRoles.Identifier); set => SetChildByRole(JsTreeRoles.Identifier, value); } - public string IdentifierName + public string? IdentifierName { get => Identifier?.Name; set => Identifier = new JsIdentifier(value); } - public JsFunctionExpression(IEnumerable parameters, JsBlockStatement bodyBlock, JsIdentifier name = null, bool isAsync = false) + public JsFunctionExpression(IEnumerable parameters, JsBlockStatement bodyBlock, JsIdentifier? name = null, bool isAsync = false) { if (name != null) AddChild(name, JsTreeRoles.Identifier); foreach (var p in parameters) AddChild(p, ParametersRole); diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifier.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifier.cs index 1774d29a6a..95351f40d2 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifier.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifier.cs @@ -27,9 +27,9 @@ public bool IsValidName() return true; } - public JsIdentifier(string name = "") + public JsIdentifier(string? name = "") { - Name = name; + this.name = name ?? ""; } public override void AcceptVisitor(IJsNodeVisitor visitor) => visitor.VisitIdentifier(this); diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifierExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifierExpression.cs index 51d93dec80..08df76221f 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifierExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIdentifierExpression.cs @@ -8,13 +8,13 @@ public class JsIdentifierExpression: JsExpression { public string Identifier { - get => GetChildByRole(JsTreeRoles.Identifier).Name; - set => SetChildByRole(JsTreeRoles.Identifier, new JsIdentifier(value)); + get => IdentifierToken.Name; + set => IdentifierToken = new JsIdentifier(value); } public JsIdentifier IdentifierToken { - get => GetChildByRole(JsTreeRoles.Identifier); + get => GetChildByRole(JsTreeRoles.Identifier)!; set => SetChildByRole(JsTreeRoles.Identifier, value); } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIfStatement.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIfStatement.cs index 60aea66a83..5d1f6226f9 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIfStatement.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIfStatement.cs @@ -8,23 +8,23 @@ public class JsIfStatement: JsStatement { public JsExpression Condition { - get => GetChildByRole(JsTreeRoles.Condition); + get => GetChildByRole(JsTreeRoles.Condition)!; set => SetChildByRole(JsTreeRoles.Condition, value); } public static JsTreeRole TrueBranchRole = new JsTreeRole("TrueBranch"); public JsStatement TrueBranch { - get => GetChildByRole(TrueBranchRole); + get => GetChildByRole(TrueBranchRole)!; set => SetChildByRole(TrueBranchRole, value); } public static JsTreeRole FalseBranchRole = new JsTreeRole("FalseBranch"); - public JsStatement FalseBranch + public JsStatement? FalseBranch { get => GetChildByRole(FalseBranchRole); set => SetChildByRole(FalseBranchRole, value); } - public JsIfStatement(JsExpression condition, JsStatement trueBranch, JsStatement falseBranch = null) + public JsIfStatement(JsExpression condition, JsStatement trueBranch, JsStatement? falseBranch = null) { this.Condition = condition; this.TrueBranch = trueBranch; diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIndexerExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIndexerExpression.cs index 3f18676b24..d45b3eb81a 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIndexerExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsIndexerExpression.cs @@ -8,13 +8,13 @@ public class JsIndexerExpression: JsExpression { public JsExpression Target { - get => GetChildByRole(JsTreeRoles.TargetExpression); + get => GetChildByRole(JsTreeRoles.TargetExpression)!; set => SetChildByRole(JsTreeRoles.TargetExpression, value); } public JsExpression Argument { - get => GetChildByRole(JsTreeRoles.Argument); + get => GetChildByRole(JsTreeRoles.Argument)!; set => SetChildByRole(JsTreeRoles.Argument, value); } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsInvocationExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsInvocationExpression.cs index 889f05cc81..34860da166 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsInvocationExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsInvocationExpression.cs @@ -8,7 +8,7 @@ public class JsInvocationExpression : JsExpression { public JsExpression Target { - get { return GetChildByRole(JsTreeRoles.TargetExpression); } + get { return GetChildByRole(JsTreeRoles.TargetExpression)!; } set { SetChildByRole(JsTreeRoles.TargetExpression, value); } } public JsNodeCollection Arguments diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsLiteral.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsLiteral.cs index 6fb2eea71b..c8292f6c20 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsLiteral.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsLiteral.cs @@ -8,9 +8,9 @@ namespace DotVVM.Framework.Compilation.Javascript.Ast { public class JsLiteral : JsExpression { - private object value; + private object? value; - public object Value + public object? Value { get { return value; } set { ThrowIfFrozen(); this.value = value; } @@ -26,7 +26,7 @@ public string LiteralValue } public JsLiteral() { } - public JsLiteral(object value) + public JsLiteral(object? value) { this.Value = value; } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsMemberAccessExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsMemberAccessExpression.cs index dec43128df..9547714761 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsMemberAccessExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsMemberAccessExpression.cs @@ -8,19 +8,19 @@ public class JsMemberAccessExpression : JsExpression { public JsExpression Target { - get => GetChildByRole(JsTreeRoles.TargetExpression); + get => GetChildByRole(JsTreeRoles.TargetExpression)!; set => SetChildByRole(JsTreeRoles.TargetExpression, value); } public string MemberName { - get => GetChildByRole(JsTreeRoles.Identifier).Name; - set => SetChildByRole(JsTreeRoles.Identifier, new JsIdentifier(value)); + get => MemberNameToken.Name; + set => MemberNameToken = new JsIdentifier(value); } public JsIdentifier MemberNameToken { - get => GetChildByRole(JsTreeRoles.Identifier); + get => GetChildByRole(JsTreeRoles.Identifier)!; set => SetChildByRole(JsTreeRoles.Identifier, value); } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNewExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNewExpression.cs index af890e9fa0..44f6466874 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNewExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNewExpression.cs @@ -8,7 +8,7 @@ public class JsNewExpression: JsExpression { public JsExpression Target { - get { return GetChildByRole(JsTreeRoles.TargetExpression); } + get { return GetChildByRole(JsTreeRoles.TargetExpression)!; } set { SetChildByRole(JsTreeRoles.TargetExpression, value); } } public JsNodeCollection Arguments diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNode.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNode.cs index 1d6340f0f5..4d9876b4ce 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNode.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNode.cs @@ -25,31 +25,31 @@ public void Freeze() child.Freeze(); } - JsNode firstChild; - JsNode lastChild; - JsNode parent; - JsNode prevSibling; - JsNode nextSibling; - - private JsTreeRole role; - public JsTreeRole Role + JsNode? firstChild; + JsNode? lastChild; + JsNode? parent; + JsNode? prevSibling; + JsNode? nextSibling; + + private JsTreeRole? role; + public JsTreeRole? Role { get { return role; } set { role = value; } } - public JsNode Parent => parent; - public JsNode NextSibling => nextSibling; - public JsNode PrevSibling => prevSibling; - public JsNode FirstChild => firstChild; - public JsNode LastChild => lastChild; + public JsNode? Parent => parent; + public JsNode? NextSibling => nextSibling; + public JsNode? PrevSibling => prevSibling; + public JsNode? FirstChild => firstChild; + public JsNode? LastChild => lastChild; public bool HasChildren => firstChild != null; public IEnumerable Children { get { - JsNode next; - for (JsNode cur = firstChild; cur != null; cur = next) { + JsNode? next; + for (var cur = firstChild; cur != null; cur = next) { Debug.Assert(cur.parent == this); // Remember next before yielding cur. // This allows removing/replacing nodes while iterating through the list. @@ -65,7 +65,7 @@ public IEnumerable Children public IEnumerable Ancestors { get { - for (JsNode cur = parent; cur != null; cur = cur.parent) { + for (JsNode? cur = parent; cur != null; cur = cur.parent) { yield return cur; } } @@ -77,7 +77,7 @@ public IEnumerable Ancestors public IEnumerable AncestorsAndSelf { get { - for (JsNode cur = this; cur != null; cur = cur.parent) { + for (JsNode? cur = this; cur != null; cur = cur.parent) { yield return cur; } } @@ -94,17 +94,17 @@ public IEnumerable AncestorsAndSelf /// public IEnumerable DescendantsAndSelf => GetDescendantsImpl(true); - public IEnumerable DescendantNodes(Func descendIntoChildren = null) + public IEnumerable DescendantNodes(Func? descendIntoChildren = null) { return GetDescendantsImpl(false, descendIntoChildren); } - public IEnumerable DescendantNodesAndSelf(Func descendIntoChildren = null) + public IEnumerable DescendantNodesAndSelf(Func? descendIntoChildren = null) { return GetDescendantsImpl(true, descendIntoChildren); } - IEnumerable GetDescendantsImpl(bool includeSelf, Func descendIntoChildren = null) + IEnumerable GetDescendantsImpl(bool includeSelf, Func? descendIntoChildren = null) { if (includeSelf) { yield return this; @@ -112,7 +112,7 @@ IEnumerable GetDescendantsImpl(bool includeSelf, Func desc yield break; } - Stack nextStack = new Stack(); + var nextStack = new Stack(); nextStack.Push(null); var pos = firstChild; while (pos != null) { @@ -132,7 +132,7 @@ IEnumerable GetDescendantsImpl(bool includeSelf, Func desc /// Gets the first child with the specified role. /// Returns the role's null object if the child is not found. /// - public T GetChildByRole(JsTreeRole role) where T : JsNode + public T? GetChildByRole(JsTreeRole role) where T : JsNode { if (role == null) throw new ArgumentNullException("role"); @@ -148,7 +148,7 @@ public JsNodeCollection GetChildrenByRole(JsTreeRole role) where T : Js return new JsNodeCollection(this, role); } - protected void SetChildByRole(JsTreeRole role, T newChild) where T : JsNode + protected void SetChildByRole(JsTreeRole role, T? newChild) where T : JsNode { if (GetChildByRole(role) is T oldChild) oldChild.ReplaceWith(newChild); @@ -156,7 +156,7 @@ protected void SetChildByRole(JsTreeRole role, T newChild) where T : JsNod AddChild(newChild, role); } - public void AddChild(T child, JsTreeRole role) where T : JsNode + public void AddChild(T? child, JsTreeRole role) where T : JsNode { if (role == null) throw new ArgumentNullException("role"); if (child == null) @@ -168,7 +168,7 @@ public void AddChild(T child, JsTreeRole role) where T : JsNode AddChildUnsafe(child, role); } - public void AddChildWithExistingRole(JsNode child) + public void AddChildWithExistingRole(JsNode? child) { if (child == null) return; @@ -185,20 +185,20 @@ public void AddChildWithExistingRole(JsNode child) /// /// Adds a child without performing any safety checks. /// - internal void AddChildUnsafe(JsNode child, JsTreeRole role) + internal void AddChildUnsafe(JsNode child, JsTreeRole? role) { child.parent = this; child.role = role; if (firstChild == null) { lastChild = firstChild = child; } else { - lastChild.nextSibling = child; + lastChild!.nextSibling = child; child.prevSibling = lastChild; lastChild = child; } } - public void InsertChildBefore(JsNode nextSibling, T child, JsTreeRole role) where T : JsNode + public void InsertChildBefore(JsNode? nextSibling, T child, JsTreeRole role) where T : JsNode { if (role == null) throw new ArgumentNullException("role"); @@ -238,7 +238,7 @@ internal void InsertChildBeforeUnsafe(JsNode nextSibling, JsNode child, JsTreeRo nextSibling.prevSibling = child; } - public void InsertChildAfter(JsNode prevSibling, T child, JsTreeRole role) where T : JsNode + public void InsertChildAfter(JsNode? prevSibling, T child, JsTreeRole role) where T : JsNode { InsertChildBefore(prevSibling == null ? firstChild : prevSibling.nextSibling, child, role); } @@ -274,7 +274,7 @@ public JsNode Remove() /// /// Replaces this node with the new node. /// - public void ReplaceWith(JsNode newNode) + public void ReplaceWith(JsNode? newNode) { if (newNode == null) { Remove(); @@ -287,7 +287,7 @@ public void ReplaceWith(JsNode newNode) ThrowIfFrozen(); // Because this method doesn't statically check the new node's type with the role, // we perform a runtime test: - if (!this.Role.IsValid(newNode)) { + if (!this.Role!.IsValid(newNode)) { throw new ArgumentException($"The new node '{newNode.GetType().Name}' is not valid in the role {this.Role.ToString()}", "newNode"); } if (newNode.parent != null) { @@ -339,7 +339,7 @@ internal JsNode CloneImpl() copy.isFrozen = false; // Then perform a deep copy: - for (JsNode cur = firstChild; cur != null; cur = cur.nextSibling) { + for (JsNode? cur = firstChild; cur != null; cur = cur.nextSibling) { copy.AddChildUnsafe(cur.CloneImpl(), cur.Role); } @@ -351,7 +351,7 @@ internal JsNode CloneImpl() public abstract void AcceptVisitor(IJsNodeVisitor visitor); - public JsNode GetNextNode() + public JsNode? GetNextNode() { if (NextSibling != null) return NextSibling; @@ -365,7 +365,7 @@ public JsNode GetNextNode() /// /// The next node. /// The predicate. - public JsNode GetNextNode(Func pred) + public JsNode? GetNextNode(Func pred) { var next = GetNextNode(); while (next != null && !pred(next)) @@ -373,7 +373,7 @@ public JsNode GetNextNode(Func pred) return next; } - public JsNode GetPrevNode() + public JsNode? GetPrevNode() { if (PrevSibling != null) return PrevSibling; @@ -387,7 +387,7 @@ public JsNode GetPrevNode() /// /// The next node. /// The predicate. - public JsNode GetPrevNode(Func pred) + public JsNode? GetPrevNode(Func pred) { var prev = GetPrevNode(); while (prev != null && !pred(prev)) @@ -400,7 +400,7 @@ public JsNode GetPrevNode(Func pred) /// /// The next node. /// The predicate. - public JsNode GetNextSibling(Func pred) + public JsNode? GetNextSibling(Func pred) { var next = NextSibling; while (next != null && !pred(next)) @@ -413,7 +413,7 @@ public JsNode GetNextSibling(Func pred) /// /// The next node. /// The predicate. - public JsNode GetPrevSibling(Func pred) + public JsNode? GetPrevSibling(Func pred) { var prev = PrevSibling; while (prev != null && !pred(prev)) diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNodeCollection.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNodeCollection.cs index cb41a71b20..e727fe5705 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNodeCollection.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsNodeCollection.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; @@ -32,7 +33,7 @@ public JsNodeCollection(JsNode node, JsTreeRole role) public int Count { get { int count = 0; - for (JsNode cur = node.FirstChild; cur != null; cur = cur.NextSibling) { + for (var cur = node.FirstChild; cur != null; cur = cur.NextSibling) { if (cur.Role == role) count++; } @@ -40,31 +41,31 @@ public int Count { } } - public void Add(T element) + public void Add(T? element) { node.AddChild(element, role); } - public void AddRange(IEnumerable nodes) + public void AddRange(IEnumerable nodes) { // Evaluate 'nodes' first, since it might change when we add the new children // Example: collection.AddRange(collection); if (nodes != null) { - foreach (T node in nodes.ToList()) + foreach (T? node in nodes.ToList()) Add(node); } } - public void AddRange(T[] nodes) + public void AddRange(T?[] nodes) { // Fast overload for arrays - we don't need to create a copy if (nodes != null) { - foreach (T node in nodes) + foreach (T? node in nodes) Add(node); } } - public void ReplaceWith(IEnumerable nodes) + public void ReplaceWith(IEnumerable? nodes) { // Evaluate 'nodes' first, since it might change when we call Clear() // Example: collection.ReplaceWith(collection); @@ -72,7 +73,7 @@ public void ReplaceWith(IEnumerable nodes) nodes = nodes.ToList(); Clear(); if (nodes != null) { - foreach (T node in nodes) + foreach (T? node in nodes) Add(node); } } @@ -87,12 +88,12 @@ public void MoveTo(ICollection targetCollection) } } - public bool Contains(T element) + public bool Contains([NotNullWhen(true)] T? element) { return element != null && element.Parent == node && element.Role == role; } - public bool Remove(T element) + public bool Remove(T? element) { if (Contains(element)) { element.Remove(); @@ -118,7 +119,7 @@ public void Clear() /// Returns the first element for which the predicate returns true, /// or the null node (JsNode with IsNull=true) if no such object is found. /// - public T FirstOrNullObject(Func predicate = null) + public T? FirstOrNullObject(Func? predicate = null) { foreach (T item in this) if (predicate == null || predicate(item)) @@ -130,9 +131,9 @@ public T FirstOrNullObject(Func predicate = null) /// Returns the last element for which the predicate returns true, /// or the null node (JsNode with IsNull=true) if no such object is found. /// - public T LastOrNullObject(Func predicate = null) + public T? LastOrNullObject(Func? predicate = null) { - T result = null; + T? result = null; foreach (T item in this) if (predicate == null || predicate(item)) result = item; @@ -145,8 +146,8 @@ bool ICollection.IsReadOnly { public IEnumerator GetEnumerator() { - JsNode next; - for (JsNode cur = node.FirstChild; cur != null; cur = next) { + JsNode? next; + for (var cur = node.FirstChild; cur != null; cur = next) { Debug.Assert(cur.Parent == node); // Remember next before yielding cur. // This allows removing/replacing nodes while iterating through the list. @@ -167,21 +168,21 @@ public override int GetHashCode() return node.GetHashCode() ^ role.GetHashCode(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { - JsNodeCollection other = obj as JsNodeCollection; + var other = obj as JsNodeCollection; if (other == null) return false; return this.node == other.node && this.role == other.role; } #endregion - public void InsertAfter(T existingItem, T newItem) + public void InsertAfter(T? existingItem, T newItem) { node.InsertChildAfter(existingItem, newItem, role); } - public void InsertBefore(T existingItem, T newItem) + public void InsertBefore(T? existingItem, T newItem) { node.InsertChildBefore(existingItem, newItem, role); } @@ -191,8 +192,8 @@ public void InsertBefore(T existingItem, T newItem) /// public void AcceptVisitor(IJsNodeVisitor visitor) { - JsNode next; - for (JsNode cur = node.FirstChild; cur != null; cur = next) { + JsNode? next; + for (var cur = node.FirstChild; cur != null; cur = next) { Debug.Assert(cur.Parent == node); // Remember next before yielding cur. // This allows removing/replacing nodes while iterating through the list. diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsObjectExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsObjectExpression.cs index 4120e01e15..08180f1df5 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsObjectExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsObjectExpression.cs @@ -25,18 +25,18 @@ public class JsObjectProperty: JsNode { public JsIdentifier Identifier { - get => GetChildByRole(JsTreeRoles.Identifier); + get => GetChildByRole(JsTreeRoles.Identifier)!; set => SetChildByRole(JsTreeRoles.Identifier, value); } public string Name { - get => GetChildByRole(JsTreeRoles.Identifier).Name; - set => SetChildByRole(JsTreeRoles.Identifier, new JsIdentifier(value)); + get => Identifier.Name; + set => Identifier = new JsIdentifier(value); } public JsExpression Expression { - get => GetChildByRole(JsTreeRoles.Expression); + get => GetChildByRole(JsTreeRoles.Expression)!; set => SetChildByRole(JsTreeRoles.Expression, value); } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsParenthisedExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsParenthisedExpression.cs index cdce02924e..158df5d1e3 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsParenthisedExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsParenthisedExpression.cs @@ -8,7 +8,7 @@ public class JsParenthesizedExpression : JsExpression { public JsExpression Expression { - get { return GetChildByRole(JsTreeRoles.Expression); } + get { return GetChildByRole(JsTreeRoles.Expression)!; } set { SetChildByRole(JsTreeRoles.Expression, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsReturnStatement.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsReturnStatement.cs index 37bdcec766..40ed8dda15 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsReturnStatement.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsReturnStatement.cs @@ -8,7 +8,7 @@ public class JsReturnStatement : JsStatement { public JsExpression Expression { - get { return GetChildByRole(JsTreeRoles.Expression); } + get { return GetChildByRole(JsTreeRoles.Expression)!; } set { SetChildByRole(JsTreeRoles.Expression, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsSymbolicParameter.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsSymbolicParameter.cs index fa8af3aa04..9d5a3cb66a 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsSymbolicParameter.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsSymbolicParameter.cs @@ -34,7 +34,7 @@ public IEnumerable EnumerateAllSymbols() { yield return Symbol; if (GetDefaultAssignment() is CodeParameterAssignment d) - foreach (var inDefault in d.Code.EnumerateAllParameters()) + foreach (var inDefault in d.Code!.EnumerateAllParameters()) yield return inDefault; } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsUnaryExpression.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsUnaryExpression.cs index b9d827c6b9..4c3a032c7f 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsUnaryExpression.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsUnaryExpression.cs @@ -9,7 +9,7 @@ public class JsUnaryExpression : JsExpression { public JsExpression Expression { - get { return GetChildByRole(JsTreeRoles.Expression); } + get { return GetChildByRole(JsTreeRoles.Expression)!; } set { SetChildByRole(JsTreeRoles.Expression, value); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDeclaration.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDeclaration.cs deleted file mode 100644 index 3fb712c4da..0000000000 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDeclaration.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace DotVVM.Framework.Compilation.Javascript.Ast -{ - class JsVariableDeclaration - { - } -} diff --git a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDefStatement.cs b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDefStatement.cs index 8c908050cb..981630b2ad 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDefStatement.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/Ast/JsVariableDefStatement.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.Javascript.Ast { @@ -15,8 +16,8 @@ public string Keyword public JsIdentifier NameIdentifier { - get { return GetChildByRole(JsTreeRoles.Identifier); } - set { SetChildByRole(JsTreeRoles.Identifier, value); } + get { return GetChildByRole(JsTreeRoles.Identifier).NotNull(); } + set { SetChildByRole(JsTreeRoles.Identifier, value.NotNull()); } } public string Name @@ -26,13 +27,13 @@ public string Name } - public JsExpression Initialization + public JsExpression? Initialization { get { return GetChildByRole(JsTreeRoles.Expression); } set { SetChildByRole(JsTreeRoles.Expression, value); } } - public JsVariableDefStatement(string name, JsExpression expr = null) + public JsVariableDefStatement(string name, JsExpression? expr = null) { this.Name = name; this.Initialization = expr; diff --git a/src/DotVVM.Framework/Compilation/Javascript/EnumGetNamesMethodTranslator.cs b/src/DotVVM.Framework/Compilation/Javascript/EnumGetNamesMethodTranslator.cs index d6080f6a99..e45f6fa9cb 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/EnumGetNamesMethodTranslator.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/EnumGetNamesMethodTranslator.cs @@ -7,7 +7,7 @@ namespace DotVVM.Framework.Compilation.Javascript { public class EnumGetNamesMethodTranslator : IJavascriptMethodTranslator { - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) + public JsExpression TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) { var enumNames = (string[])method.Invoke(null, new object[0]); diff --git a/src/DotVVM.Framework/Compilation/Javascript/EnumToStringMethodTranslator.cs b/src/DotVVM.Framework/Compilation/Javascript/EnumToStringMethodTranslator.cs index 026864e2fd..d9ac4ec390 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/EnumToStringMethodTranslator.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/EnumToStringMethodTranslator.cs @@ -7,13 +7,13 @@ namespace DotVVM.Framework.Compilation.Javascript { public class EnumToStringMethodTranslator : IJavascriptMethodTranslator { - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) + public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) { // Enum has totally strange behavior in reflection: // method.DeclaringType.IsEnum == false // method != typeof(Enum).GetMethod("ToString", Array.Empty()) - if (method?.DeclaringType == typeof(Enum) && method.Name == "ToString" && method.GetParameters().Length == 0) + if (method?.DeclaringType == typeof(Enum) && context is object && method.Name == "ToString" && method.GetParameters().Length == 0) return context.JsExpression(); else return null; diff --git a/src/DotVVM.Framework/Compilation/Javascript/GenericMethodCompiler.cs b/src/DotVVM.Framework/Compilation/Javascript/GenericMethodCompiler.cs index f3846b69c3..641c66e634 100755 --- a/src/DotVVM.Framework/Compilation/Javascript/GenericMethodCompiler.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/GenericMethodCompiler.cs @@ -8,33 +8,33 @@ namespace DotVVM.Framework.Compilation.Javascript { public class GenericMethodCompiler : IJavascriptMethodTranslator { - public Func TryTranslateDelegate; + public Func TryTranslateDelegate; - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) => + public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) => TryTranslateDelegate(context, arguments, method); - public GenericMethodCompiler(Func builder, Func check = null) + public GenericMethodCompiler(Func builder, Func? check = null) { TryTranslateDelegate = - (t, arg, m) => check?.Invoke(m, t.OriginalExpression, arg.Select(a => a.OriginalExpression).ToArray()) == false + (t, arg, m) => check?.Invoke(m, t?.OriginalExpression, arg.Select(a => a.OriginalExpression).ToArray()) == false ? null - : builder(new [] { t.JsExpression() }.Concat(arg.Select(a => a.JsExpression())).ToArray()); + : builder(new [] { t?.JsExpression()! }.Concat(arg.Select(a => a.JsExpression())).ToArray()); } - public GenericMethodCompiler(Func builder, Func check = null) + public GenericMethodCompiler(Func builder, Func? check = null) { TryTranslateDelegate = - (t, arg, m) => check?.Invoke(m, t.OriginalExpression, arg.Select(a => a.OriginalExpression).ToArray()) == false + (t, arg, m) => check?.Invoke(m, t?.OriginalExpression, arg.Select(a => a.OriginalExpression).ToArray()) == false ? null - : builder(new[] { t.JsExpression() }.Concat(arg.Select(a => a.JsExpression())).ToArray(), arg.Select(a => a.OriginalExpression).ToArray()); + : builder(new[] { t?.JsExpression()! }.Concat(arg.Select(a => a.JsExpression())).ToArray(), arg.Select(a => a.OriginalExpression).ToArray()); } - public GenericMethodCompiler(Func builder, Func check = null) + public GenericMethodCompiler(Func builder, Func? check = null) { TryTranslateDelegate = - (t, arg, m) => check?.Invoke(m, t.OriginalExpression, arg.Select(a => a.OriginalExpression).ToArray()) == false + (t, arg, m) => check?.Invoke(m, t?.OriginalExpression, arg.Select(a => a.OriginalExpression).ToArray()) == false ? null - : builder(new [] { t.JsExpression() }.Concat(arg.Select(a => a.JsExpression())).ToArray(), m); + : builder(new [] { t?.JsExpression()! }.Concat(arg.Select(a => a.JsExpression())).ToArray(), m); } } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/IJavascriptMethodTranslator.cs b/src/DotVVM.Framework/Compilation/Javascript/IJavascriptMethodTranslator.cs index a3c0afd469..5b033d1782 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/IJavascriptMethodTranslator.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/IJavascriptMethodTranslator.cs @@ -6,6 +6,6 @@ namespace DotVVM.Framework.Compilation.Javascript { public interface IJavascriptMethodTranslator { - JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method); + JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/JavascriptCompilationHelper.cs b/src/DotVVM.Framework/Compilation/Javascript/JavascriptCompilationHelper.cs index 07b46bf54e..2af0a25933 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JavascriptCompilationHelper.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JavascriptCompilationHelper.cs @@ -11,7 +11,7 @@ namespace DotVVM.Framework.Compilation.Javascript { public static class JavascriptCompilationHelper { - public static string CompileConstant(object obj) => JsonConvert.SerializeObject(obj, DefaultSerializerSettingsProvider.Instance.Settings); + public static string CompileConstant(object? obj) => JsonConvert.SerializeObject(obj, DefaultSerializerSettingsProvider.Instance.Settings); private static readonly CodeSymbolicParameter indexerTargetParameter = new CodeSymbolicParameter("JavascriptCompilationHelper.indexerTargetParameter"); private static readonly CodeSymbolicParameter indexerExpressionParameter = new CodeSymbolicParameter("JavascriptCompilationHelper.indexerExpressionParameter"); @@ -30,9 +30,9 @@ public static ParametrizedCode AddIndexerToViewModel(ParametrizedCode script, Js default(CodeParameterAssignment)); } - public static ViewModelInfoAnnotation GetResultType(this JsExpression expr) + public static ViewModelInfoAnnotation? GetResultType(this JsExpression expr) { - ViewModelInfoAnnotation combine2(ViewModelInfoAnnotation a, ViewModelInfoAnnotation b) + ViewModelInfoAnnotation? combine2(ViewModelInfoAnnotation? a, ViewModelInfoAnnotation? b) { if (a == null || b == null) return a ?? b; else if (a.Type.IsAssignableFrom(b.Type)) return a; @@ -76,7 +76,7 @@ ViewModelInfoAnnotation combine2(ViewModelInfoAnnotation a, ViewModelInfoAnnotat } public static bool IsComplexType(this JsExpression expr) => - GetResultType(expr) is ViewModelInfoAnnotation vmInfo && ReflectionUtils.IsComplexType(vmInfo.Type); + GetResultType(expr) is { Type: var type } && ReflectionUtils.IsComplexType(type); public static bool IsRootResultExpression(this JsNode node) => SatisfyResultCondition(node, n => n.Parent == null || n.Parent is JsExpressionStatement); @@ -85,7 +85,7 @@ public static bool SatisfyResultCondition(this JsNode node, Func p (node.Parent is JsParenthesizedExpression || node.Role == JsConditionalExpression.FalseRole || node.Role == JsConditionalExpression.TrueRole - ) && node.Parent.SatisfyResultCondition(predicate); + ) && node.Parent!.SatisfyResultCondition(predicate); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/JavascriptNullCheckAdder.cs b/src/DotVVM.Framework/Compilation/Javascript/JavascriptNullCheckAdder.cs index 5afe856800..1b5a6d3cc7 100644 Binary files a/src/DotVVM.Framework/Compilation/Javascript/JavascriptNullCheckAdder.cs and b/src/DotVVM.Framework/Compilation/Javascript/JavascriptNullCheckAdder.cs differ diff --git a/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs b/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs index c80c18954a..92d1ce148f 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslatableMethodCollection.cs @@ -18,14 +18,9 @@ namespace DotVVM.Framework.Compilation.Javascript { public class DelegateInvokeMethodTranslator : IJavascriptMethodTranslator { - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) + public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) { - if (method == null) - { - return null; - } - - if (method.Name == "Invoke" && typeof(Delegate).IsAssignableFrom(method.DeclaringType)) + if (context is object && method.Name == "Invoke" && typeof(Delegate).IsAssignableFrom(method.DeclaringType)) { var invocationTargetExpressionCall = context.JsExpression().Invoke(arguments.Select(a => a.JsExpression())); return invocationTargetExpressionCall @@ -50,7 +45,7 @@ public JavascriptTranslatableMethodCollection() AddDefaultMethodTranslators(); } - public void AddMethodTranslator(Type declaringType, string methodName, IJavascriptMethodTranslator translator, Type[] parameters = null, bool allowGeneric = true, bool allowMultipleMethods = false) + public void AddMethodTranslator(Type declaringType, string methodName, IJavascriptMethodTranslator translator, Type[]? parameters = null, bool allowGeneric = true, bool allowMultipleMethods = false) { var methods = declaringType.GetMethods() .Where(m => m.Name == methodName && (allowGeneric || !m.IsGenericMethod)); @@ -65,7 +60,7 @@ public void AddMethodTranslator(Type declaringType, string methodName, IJavascri AddMethodsCore(methods.ToArray(), translator, allowMultipleMethods); } - public void AddMethodTranslator(Type declaringType, string methodName, IJavascriptMethodTranslator translator, int parameterCount, bool allowMultipleMethods = false, Func parameterFilter = null) + public void AddMethodTranslator(Type declaringType, string methodName, IJavascriptMethodTranslator translator, int parameterCount, bool allowMultipleMethods = false, Func? parameterFilter = null) { var methods = declaringType.GetMethods() .Where(m => m.Name == methodName) @@ -160,8 +155,8 @@ JsExpression dictionarySetIndexer(JsExpression[] args, MethodInfo method) => AddMethodTranslator(typeof(DotvvmBindableObject).GetMethods(BindingFlags.Instance | BindingFlags.Public).Single(m => m.Name == "GetValue" && !m.ContainsGenericParameters), new GenericMethodCompiler( args => { - var dotvvmproperty = ((DotvvmProperty)((JsLiteral)args[1]).Value); - return JavascriptTranslationVisitor.TranslateViewModelProperty(args[0], (MemberInfo)dotvvmproperty.PropertyInfo ?? dotvvmproperty.PropertyType, name: dotvvmproperty.Name); + var dotvvmproperty = ((DotvvmProperty)((JsLiteral)args[1]).Value!); + return JavascriptTranslationVisitor.TranslateViewModelProperty(args[0], (MemberInfo?)dotvvmproperty.PropertyInfo ?? dotvvmproperty.PropertyType, name: dotvvmproperty.Name); } )); @@ -182,7 +177,7 @@ JsExpression dictionarySetIndexer(JsExpression[] args, MethodInfo method) => private void AddDefaultToStringTranslations() { AddMethodTranslator(typeof(object), "ToString", new GenericMethodCompiler( - a => new JsIdentifierExpression("String").Invoke(a[0]), (m, c, a) => ToStringCheck(c)), 0); + a => new JsIdentifierExpression("String").Invoke(a[0]), (m, c, a) => ToStringCheck(c!)), 0); AddMethodTranslator(typeof(Convert), "ToString", new GenericMethodCompiler( a => new JsIdentifierExpression("String").Invoke(a[1]), (m, c, a) => ToStringCheck(a[0])), 1, true); @@ -479,7 +474,7 @@ string GetDelegateReturnTypeHash(Type type) AddMethodTranslator(typeof(Enumerable), nameof(Enumerable.Count), parameterCount: 1, translator: new GenericMethodCompiler(args => args[1].Member("length"))); AddMethodTranslator(typeof(Enumerable), nameof(Enumerable.Distinct), parameterCount: 1, translator: new GenericMethodCompiler(args => new JsIdentifierExpression("dotvvm").Member("translations").Member("array").Member("distinct").Invoke(args[1]), - check: (method, target, arguments) => EnsureIsComparableInJavascript(method, target?.Type ?? ReflectionUtils.GetEnumerableType(arguments.First().Type)))); + check: (method, target, arguments) => EnsureIsComparableInJavascript(method, ReflectionUtils.GetEnumerableType(arguments.First().Type).NotNull()))); AddMethodTranslator(typeof(Enumerable), nameof(Enumerable.ElementAt), parameterCount: 2, parameterFilter: p => p[1].ParameterType == typeof(int), translator: new GenericMethodCompiler((args, method) => BuildIndexer(args[1], args[2], method))); @@ -589,13 +584,8 @@ JsExpression IncrementExpression(JsExpression left, int value) new JsNewExpression(new JsIdentifierExpression("Date"), args[0]).Member("getMilliseconds").Invoke())); } - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] args, MethodInfo method) + public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] args, MethodInfo method) { - if (method == null) - { - return null; - } - { if (MethodTranslators.TryGetValue(method, out var translator) && translator.TryTranslateCall(context, args, method) is JsExpression result) { diff --git a/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslationVisitor.cs b/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslationVisitor.cs index 8c781ce051..386b1b0714 100755 --- a/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslationVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslationVisitor.cs @@ -152,7 +152,7 @@ public JsExpression TranslateAssign(BinaryExpression expression) var target = Translate(property.Expression); var value = Translate(expression.Right); return TryTranslateMethodCall((property.Member as PropertyInfo)?.SetMethod, property.Expression, new[] { expression.Right }) ?? - SetProperty(target, property.Member as PropertyInfo, value); + SetProperty(target, property.Member, value); } else if (expression.Left.GetParameterAnnotation() is BindingParameterAnnotation annotation) { @@ -165,7 +165,7 @@ public JsExpression TranslateAssign(BinaryExpression expression) throw new NotSupportedException($"Can not assign expression of type {expression.Left.NodeType}!"); } - private JsExpression SetProperty(JsExpression target, PropertyInfo property, JsExpression value) => + private JsExpression SetProperty(JsExpression target, MemberInfo property, JsExpression value) => new JsAssignmentExpression(TranslateViewModelProperty(target, property), value); public JsExpression TranslateConditional(ConditionalExpression expression) => @@ -197,7 +197,7 @@ JsExpression getDataContext(int parentContexts) context = context.Member("$parentContext"); return context; } - int getContextSteps(DataContextStack item) => + int getContextSteps(DataContextStack? item) => item == null ? 0 : ContextMap[item]; if (annotation.ExtensionParameter != null) @@ -353,15 +353,15 @@ public JsExpression TranslateMemberAccess(MemberExpression expression) } } - public static JsExpression TranslateViewModelProperty(JsExpression context, MemberInfo propInfo, string name = null) => + public static JsExpression TranslateViewModelProperty(JsExpression context, MemberInfo propInfo, string? name = null) => new JsMemberAccessExpression(context, name ?? propInfo.Name) .WithAnnotation(new VMPropertyInfoAnnotation(propInfo)) .WithAnnotation(new ViewModelInfoAnnotation(propInfo.GetResultType())); - public JsExpression TryTranslateMethodCall(MethodInfo methodInfo, Expression target, IEnumerable arguments) => + public JsExpression? TryTranslateMethodCall(MethodInfo? methodInfo, Expression? target, IEnumerable arguments) => methodInfo is null ? null : Translator.TryTranslateCall( - new LazyTranslatedExpression(target, Translate), + target is null ? null : new LazyTranslatedExpression(target, Translate), arguments.Select(a => new LazyTranslatedExpression(a, Translate)).ToArray(), methodInfo) ?.WithAnnotation(new ViewModelInfoAnnotation(methodInfo.ReturnType), append: false); @@ -370,7 +370,7 @@ public class FakeExtensionParameter : BindingExtensionParameter { private readonly Func getJsTranslation; - public FakeExtensionParameter(Func getJsTranslation, string identifier = "__", ITypeDescriptor type = null, bool inherit = false) : base(identifier, type, inherit) + public FakeExtensionParameter(Func getJsTranslation, string identifier = "__", ITypeDescriptor? type = null, bool inherit = false) : base(identifier, type, inherit) { this.getJsTranslation = getJsTranslation; } @@ -383,14 +383,13 @@ public FakeExtensionParameter(Func getJsTranslation, /// Represents an Linq.Expression that is being translated to JsAst. public class LazyTranslatedExpression { - private static readonly Lazy nullLazy = new Lazy(() => null); private readonly Lazy lazyJsExpression; public JsExpression JsExpression() => lazyJsExpression.Value; public Expression OriginalExpression { get; } public LazyTranslatedExpression(Expression expr, Func translateMethod) { - this.OriginalExpression = expr; - this.lazyJsExpression = expr == null ? nullLazy : new Lazy(() => translateMethod(expr)); + this.OriginalExpression = expr ?? throw new ArgumentNullException(nameof(expr)); + this.lazyJsExpression = new(() => translateMethod(expr)); } } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslator.cs b/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslator.cs index befc2c5992..2c0d121581 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslator.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JavascriptTranslator.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -92,7 +91,7 @@ public JavascriptTranslator(IJavascriptMethodTranslator config, IViewModelSerial this.mapper = serializationMapper; } - public JsExpression TryTranslateMethodCall(Expression context, Expression[] arguments, MethodInfo method, DataContextStack dataContext) + public JsExpression? TryTranslateMethodCall(Expression? context, Expression[] arguments, MethodInfo? method, DataContextStack dataContext) { return new JavascriptTranslationVisitor(dataContext, DefaultMethodTranslator).TryTranslateMethodCall(method, context, arguments); } @@ -213,7 +212,7 @@ public JavascriptTranslatorConfiguration() Translators.Add(new DelegateInvokeMethodTranslator()); } - public JsExpression TryTranslateCall(LazyTranslatedExpression context, LazyTranslatedExpression[] arguments, MethodInfo method) => + public JsExpression? TryTranslateCall(LazyTranslatedExpression? context, LazyTranslatedExpression[] arguments, MethodInfo method) => Translators.Select(t => t.TryTranslateCall(context, arguments, method)).FirstOrDefault(d => d != null); } } diff --git a/src/DotVVM.Framework/Compilation/Javascript/JsFormattingVisitor.cs b/src/DotVVM.Framework/Compilation/Javascript/JsFormattingVisitor.cs index e90dfa0705..393e755bf5 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JsFormattingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JsFormattingVisitor.cs @@ -19,7 +19,7 @@ public JsFormattingVisitor(bool niceMode = false, string indent = "\t") } StringBuilder result = new StringBuilder(); - List<(int index, CodeParameterInfo parameter)> parameters; + List<(int index, CodeParameterInfo parameter)>? parameters; protected void Emit(string str) { Debug.Assert(!str.Contains("\n")); diff --git a/src/DotVVM.Framework/Compilation/Javascript/JsParensFixingVisitor.cs b/src/DotVVM.Framework/Compilation/Javascript/JsParensFixingVisitor.cs index b52bb5a29e..a828f130a4 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JsParensFixingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JsParensFixingVisitor.cs @@ -55,7 +55,7 @@ public override string ToString() public class JsParensFixingVisitor : JsNodeVisitor { - public static byte OperatorLevel(JsExpression expression) + public static byte OperatorLevel(JsExpression? expression) { switch (expression) { case JsParenthesizedExpression _: diff --git a/src/DotVVM.Framework/Compilation/Javascript/JsTemporaryVariableResolver.cs b/src/DotVVM.Framework/Compilation/Javascript/JsTemporaryVariableResolver.cs index 5a8d4c1f05..4b3bbe2969 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JsTemporaryVariableResolver.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JsTemporaryVariableResolver.cs @@ -54,7 +54,7 @@ void walkNode(List<(JsNode, bool)> path, JsNode n) .OfType() .Count(p => p == v); Debug.Assert(count >= 1); - if (count == 1 && v.AllowInlining) + if (count == 1 && v.AllowInlining && v.Initializer is object) { node = node.AssignParameters(p => p == v ? v.Initializer.Clone() : null); allVariables.Remove(v); @@ -124,7 +124,7 @@ static bool ContainsAwait(JsNode node) => node.DescendantNodesAndSelf(child => !(child is JsFunctionExpression)) .Any(child => child is JsUnaryExpression { Operator: UnaryOperatorType.Await }); - public static IEnumerable GetNames(string baseName = null) + public static IEnumerable GetNames(string? baseName = null) { IEnumerable getChars(bool isFirst) { @@ -149,11 +149,11 @@ IEnumerable getChars(bool isFirst) } public sealed class JsTemporaryVariableParameter: CodeSymbolicParameter { - public JsExpression Initializer { get; } - public string PreferredName { get; } + public JsExpression? Initializer { get; } + public string? PreferredName { get; } public bool AllowInlining { get; } - public JsTemporaryVariableParameter(JsExpression initializer = null, string preferredName = null, bool allowInlining = true) + public JsTemporaryVariableParameter(JsExpression? initializer = null, string? preferredName = null, bool allowInlining = true) : base("tmp_var[" + initializer?.ToString() + "]") { this.Initializer = initializer; diff --git a/src/DotVVM.Framework/Compilation/Javascript/JsViewModelPropertyAdjuster.cs b/src/DotVVM.Framework/Compilation/Javascript/JsViewModelPropertyAdjuster.cs index 6102b79a5d..c9923e9914 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/JsViewModelPropertyAdjuster.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/JsViewModelPropertyAdjuster.cs @@ -49,34 +49,34 @@ protected override void DefaultVisit(JsNode node) } } - if (node.Annotation() is VMPropertyInfoAnnotation propAnnotation) + if (node.Annotation() is { MemberInfo: {} member } propAnnotation) { - var target = node.GetChildByRole(JsTreeRoles.TargetExpression); + var target = node.GetChildByRole(JsTreeRoles.TargetExpression)!; if (target.HasAnnotation()) target = target.GetChildByRole(JsTreeRoles.TargetExpression); else if (target.HasAnnotation()) throw new NotImplementedException(); - var propertyType = propAnnotation.MemberInfo.GetResultType(); + var propertyType = member.GetResultType(); var annotation = node.Annotation() ?? new ViewModelInfoAnnotation(propertyType); if (target?.Annotation() is {} targetAnnotation) { propAnnotation.SerializationMap ??= targetAnnotation.SerializationMap?.Properties - .FirstOrDefault(p => p.PropertyInfo == propAnnotation.MemberInfo); + .FirstOrDefault(p => p.PropertyInfo == member); annotation.ContainsObservables ??= targetAnnotation.ContainsObservables; } if (propAnnotation.SerializationMap is ViewModelPropertyMap propertyMap) { - if (propertyMap.ViewModelProtection == ViewModel.ProtectMode.EncryptData) throw new Exception($"Property {propAnnotation.MemberInfo.Name} is encrypted and cannot be used in JS."); + if (propertyMap.ViewModelProtection == ViewModel.ProtectMode.EncryptData) throw new Exception($"Property {member.Name} is encrypted and cannot be used in JS."); if (node is JsMemberAccessExpression memberAccess && propertyMap.Name != memberAccess.MemberName) { memberAccess.MemberName = propertyMap.Name; } } - else if (propAnnotation.MemberInfo is FieldInfo) - throw new NotSupportedException($"Can not translate field '{propAnnotation.MemberInfo}' to Javascript"); + else if (member is FieldInfo) + throw new NotSupportedException($"Can not translate field '{member}' to Javascript"); annotation.ContainsObservables ??= !this.preferUsingState; // we don't know -> guess what is the current preference @@ -106,7 +106,7 @@ public override void VisitMemberAccessExpression(JsMemberAccessExpression expr) if (preferUsingState && expr.Target is JsSymbolicParameter { Symbol: JavascriptTranslator.ViewModelSymbolicParameter vmSymbol }) { var propertyAnnotation = expr.Annotation(); - var typeAnnotation = expr.Annotation() ?? new ViewModelInfoAnnotation(propertyAnnotation.MemberInfo.GetResultType()); + var typeAnnotation = expr.Annotation() ?? new ViewModelInfoAnnotation(propertyAnnotation!.MemberInfo!.GetResultType()); expr = (JsMemberAccessExpression)expr.ReplaceWith(_ => expr.WithAnnotation(ShouldBeObservableAnnotation.Instance) .Member("state") diff --git a/src/DotVVM.Framework/Compilation/Javascript/KnockoutObservableHandlingVisitor.cs b/src/DotVVM.Framework/Compilation/Javascript/KnockoutObservableHandlingVisitor.cs index 2028b7e668..e34c661943 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/KnockoutObservableHandlingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/KnockoutObservableHandlingVisitor.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using DotVVM.Framework.Compilation.Javascript.Ast; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.Javascript { @@ -31,7 +32,7 @@ private void HandleNode(JsNode node) node.ReplaceWith(_ => transform.TransformExpression(expression2)); } - if (node is JsExpression expression && IsObservableResult(node) && !node.Parent.HasAnnotation() && !(node.Role == JsAssignmentExpression.LeftRole && node.Parent is JsAssignmentExpression) && node.Parent != null) + if (node is JsExpression expression && IsObservableResult(node) && !node.Parent!.HasAnnotation() && !(node.Role == JsAssignmentExpression.LeftRole && node.Parent is JsAssignmentExpression) && node.Parent != null) { if (ShouldUnwrap(node)) { @@ -69,7 +70,7 @@ public override void VisitAssignmentExpression(JsAssignmentExpression assignment // only do for ResultIsObservable, not ResultMayBeObservable if (assignmentExpression.Left.HasAnnotation()) { - var resultType = assignmentExpression.GetResultType(); + var resultType = assignmentExpression.GetResultType().NotNull("Can not process assignment operator with unknown type."); var value = assignmentExpression.Right.Detach(); var assignee = assignmentExpression.Left.Detach(); assignee.RemoveAnnotations(); diff --git a/src/DotVVM.Framework/Compilation/Javascript/ParametrizedCode.cs b/src/DotVVM.Framework/Compilation/Javascript/ParametrizedCode.cs index e3db4f7d7f..ad08048393 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/ParametrizedCode.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/ParametrizedCode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq; using System.Collections.Generic; using System.Text; @@ -323,7 +322,7 @@ public readonly struct CodeParameterAssignment public CodeParameterAssignment(string code, OperatorPrecedence operatorPrecedence, bool isGlobalContext = false) : this(new ParametrizedCode(code, operatorPrecedence), isGlobalContext) { } - public CodeParameterAssignment(ParametrizedCode code, bool isGlobalContext = false) + public CodeParameterAssignment(ParametrizedCode? code, bool isGlobalContext = false) { this.Code = code; this.IsGlobalContext = isGlobalContext; diff --git a/src/DotVVM.Framework/Compilation/Javascript/PropertyPathExtractingVisitor.cs b/src/DotVVM.Framework/Compilation/Javascript/PropertyPathExtractingVisitor.cs index 588fbbfd88..75c252165c 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/PropertyPathExtractingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/PropertyPathExtractingVisitor.cs @@ -1,4 +1,5 @@ -using DotVVM.Framework.Compilation.Javascript.Ast; +#nullable disable +using DotVVM.Framework.Compilation.Javascript.Ast; namespace DotVVM.Framework.Compilation.Javascript { @@ -28,4 +29,4 @@ private void ExtractPropertyPath() ExtractedPropertyPath = fullPropertyPath.Substring(koUnwrapPathSegment.Length + 1); } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Compilation/Javascript/SideEffectAnalyzer.cs b/src/DotVVM.Framework/Compilation/Javascript/SideEffectAnalyzer.cs index 8786d414a2..7022c7bb0a 100644 --- a/src/DotVVM.Framework/Compilation/Javascript/SideEffectAnalyzer.cs +++ b/src/DotVVM.Framework/Compilation/Javascript/SideEffectAnalyzer.cs @@ -16,7 +16,7 @@ public static ExpressionMutationList GetPossibleMutations(params JsNode[] nodes) ComputePossibleMutations(result, node); return result; } - static bool isNameOverridden(object name, JsNode n, JsNode rootNode) + static bool isNameOverridden(object name, JsNode? n, JsNode? rootNode) { if (!(name is string)) return false; while (n != null && n != rootNode) @@ -27,7 +27,7 @@ static bool isNameOverridden(object name, JsNode n, JsNode rootNode) } return false; } - static IEnumerable getAssignedPath(JsExpression expression, JsNode rootNode) + static IEnumerable? getAssignedPath(JsExpression? expression, JsNode? rootNode) { if (expression is JsIdentifierExpression identifier && !isNameOverridden(identifier.Identifier, identifier, rootNode)) return new [] { identifier.Identifier }; @@ -50,7 +50,7 @@ public static void ComputePossibleMutations(ExpressionMutationList result, JsNod path?.ApplyAction(result.SetMutatedMember); var rightPath = getAssignedPath(assignment.Right, node); if (path != null && rightPath != null) - result.GetMember(rightPath).EqualTo.Add(result.GetMember(path)); + result.GetMember(rightPath).NotNull().EqualTo.Add(result.GetMember(path).NotNull()); } else if (n is JsInvocationExpression invocation) { @@ -105,10 +105,10 @@ public ExpressionMutationList GetMember(object member) return result; } - public ExpressionMutationList GetMember(IEnumerable path) => + public ExpressionMutationList? GetMember(IEnumerable? path) => path?.Aggregate(this, (p, m) => p.GetMember(m)); public void SetMutatedMember(IEnumerable path) => - GetMember(path).MutatesRoot = true; + GetMember(path).NotNull("Could not find path.").MutatesRoot = true; } } diff --git a/src/DotVVM.Framework/Compilation/NamespaceImport.cs b/src/DotVVM.Framework/Compilation/NamespaceImport.cs index d1407e1e83..4c0286343f 100644 --- a/src/DotVVM.Framework/Compilation/NamespaceImport.cs +++ b/src/DotVVM.Framework/Compilation/NamespaceImport.cs @@ -13,15 +13,16 @@ public struct NamespaceImport: IEquatable [JsonProperty("namespace")] public readonly string Namespace; [JsonProperty("alias")] - public readonly string Alias; + public readonly string? Alias; [JsonIgnore] - public bool HasAlias => Alias != null; + public bool HasAlias => Alias is not null; [JsonConstructor] - public NamespaceImport(string @namespace, string alias = null) + public NamespaceImport(string @namespace, string? alias = null) { if (@namespace == null) throw new ArgumentNullException(nameof(@namespace)); + if (alias == "") throw new ArgumentException("Alias can not be empty string, use null instead."); this.Namespace = @namespace; this.Alias = alias; } diff --git a/src/DotVVM.Framework/Compilation/Parser/AggregateList.cs b/src/DotVVM.Framework/Compilation/Parser/AggregateList.cs index 6debb9c91d..0eb43b5fd3 100644 --- a/src/DotVVM.Framework/Compilation/Parser/AggregateList.cs +++ b/src/DotVVM.Framework/Compilation/Parser/AggregateList.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/src/DotVVM.Framework/Compilation/Parser/BeginWithLastTokenOfTypeTokenError.cs b/src/DotVVM.Framework/Compilation/Parser/BeginWithLastTokenOfTypeTokenError.cs index 9bee546bba..7777de3034 100644 --- a/src/DotVVM.Framework/Compilation/Parser/BeginWithLastTokenOfTypeTokenError.cs +++ b/src/DotVVM.Framework/Compilation/Parser/BeginWithLastTokenOfTypeTokenError.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; namespace DotVVM.Framework.Compilation.Parser diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/Annotations/WriteAccessAnnotation.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/Annotations/WriteAccessAnnotation.cs index 2c71fdd8ad..e23da7df95 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/Annotations/WriteAccessAnnotation.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/Annotations/WriteAccessAnnotation.cs @@ -13,7 +13,7 @@ private WriteAccessAnnotation() } - private static WriteAccessAnnotation instance; + private static WriteAccessAnnotation? instance; public static WriteAccessAnnotation Instance { get diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ArrayAccessBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ArrayAccessBindingParserNode.cs index 97324344d6..16acf3e3aa 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ArrayAccessBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ArrayAccessBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/AssemblyQualifiedNameBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/AssemblyQualifiedNameBindingParserNode.cs index 0a4c11ea5a..5e2bdcc9b5 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/AssemblyQualifiedNameBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/AssemblyQualifiedNameBindingParserNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BinaryOperatorBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BinaryOperatorBindingParserNode.cs index 456fb97eb2..fff6e9d965 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BinaryOperatorBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BinaryOperatorBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParser.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParser.cs index 02b2e99686..f7fd66a888 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParser.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParser.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Globalization; @@ -503,8 +502,8 @@ private bool TryReadTypeReference([NotNullWhen(returnValue: true)] out TypeRefer { // Nullable Read(); - expression = (!(expression is TypeReferenceBindingParserNode)) ? new ActualTypeReferenceBindingParserNode(expression) : expression; - expression = CreateNode(new NullableTypeReferenceBindingParserNode(expression as TypeReferenceBindingParserNode), startIndex); + var typeExpr = expression as TypeReferenceBindingParserNode ?? new ActualTypeReferenceBindingParserNode(expression); + expression = CreateNode(new NullableTypeReferenceBindingParserNode(typeExpr), startIndex); } else if (next.Type == BindingTokenType.OpenArrayBrace) { @@ -514,8 +513,8 @@ private bool TryReadTypeReference([NotNullWhen(returnValue: true)] out TypeRefer if (next?.Type != BindingTokenType.CloseArrayBrace) return false; Read(); - expression = (!(expression is TypeReferenceBindingParserNode)) ? new ActualTypeReferenceBindingParserNode(expression) : expression; - expression = CreateNode(new ArrayTypeReferenceBindingParserNode(expression as TypeReferenceBindingParserNode), startIndex); + var typeExpr = expression as TypeReferenceBindingParserNode ?? new ActualTypeReferenceBindingParserNode(expression); + expression = CreateNode(new ArrayTypeReferenceBindingParserNode(typeExpr), startIndex); } else { @@ -524,8 +523,7 @@ private bool TryReadTypeReference([NotNullWhen(returnValue: true)] out TypeRefer next = Peek(); } - expression = (!(expression is TypeReferenceBindingParserNode)) ? new ActualTypeReferenceBindingParserNode(expression) : expression; - typeNode = (expression as TypeReferenceBindingParserNode)!; + typeNode = expression as TypeReferenceBindingParserNode ?? new ActualTypeReferenceBindingParserNode(expression); return true; } diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNode.cs index 0c62316fc9..2796247309 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNodeVisitor.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNodeVisitor.cs index afef82167a..5e17006d32 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNodeVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BindingParserNodeVisitor.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; namespace DotVVM.Framework.Compilation.Parser.Binding.Parser { diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BlockBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BlockBindingParserNode.cs index df4e7d045a..d5796e37e2 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BlockBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/BlockBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ConditionalExpressionBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ConditionalExpressionBindingParserNode.cs index 9ab493631e..da41cd595e 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ConditionalExpressionBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ConditionalExpressionBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/FunctionCallBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/FunctionCallBindingParserNode.cs index 66d53955b8..62c541e62f 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/FunctionCallBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/FunctionCallBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/GenericNameBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/GenericNameBindingParserNode.cs index 0e7ca1f8a8..ac3785e95b 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/GenericNameBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/GenericNameBindingParserNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Compilation.Parser.Binding.Tokenizer; +using DotVVM.Framework.Compilation.Parser.Binding.Tokenizer; using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/IdentifierNameBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/IdentifierNameBindingParserNode.cs index 06a92fd5e0..a0aec8a4f5 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/IdentifierNameBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/IdentifierNameBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Compilation.Parser.Binding.Tokenizer; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LambdaBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LambdaBindingParserNode.cs index 2f7abd505b..3a8d965c68 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LambdaBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LambdaBindingParserNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LiteralExpressionBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LiteralExpressionBindingParserNode.cs index 4669fd5e4b..81cc3fa5a1 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LiteralExpressionBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/LiteralExpressionBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MemberAccessBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MemberAccessBindingParserNode.cs index 8f8961e2c4..23d06d9ac5 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MemberAccessBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MemberAccessBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MultiExpressionBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MultiExpressionBindingParserNode.cs index efe76f6818..e6ad5b67b4 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MultiExpressionBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/MultiExpressionBindingParserNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ParenthesizedExpressionBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ParenthesizedExpressionBindingParserNode.cs index 6ce6dbb9ea..f48529947e 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ParenthesizedExpressionBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/ParenthesizedExpressionBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/SimpleNameBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/SimpleNameBindingParserNode.cs index fb39b970dd..98bb73c7c0 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/SimpleNameBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/SimpleNameBindingParserNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/TypeOrFunctionReferenceBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/TypeOrFunctionReferenceBindingParserNode.cs index aeff4011bb..7705fd7c27 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/TypeOrFunctionReferenceBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/TypeOrFunctionReferenceBindingParserNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/UnaryOperatorBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/UnaryOperatorBindingParserNode.cs index 8a12ff4979..5b649f2485 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/UnaryOperatorBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/UnaryOperatorBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/VoidBindingParserNode.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/VoidBindingParserNode.cs index 6b8ff68e3c..f4fd0156db 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/VoidBindingParserNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Parser/VoidBindingParserNode.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Compilation.Parser.Binding.Tokenizer; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingToken.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingToken.cs index 73f142677c..46bce1f896 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingToken.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingToken.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Compilation.Parser.Binding.Tokenizer { public class BindingToken : TokenBase diff --git a/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingTokenizer.cs b/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingTokenizer.cs index f20137bf88..6e3cb8c4f8 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingTokenizer.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Binding/Tokenizer/BindingTokenizer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DotHtmlCommentNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DotHtmlCommentNode.cs index 9e2ca23581..24e2ed242b 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DotHtmlCommentNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DotHtmlCommentNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlAttributeNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlAttributeNode.cs index daceec370b..05457ac7ee 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlAttributeNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlAttributeNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlBindingNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlBindingNode.cs index 9870237afc..8696abc5df 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlBindingNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlBindingNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlDirectiveNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlDirectiveNode.cs index 99ac9a765d..9a9f96ed69 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlDirectiveNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlDirectiveNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlElementNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlElementNode.cs index 2aab12a3ff..6efc789e38 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlElementNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlElementNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlLiteralNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlLiteralNode.cs index c5376af8ce..cc598bdf6c 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlLiteralNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlLiteralNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNameNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNameNode.cs index 583f6ab91f..2e62c3b9ac 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNameNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNameNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNode.cs index 98c0cd8783..52a140ff9a 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeHelper.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeHelper.cs index 27e978b27c..c8f79fe4e6 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeHelper.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeHelper.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Linq; using System.Diagnostics.CodeAnalysis; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeWithContent.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeWithContent.cs index 0ef570e5e3..55846b76ca 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeWithContent.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlNodeWithContent.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; namespace DotVVM.Framework.Compilation.Parser.Dothtml.Parser diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlParser.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlParser.cs index 8838be85b1..31c9edae39 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlParser.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlParser.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlRootNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlRootNode.cs index 20347be3b0..83337b70d7 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlRootNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlRootNode.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueBindingNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueBindingNode.cs index d540185217..6084be6f5a 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueBindingNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueBindingNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueNode.cs index 7a52a6895a..f7911fd424 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueTextNode.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueTextNode.cs index 041e96be67..b15b51181f 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueTextNode.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/DothtmlValueTextNode.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/HierarchyBuildingVisitor.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/HierarchyBuildingVisitor.cs index d9739ab438..b9c95f2a3c 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/HierarchyBuildingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/HierarchyBuildingVisitor.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; namespace DotVVM.Framework.Compilation.Parser.Dothtml.Parser diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/IDothtmlSyntaxTreeVisitor.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/IDothtmlSyntaxTreeVisitor.cs index dc99dbe079..b55679cfec 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/IDothtmlSyntaxTreeVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/IDothtmlSyntaxTreeVisitor.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace DotVVM.Framework.Compilation.Parser.Dothtml.Parser +namespace DotVVM.Framework.Compilation.Parser.Dothtml.Parser { public interface IDothtmlSyntaxTreeVisitor { diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParentResolvingVisitor.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParentResolvingVisitor.cs index c9b559cea1..d6ae4c3ff0 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParentResolvingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParentResolvingVisitor.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace DotVVM.Framework.Compilation.Parser.Dothtml.Parser +namespace DotVVM.Framework.Compilation.Parser.Dothtml.Parser { public class ParentResolvingVisitor : IDothtmlSyntaxTreeVisitor { diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParserBase.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParserBase.cs index 979e5f233f..a166deed95 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParserBase.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Parser/ParserBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Tokenizer/DothtmlTokenizer.cs b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Tokenizer/DothtmlTokenizer.cs index 7202e5de5c..004f84b4f8 100644 --- a/src/DotVVM.Framework/Compilation/Parser/Dothtml/Tokenizer/DothtmlTokenizer.cs +++ b/src/DotVVM.Framework/Compilation/Parser/Dothtml/Tokenizer/DothtmlTokenizer.cs @@ -146,7 +146,7 @@ private void ReadDirective() SkipWhitespace(false); // whitespace - if (LastToken.Type != DothtmlTokenType.WhiteSpace) + if (LastToken!.Type != DothtmlTokenType.WhiteSpace) { CreateToken(DothtmlTokenType.WhiteSpace, errorProvider: t => CreateTokenError(t, DothtmlTokenType.DirectiveStart, DothtmlTokenizerErrors.DirectiveValueExpected)); } @@ -623,8 +623,7 @@ private void ReadBinding(bool doubleCloseBrace) if (ch == '\'' || ch == '"') { // string literal - ignore curly braces inside - string errorMessage; - BindingTokenizer.ReadStringLiteral(Peek, Read, out errorMessage); + BindingTokenizer.ReadStringLiteral(Peek, Read, out _); } else if (ch == NullChar) { diff --git a/src/DotVVM.Framework/Compilation/Parser/DotvvmParserException.cs b/src/DotVVM.Framework/Compilation/Parser/DotvvmParserException.cs index 75d20c0107..185da9977c 100644 --- a/src/DotVVM.Framework/Compilation/Parser/DotvvmParserException.cs +++ b/src/DotVVM.Framework/Compilation/Parser/DotvvmParserException.cs @@ -9,7 +9,7 @@ public class DotvvmParserException : Exception public int PositionOnLine { get; set; } - public string FileName { get; set; } + public string? FileName { get; set; } public DotvvmParserException(string message) : base(message) diff --git a/src/DotVVM.Framework/Compilation/Parser/NullTokenError.cs b/src/DotVVM.Framework/Compilation/Parser/NullTokenError.cs index b0c1574cb8..a7fc4cd2ab 100644 --- a/src/DotVVM.Framework/Compilation/Parser/NullTokenError.cs +++ b/src/DotVVM.Framework/Compilation/Parser/NullTokenError.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Compilation.Parser { public class NullTokenError : TokenError where TToken : TokenBase diff --git a/src/DotVVM.Framework/Compilation/Parser/TokenBase.cs b/src/DotVVM.Framework/Compilation/Parser/TokenBase.cs index 9c4b254134..8ccd0bbf85 100644 --- a/src/DotVVM.Framework/Compilation/Parser/TokenBase.cs +++ b/src/DotVVM.Framework/Compilation/Parser/TokenBase.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Compilation.Parser { public abstract class TokenBase : ITextRange @@ -26,10 +25,7 @@ protected TokenBase(string text, int lineNumber, int columnNumber, int length, i public TokenError? Error { get; set; } - public bool HasError - { - get { return Error != null; } - } + public bool HasError => Error is not null; public override string ToString() { return string.Format("Token ({0}:{1}): {2}", StartPosition, Length, Text); diff --git a/src/DotVVM.Framework/Compilation/Parser/TokenError.cs b/src/DotVVM.Framework/Compilation/Parser/TokenError.cs index 9c1d0b54d2..3ebd7008cf 100644 --- a/src/DotVVM.Framework/Compilation/Parser/TokenError.cs +++ b/src/DotVVM.Framework/Compilation/Parser/TokenError.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Compilation.Parser { public abstract class TokenError diff --git a/src/DotVVM.Framework/Compilation/Parser/TokenListExtensions.cs b/src/DotVVM.Framework/Compilation/Parser/TokenListExtensions.cs index 0c6fa47dfe..78483f128e 100644 --- a/src/DotVVM.Framework/Compilation/Parser/TokenListExtensions.cs +++ b/src/DotVVM.Framework/Compilation/Parser/TokenListExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using DotVVM.Framework.Compilation.Parser.Dothtml.Tokenizer; diff --git a/src/DotVVM.Framework/Compilation/Parser/TokenizerBase.cs b/src/DotVVM.Framework/Compilation/Parser/TokenizerBase.cs index 1b5b5048e9..d42a43a88f 100644 --- a/src/DotVVM.Framework/Compilation/Parser/TokenizerBase.cs +++ b/src/DotVVM.Framework/Compilation/Parser/TokenizerBase.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; diff --git a/src/DotVVM.Framework/Compilation/RoslynValueEmitter.cs b/src/DotVVM.Framework/Compilation/RoslynValueEmitter.cs index 729cbd2581..f8ff952285 100644 --- a/src/DotVVM.Framework/Compilation/RoslynValueEmitter.cs +++ b/src/DotVVM.Framework/Compilation/RoslynValueEmitter.cs @@ -24,22 +24,22 @@ public RoslynValueEmitter(Func useType) protected Func UseType { get; } - private ConditionalWeakTable inverseEmitValue = new ConditionalWeakTable(); + private ConditionalWeakTable inverseEmitValue = new(); /// /// Emits the value. /// - public ExpressionSyntax EmitValue(object value) + public ExpressionSyntax EmitValue(object? value) { var result = EmitValueCore(value); inverseEmitValue.GetValue(result, _ => value); return result; } - public bool TryInvertExpression(ExpressionSyntax expression, out object value) => + public bool TryInvertExpression(ExpressionSyntax expression, out object? value) => inverseEmitValue.TryGetValue(expression, out value); - private ExpressionSyntax EmitValueCore(object value) + private ExpressionSyntax EmitValueCore(object? value) { if (value == null) { @@ -81,9 +81,9 @@ private ExpressionSyntax EmitValueCore(object value) { return EmitStandardNumericLiteral((double)value); } - if (value is Type) + if (value is Type valueAsType) { - return SyntaxFactory.TypeOfExpression(UseType(value as Type)); + return SyntaxFactory.TypeOfExpression(UseType(valueAsType)); } var type = value.GetType(); @@ -116,7 +116,7 @@ private ExpressionSyntax EmitValueCore(object value) return EmitValueReference(value); if (type.IsArray || typeof(System.Collections.IEnumerable).IsAssignableFrom(type)) { - return EmitCreateArray(ReflectionUtils.GetEnumerableType(type), (System.Collections.IEnumerable)value); + return EmitCreateArray(ReflectionUtils.GetEnumerableType(type)!, (System.Collections.IEnumerable)value); } throw new NotSupportedException($"Emitting value of type '{value.GetType().FullName}' is not supported."); } diff --git a/src/DotVVM.Framework/Compilation/Static/CompilationReport.cs b/src/DotVVM.Framework/Compilation/Static/CompilationReport.cs index 1e3dfe03bb..0cc58f3051 100644 --- a/src/DotVVM.Framework/Compilation/Static/CompilationReport.cs +++ b/src/DotVVM.Framework/Compilation/Static/CompilationReport.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/Static/ConfigurationInitializer.cs b/src/DotVVM.Framework/Compilation/Static/ConfigurationInitializer.cs index f66d113c07..04ae9c21f2 100644 --- a/src/DotVVM.Framework/Compilation/Static/ConfigurationInitializer.cs +++ b/src/DotVVM.Framework/Compilation/Static/ConfigurationInitializer.cs @@ -1,5 +1,4 @@ -#nullable enable - + using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Compilation/Static/DefaultCompilationReportLogger.cs b/src/DotVVM.Framework/Compilation/Static/DefaultCompilationReportLogger.cs index 78252033f6..50422b230a 100644 --- a/src/DotVVM.Framework/Compilation/Static/DefaultCompilationReportLogger.cs +++ b/src/DotVVM.Framework/Compilation/Static/DefaultCompilationReportLogger.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/Static/ICompilationReportLogger.cs b/src/DotVVM.Framework/Compilation/Static/ICompilationReportLogger.cs index 195d2f5281..062f0bf1ff 100644 --- a/src/DotVVM.Framework/Compilation/Static/ICompilationReportLogger.cs +++ b/src/DotVVM.Framework/Compilation/Static/ICompilationReportLogger.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Compilation/Static/StaticView.cs b/src/DotVVM.Framework/Compilation/Static/StaticView.cs index d5e7e4d06b..90839a7038 100644 --- a/src/DotVVM.Framework/Compilation/Static/StaticView.cs +++ b/src/DotVVM.Framework/Compilation/Static/StaticView.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/Static/StaticViewCompiler.cs b/src/DotVVM.Framework/Compilation/Static/StaticViewCompiler.cs index be5cc553f8..14a0df006f 100644 --- a/src/DotVVM.Framework/Compilation/Static/StaticViewCompiler.cs +++ b/src/DotVVM.Framework/Compilation/Static/StaticViewCompiler.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Compilation/Static/UnallowedConstantRemover.cs b/src/DotVVM.Framework/Compilation/Static/UnallowedConstantRemover.cs index c0c5dfa084..ba13147ec5 100644 --- a/src/DotVVM.Framework/Compilation/Static/UnallowedConstantRemover.cs +++ b/src/DotVVM.Framework/Compilation/Static/UnallowedConstantRemover.cs @@ -1,5 +1,4 @@ -#nullable enable - + using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; diff --git a/src/DotVVM.Framework/Compilation/Styles/CompileTimeStyleBase.cs b/src/DotVVM.Framework/Compilation/Styles/CompileTimeStyleBase.cs index ca7ba3c47c..919a571423 100644 --- a/src/DotVVM.Framework/Compilation/Styles/CompileTimeStyleBase.cs +++ b/src/DotVVM.Framework/Compilation/Styles/CompileTimeStyleBase.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using DotVVM.Framework.Binding; using DotVVM.Framework.Compilation.ControlTree.Resolved; diff --git a/src/DotVVM.Framework/Compilation/Styles/FunctionOrValue.cs b/src/DotVVM.Framework/Compilation/Styles/FunctionOrValue.cs index e9164171a7..0e60889aae 100644 --- a/src/DotVVM.Framework/Compilation/Styles/FunctionOrValue.cs +++ b/src/DotVVM.Framework/Compilation/Styles/FunctionOrValue.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Diagnostics.CodeAnalysis; diff --git a/src/DotVVM.Framework/Compilation/Styles/ResolvedControlHelper.cs b/src/DotVVM.Framework/Compilation/Styles/ResolvedControlHelper.cs index 9711f24456..6ed22e8142 100644 --- a/src/DotVVM.Framework/Compilation/Styles/ResolvedControlHelper.cs +++ b/src/DotVVM.Framework/Compilation/Styles/ResolvedControlHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; using DotVVM.Framework.Binding; @@ -56,7 +55,7 @@ public static ResolvedControl FromRuntimeControl( foreach (var pg in DotvvmPropertyGroup.GetPropertyGroups(type).Where(pg => pg.PropertyGroupMode == PropertyGroupMode.ValueCollection)) { - var dictionary = pg.PropertyInfo.GetValue(obj) as IDictionary; + var dictionary = pg.PropertyInfo!.GetValue(obj) as IDictionary; if (dictionary is null) continue; foreach (var p in dictionary) { diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleApplicator.cs b/src/DotVVM.Framework/Compilation/Styles/StyleApplicator.cs index f062ad1809..2a6c054681 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleApplicator.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleApplicator.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleBuilder.cs b/src/DotVVM.Framework/Compilation/Styles/StyleBuilder.cs index 2f7e09513e..25f1d01c5f 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleBuilder.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleBuilder.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq.Expressions; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.Helpers.cs b/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.Helpers.cs index d10a062e08..c25dbce60d 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.Helpers.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.Helpers.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Utils; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.cs b/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.cs index ac9357414b..f63877500b 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleBuilderMethods.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq.Expressions; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleMatchContext.cs b/src/DotVVM.Framework/Compilation/Styles/StyleMatchContext.cs index 043fa5ea17..e18a19dcb9 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleMatchContext.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleMatchContext.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleMatchContextMethods.cs b/src/DotVVM.Framework/Compilation/Styles/StyleMatchContextMethods.cs index 9e939cf4a5..14e2aed71f 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleMatchContextMethods.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleMatchContextMethods.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleMatcher.cs b/src/DotVVM.Framework/Compilation/Styles/StyleMatcher.cs index 9231138c91..2d59ff8d21 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleMatcher.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleMatcher.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Compilation.ControlTree.Resolved; @@ -9,6 +8,7 @@ using DotVVM.Framework.Configuration; using System.Linq.Expressions; using DotVVM.Framework.Controls; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.Styles { @@ -50,7 +50,7 @@ public void PopControl() public IEnumerable GetMatchingStyles() { - return GetStyleCandidatesForControl().Where(s => s.Matches(Context)).Select(s => s.Applicator); + return GetStyleCandidatesForControl().Where(s => s.Matches(Context.NotNull("not initialized"))).Select(s => s.Applicator); } protected IEnumerable GetStyleCandidatesForControl() diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleRepository.cs b/src/DotVVM.Framework/Compilation/Styles/StyleRepository.cs index 9f09affc04..2ce0b6a07d 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleRepository.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleRepository.cs @@ -38,7 +38,7 @@ public StyleMatcher CreateMatcher() /// If this function returns true, the style will be applied, otherwise not. /// Also allow classes that are derived from . /// A that can be used to style the control. - public StyleBuilder Register(Func, bool> matcher = null, bool allowDerived = true) + public StyleBuilder Register(Func, bool>? matcher = null, bool allowDerived = true) where T : DotvvmBindableObject { ThrowIfFrozen(); @@ -54,7 +54,7 @@ public StyleBuilder Register(Func, bool> matcher = nu /// If this function returns true, the style will be applied, otherwise not. /// Also allow classes that are derived from . /// A that can be used to style the control. - public StyleBuilder Register(Type type, Func matcher = null, bool allowDerived = true) + public StyleBuilder Register(Type type, Func? matcher = null, bool allowDerived = true) { ThrowIfFrozen(); var styleBuilder = new StyleBuilder(matcher, allowDerived); @@ -68,16 +68,16 @@ public StyleBuilder Register(Type type, FuncThe HTML tag the style is applied to. /// If this function returns true, the style will be applied, otherwise not. /// A that can be used to style the control. - public StyleBuilder Register(string tagName, Func, bool> matcher = null) + public StyleBuilder Register(string tagName, Func, bool>? matcher = null) { ThrowIfFrozen(); if (matcher != null) { - return Register(m => (string)m.Control.ConstructorParameters[0] == tagName && matcher(m), false); + return Register(m => (string)m.Control.ConstructorParameters![0] == tagName && matcher(m), false); } else { - return Register(m => (string)m.Control.ConstructorParameters[0] == tagName, false); + return Register(m => (string)m.Control.ConstructorParameters![0] == tagName, false); } } @@ -92,14 +92,14 @@ public StyleBuilder RegisterRoot() => /// Registers a server-side style for any component of type DotvvmControl (which is almost everything with exception of special objects like GridViewColumn) /// /// A that can be used to style the control. - public StyleBuilder RegisterAnyControl(Func, bool> matcher = null) => + public StyleBuilder RegisterAnyControl(Func, bool>? matcher = null) => Register(matcher); /// /// Registers a server-side style for any component (including special objects like GridViewColumn) /// /// A that can be used to style the control. - public StyleBuilder RegisterAnyObject(Func, bool> matcher = null) => + public StyleBuilder RegisterAnyObject(Func, bool>? matcher = null) => Register(matcher); private bool isFrozen = false; diff --git a/src/DotVVM.Framework/Compilation/Styles/StyleTreeShufflingVisitor.cs b/src/DotVVM.Framework/Compilation/Styles/StyleTreeShufflingVisitor.cs index ec49b79754..f93cc47ea3 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StyleTreeShufflingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StyleTreeShufflingVisitor.cs @@ -6,6 +6,7 @@ using DotVVM.Framework.Compilation.ControlTree; using DotVVM.Framework.Compilation.ControlTree.Resolved; using DotVVM.Framework.Controls; +using DotVVM.Framework.Utils; using static DotVVM.Framework.Controls.Styles; namespace DotVVM.Framework.Compilation.Styles @@ -42,6 +43,8 @@ public override void VisitControl(ResolvedControl control) public override void VisitPropertyControl(ResolvedPropertyControl propertyControl) { var control = propertyControl.Control; + if (control is null) + return; if (control.Properties.ContainsKey(AppendProperty) || control.Properties.ContainsKey(PrependProperty)) throw new Exception( @@ -130,7 +133,7 @@ ResolvedControl ProcessReplacement(ResolvedControl control) if (!control.Properties.TryGetValue(ReplaceWithProperty, out var setter)) return control; control.Properties.Remove(ReplaceWithProperty); - var newControl = ((ResolvedPropertyControl)setter).Control; + var newControl = ((ResolvedPropertyControl)setter).Control.NotNull(); // Copy content ResolvedControlHelper.SetContent(newControl, control.Content.ToArray(), StyleOverrideOptions.Append); diff --git a/src/DotVVM.Framework/Compilation/Styles/StylingVisitor.cs b/src/DotVVM.Framework/Compilation/Styles/StylingVisitor.cs index 1780ecc9b4..e272556499 100644 --- a/src/DotVVM.Framework/Compilation/Styles/StylingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/Styles/StylingVisitor.cs @@ -1,5 +1,6 @@ using DotVVM.Framework.Compilation.ControlTree.Resolved; using DotVVM.Framework.Configuration; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.Compilation.Styles { @@ -20,7 +21,7 @@ public override void VisitControl(ResolvedControl control) Matcher.PushControl(control); foreach (var style in Matcher.GetMatchingStyles()) { - style.ApplyStyle(control, Matcher.Context); + style.ApplyStyle(control, Matcher.Context.NotNull()); } base.VisitControl(control); Matcher.PopControl(); diff --git a/src/DotVVM.Framework/Compilation/Validation/ControlUsageError.cs b/src/DotVVM.Framework/Compilation/Validation/ControlUsageError.cs index a8befe9567..f4284de76a 100644 --- a/src/DotVVM.Framework/Compilation/Validation/ControlUsageError.cs +++ b/src/DotVVM.Framework/Compilation/Validation/ControlUsageError.cs @@ -8,11 +8,11 @@ public class ControlUsageError { public string ErrorMessage { get; } public DothtmlNode[] Nodes { get; } - public ControlUsageError(string message, IEnumerable nodes) + public ControlUsageError(string message, IEnumerable nodes) { ErrorMessage = message; - Nodes = nodes.Where(n => n != null).ToArray(); + Nodes = nodes.Where(n => n != null).ToArray()!; } - public ControlUsageError(string message, params DothtmlNode[] nodes) : this(message, (IEnumerable)nodes) { } + public ControlUsageError(string message, params DothtmlNode?[] nodes) : this(message, nodes.AsEnumerable()) { } } } diff --git a/src/DotVVM.Framework/Compilation/Validation/DefaultControlUsageValidator.cs b/src/DotVVM.Framework/Compilation/Validation/DefaultControlUsageValidator.cs index 01b579a689..bbf5e66545 100755 --- a/src/DotVVM.Framework/Compilation/Validation/DefaultControlUsageValidator.cs +++ b/src/DotVVM.Framework/Compilation/Validation/DefaultControlUsageValidator.cs @@ -20,7 +20,7 @@ public DefaultControlUsageValidator(DotvvmConfiguration config) public static ConcurrentDictionary cache = new ConcurrentDictionary(); - protected static DotvvmConfiguration Configuration { get; private set; } + protected DotvvmConfiguration Configuration { get; } public static IEnumerable ValidateDefaultRules(IAbstractControl control) { @@ -47,7 +47,7 @@ public static IEnumerable ValidateDefaultRules(IAbstractContr public IEnumerable Validate(IAbstractControl control) { var type = GetControlType(control.Metadata); - if (type == null) return null; + if (type == null) return Enumerable.Empty(); var result = new List(); result.AddRange(ValidateDefaultRules(control)); @@ -116,7 +116,7 @@ protected virtual MethodInfo[] FindMethods(Type type) return ancestorMethods.Concat(methods).ToArray(); } - protected virtual Type GetControlType(IControlResolverMetadata metadata) + protected virtual Type? GetControlType(IControlResolverMetadata metadata) { var type = metadata.Type as ResolvedTypeDescriptor; return type?.Type; diff --git a/src/DotVVM.Framework/Compilation/Validation/IControlUsageValidator.cs b/src/DotVVM.Framework/Compilation/Validation/IControlUsageValidator.cs index ec1bbd08a6..1486258c14 100644 --- a/src/DotVVM.Framework/Compilation/Validation/IControlUsageValidator.cs +++ b/src/DotVVM.Framework/Compilation/Validation/IControlUsageValidator.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using DotVVM.Framework.Compilation.ControlTree; namespace DotVVM.Framework.Compilation.Validation diff --git a/src/DotVVM.Framework/Compilation/ViewCompilingVisitor.cs b/src/DotVVM.Framework/Compilation/ViewCompilingVisitor.cs index 06a1977af2..80033a8ca1 100755 --- a/src/DotVVM.Framework/Compilation/ViewCompilingVisitor.cs +++ b/src/DotVVM.Framework/Compilation/ViewCompilingVisitor.cs @@ -24,8 +24,8 @@ public class ViewCompilingVisitor : ResolvedControlTreeVisitor protected int currentTemplateIndex; protected string className; - protected ControlResolverMetadata lastMetadata; - protected string controlName; + protected ControlResolverMetadata? lastMetadata; + protected string? controlName; public ViewCompilingVisitor(DefaultViewCompilerCodeEmitter emitter, CompiledAssemblyCache compiledAssemblyCache, IBindingCompiler bindingCompiler, string className) @@ -90,7 +90,7 @@ public override void VisitView(ResolvedTreeRoot view) emitter.PopMethod(); } - protected string EmitCreateControl(Type type, object[] arguments) + protected string EmitCreateControl(Type type, object[]? arguments) { // if marked with [RequireDependencyInjection] attribute, invoke injected factory if (type.GetCustomAttribute(typeof(DependencyInjection.RequireDependencyInjectionAttribute)) is DependencyInjection.RequireDependencyInjectionAttribute requireDiAttr) @@ -126,7 +126,7 @@ protected string EmitCreateControl(Type type, object[] arguments) /// public override void VisitControl(ResolvedControl node) { - var parentName = controlName; + var parentName = controlName.NotNull(); var localControlName = controlName = CreateControl(node); base.VisitControl(node); @@ -151,18 +151,18 @@ private void SetProperty(string controlName, DotvvmProperty property, Expression else emitter.EmitSetDotvvmProperty(controlName, property, value); } - private void SetPropertyValue(string controlName, DotvvmProperty property, object value) + private void SetPropertyValue(string controlName, DotvvmProperty property, object? value) => SetProperty(controlName, property, emitter.EmitValue(value)); public override void VisitPropertyValue(ResolvedPropertyValue propertyValue) { - SetPropertyValue(controlName, propertyValue.Property, propertyValue.Value); + SetPropertyValue(controlName.NotNull(), propertyValue.Property, propertyValue.Value); base.VisitPropertyValue(propertyValue); } public override void VisitPropertyBinding(ResolvedPropertyBinding propertyBinding) { - SetProperty(controlName, propertyBinding.Property, ProcessBinding(propertyBinding.Binding)); + SetProperty(controlName.NotNull(), propertyBinding.Property, ProcessBinding(propertyBinding.Binding)); base.VisitPropertyBinding(propertyBinding); } @@ -171,8 +171,8 @@ public override void VisitPropertyControl(ResolvedPropertyControl propertyContro if (propertyControl.Property is CompileTimeOnlyDotvvmProperty) return; - var control = propertyControl.Control; - var parentName = controlName; + var control = propertyControl.Control.NotNull(); + var parentName = controlName.NotNull(); controlName = CreateControl(control); // compile control content base.VisitControl(control); @@ -188,7 +188,7 @@ public override void VisitPropertyControlCollection(ResolvedPropertyControlColle if (propertyControlCollection.Property is CompileTimeOnlyDotvvmProperty) return; - var parentName = controlName; + var parentName = controlName.NotNull(); var collectionName = emitter.EmitEnsureCollectionInitialized(parentName, propertyControlCollection.Property); foreach (var control in propertyControlCollection.Controls) @@ -212,7 +212,7 @@ public override void VisitPropertyTemplate(ResolvedPropertyTemplate propertyTemp if (propertyTemplate.Property is CompileTimeOnlyDotvvmProperty) return; - var parentName = controlName; + var parentName = controlName.NotNull(); var methodName = DefaultViewCompilerCodeEmitter.BuildTemplateFunctionName + $"_{propertyTemplate.Property.DeclaringType.Name}_{propertyTemplate.Property.Name}_{currentTemplateIndex++}"; emitter.PushNewMethod(methodName, typeof(void), emitter.EmitControlBuilderParameters().Concat(new [] { emitter.EmitParameter("templateContainer", typeof(DotvvmControl))}).ToArray()); // build the statements diff --git a/src/DotVVM.Framework/Configuration/ConfigurationHelper.cs b/src/DotVVM.Framework/Configuration/ConfigurationHelper.cs index 210b9b5c8b..4bab11fb1e 100644 --- a/src/DotVVM.Framework/Configuration/ConfigurationHelper.cs +++ b/src/DotVVM.Framework/Configuration/ConfigurationHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Configuration/DefaultControlRegistrationStrategy.cs b/src/DotVVM.Framework/Configuration/DefaultControlRegistrationStrategy.cs index a3e59e829c..5ac3d1b336 100644 --- a/src/DotVVM.Framework/Configuration/DefaultControlRegistrationStrategy.cs +++ b/src/DotVVM.Framework/Configuration/DefaultControlRegistrationStrategy.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/DotVVM.Framework/Configuration/DefaultSerializerSettingsProvider.cs b/src/DotVVM.Framework/Configuration/DefaultSerializerSettingsProvider.cs index 5118a40fb0..ea499f8c8d 100644 --- a/src/DotVVM.Framework/Configuration/DefaultSerializerSettingsProvider.cs +++ b/src/DotVVM.Framework/Configuration/DefaultSerializerSettingsProvider.cs @@ -42,7 +42,7 @@ public static DefaultSerializerSettingsProvider Instance return instance; } } - private static DefaultSerializerSettingsProvider instance; + private static DefaultSerializerSettingsProvider? instance; private DefaultSerializerSettingsProvider() { diff --git a/src/DotVVM.Framework/Configuration/DotvvmConfiguration.cs b/src/DotVVM.Framework/Configuration/DotvvmConfiguration.cs index d525daad5c..441d261043 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmConfiguration.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -341,7 +340,7 @@ static void RegisterConstraints(DotvvmConfiguration configuration) private static void RegisterResources(DotvvmConfiguration configuration) { configuration.Resources.Register(ResourceConstants.PolyfillBundleResourceName, - new ScriptModuleResource(location: null, + new ScriptModuleResource(location: null!, nomoduleLocation: new EmbeddedResourceLocation( typeof(DotvvmConfiguration).Assembly, "DotVVM.Framework.obj.javascript.polyfill.bundle.js") diff --git a/src/DotVVM.Framework/Configuration/DotvvmConfigurationException.cs b/src/DotVVM.Framework/Configuration/DotvvmConfigurationException.cs index 6c06e65f55..0ed3e26192 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmConfigurationException.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmConfigurationException.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; diff --git a/src/DotVVM.Framework/Configuration/DotvvmControlConfiguration.cs b/src/DotVVM.Framework/Configuration/DotvvmControlConfiguration.cs index aa42419b19..f333eb220a 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmControlConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmControlConfiguration.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeatureFlag.cs b/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeatureFlag.cs index 835d3fb187..7f1cd7a86f 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeatureFlag.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeatureFlag.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.ComponentModel; @@ -84,9 +83,9 @@ public bool IsEnabledForAnyRoute() return Enabled || IncludedRoutes.Count > 0; } - public bool IsEnabledForRoute(string routeName) + public bool IsEnabledForRoute(string? routeName) { - return (Enabled && !ExcludedRoutes.Contains(routeName)) || (!Enabled && IncludedRoutes.Contains(routeName)); + return (Enabled && !ExcludedRoutes.Contains(routeName!)) || (!Enabled && IncludedRoutes.Contains(routeName!)); } private bool isFrozen = false; diff --git a/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeaturesConfiguration.cs b/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeaturesConfiguration.cs index c653ffdcfb..ca7a02b91b 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeaturesConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmExperimentalFeaturesConfiguration.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; diff --git a/src/DotVVM.Framework/Configuration/DotvvmGlobalExperimentalFeatureFlag.cs b/src/DotVVM.Framework/Configuration/DotvvmGlobalExperimentalFeatureFlag.cs index 0054f23c77..e49cfa14f7 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmGlobalExperimentalFeatureFlag.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmGlobalExperimentalFeatureFlag.cs @@ -1,5 +1,4 @@ -#nullable enable -using Newtonsoft.Json; +using Newtonsoft.Json; namespace DotVVM.Framework.Configuration { diff --git a/src/DotVVM.Framework/Configuration/DotvvmMarkupConfiguration.cs b/src/DotVVM.Framework/Configuration/DotvvmMarkupConfiguration.cs index 4044fecc1c..00defeedeb 100755 --- a/src/DotVVM.Framework/Configuration/DotvvmMarkupConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmMarkupConfiguration.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Configuration/DotvvmRuntimeConfiguration.cs b/src/DotVVM.Framework/Configuration/DotvvmRuntimeConfiguration.cs index 2cc4cd8afa..e024df0b94 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmRuntimeConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmRuntimeConfiguration.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Configuration/DotvvmSecurityConfiguration.cs b/src/DotVVM.Framework/Configuration/DotvvmSecurityConfiguration.cs index 41da263627..ac18448d61 100644 --- a/src/DotVVM.Framework/Configuration/DotvvmSecurityConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/DotvvmSecurityConfiguration.cs @@ -1,4 +1,3 @@ -#nullable enable using Newtonsoft.Json; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Configuration/FreezableDictionary.cs b/src/DotVVM.Framework/Configuration/FreezableDictionary.cs index bd37d6c510..5b1f937aba 100644 --- a/src/DotVVM.Framework/Configuration/FreezableDictionary.cs +++ b/src/DotVVM.Framework/Configuration/FreezableDictionary.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Configuration/FreezableList.cs b/src/DotVVM.Framework/Configuration/FreezableList.cs index 6eb3c203c1..492debefdd 100644 --- a/src/DotVVM.Framework/Configuration/FreezableList.cs +++ b/src/DotVVM.Framework/Configuration/FreezableList.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Configuration/FreezableSet.cs b/src/DotVVM.Framework/Configuration/FreezableSet.cs index 5652ea3722..600bf6be53 100644 --- a/src/DotVVM.Framework/Configuration/FreezableSet.cs +++ b/src/DotVVM.Framework/Configuration/FreezableSet.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Configuration/FreezableUtils.cs b/src/DotVVM.Framework/Configuration/FreezableUtils.cs index ec5f15151c..7ade12bc2a 100644 --- a/src/DotVVM.Framework/Configuration/FreezableUtils.cs +++ b/src/DotVVM.Framework/Configuration/FreezableUtils.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Configuration/HtmlAttributeTransformConfiguration.cs b/src/DotVVM.Framework/Configuration/HtmlAttributeTransformConfiguration.cs index 1afb8e66c3..0e9266e055 100644 --- a/src/DotVVM.Framework/Configuration/HtmlAttributeTransformConfiguration.cs +++ b/src/DotVVM.Framework/Configuration/HtmlAttributeTransformConfiguration.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using Newtonsoft.Json; diff --git a/src/DotVVM.Framework/Configuration/HtmlTagAttributePair.cs b/src/DotVVM.Framework/Configuration/HtmlTagAttributePair.cs index e9e0409c9e..f0860c895d 100644 --- a/src/DotVVM.Framework/Configuration/HtmlTagAttributePair.cs +++ b/src/DotVVM.Framework/Configuration/HtmlTagAttributePair.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Text.RegularExpressions; diff --git a/src/DotVVM.Framework/Configuration/IControlRegistrationStrategy.cs b/src/DotVVM.Framework/Configuration/IControlRegistrationStrategy.cs index b4723652fc..161c4680e6 100644 --- a/src/DotVVM.Framework/Configuration/IControlRegistrationStrategy.cs +++ b/src/DotVVM.Framework/Configuration/IControlRegistrationStrategy.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Configuration/IDotvvmServiceConfigurator.cs b/src/DotVVM.Framework/Configuration/IDotvvmServiceConfigurator.cs index 740fa20c36..668dd171e2 100644 --- a/src/DotVVM.Framework/Configuration/IDotvvmServiceConfigurator.cs +++ b/src/DotVVM.Framework/Configuration/IDotvvmServiceConfigurator.cs @@ -1,5 +1,4 @@ -#nullable enable -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; namespace DotVVM.Framework.Configuration { diff --git a/src/DotVVM.Framework/Configuration/IDotvvmStartup.cs b/src/DotVVM.Framework/Configuration/IDotvvmStartup.cs index 85603c0358..05febebea0 100644 --- a/src/DotVVM.Framework/Configuration/IDotvvmStartup.cs +++ b/src/DotVVM.Framework/Configuration/IDotvvmStartup.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Configuration/RestApiRegistrationHelpers.cs b/src/DotVVM.Framework/Configuration/RestApiRegistrationHelpers.cs index 33417d1548..78c5d5a3cc 100644 --- a/src/DotVVM.Framework/Configuration/RestApiRegistrationHelpers.cs +++ b/src/DotVVM.Framework/Configuration/RestApiRegistrationHelpers.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Linq; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Configuration/ServiceLocator.cs b/src/DotVVM.Framework/Configuration/ServiceLocator.cs index 4cca161d80..8b5126d0ba 100644 --- a/src/DotVVM.Framework/Configuration/ServiceLocator.cs +++ b/src/DotVVM.Framework/Configuration/ServiceLocator.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Diagnostics; using System.Reflection; diff --git a/src/DotVVM.Framework/Controls/AuthenticatedView.cs b/src/DotVVM.Framework/Controls/AuthenticatedView.cs index 4f493b6d00..05a1fba388 100644 --- a/src/DotVVM.Framework/Controls/AuthenticatedView.cs +++ b/src/DotVVM.Framework/Controls/AuthenticatedView.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using System; using System.Collections.Generic; using System.Text; diff --git a/src/DotVVM.Framework/Controls/Button.cs b/src/DotVVM.Framework/Controls/Button.cs index 30bf91d38b..12a91a383d 100644 --- a/src/DotVVM.Framework/Controls/Button.cs +++ b/src/DotVVM.Framework/Controls/Button.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Runtime; using System; diff --git a/src/DotVVM.Framework/Controls/ButtonBase.cs b/src/DotVVM.Framework/Controls/ButtonBase.cs index d9cacbbb2c..eba16d6d84 100644 --- a/src/DotVVM.Framework/Controls/ButtonBase.cs +++ b/src/DotVVM.Framework/Controls/ButtonBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/CheckBox.cs b/src/DotVVM.Framework/Controls/CheckBox.cs index e7010a85d5..803206fbe6 100644 --- a/src/DotVVM.Framework/Controls/CheckBox.cs +++ b/src/DotVVM.Framework/Controls/CheckBox.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -134,8 +133,8 @@ protected virtual void RenderCheckedProperty(IHtmlWriter writer) { yield return new ControlUsageError( $"Type of items in CheckedItems \'{to}\' must be same as CheckedValue type \'{from}\'.", - control.GetValue(CheckedItemsProperty).DothtmlNode, - control.GetValue(CheckedValueProperty).DothtmlNode + control.GetValue(CheckedItemsProperty)?.DothtmlNode, + control.GetValue(CheckedValueProperty)?.DothtmlNode ); } } diff --git a/src/DotVVM.Framework/Controls/CheckableControlBase.cs b/src/DotVVM.Framework/Controls/CheckableControlBase.cs index c3a415de47..abeb61b773 100644 --- a/src/DotVVM.Framework/Controls/CheckableControlBase.cs +++ b/src/DotVVM.Framework/Controls/CheckableControlBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Binding; @@ -77,7 +76,7 @@ public TextOrContentCapability TextOrContentCapability DotvvmCapabilityProperty.RegisterCapability("TextOrContentCapability", typeof(CheckableControlBase), typeof(TextOrContentCapability), control => TextOrContentCapability.FromChildren((CheckableControlBase)control, TextProperty), (control, boxedValue) => { - var value = (TextOrContentCapability)boxedValue; + var value = (TextOrContentCapability?)boxedValue ?? new TextOrContentCapability(); value.WriteToChildren((CheckableControlBase)control, TextProperty); } ); diff --git a/src/DotVVM.Framework/Controls/ClaimView.cs b/src/DotVVM.Framework/Controls/ClaimView.cs index c22d17c6e8..5eef5556bc 100644 --- a/src/DotVVM.Framework/Controls/ClaimView.cs +++ b/src/DotVVM.Framework/Controls/ClaimView.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Linq; using System.Security.Claims; diff --git a/src/DotVVM.Framework/Controls/ComboBox.cs b/src/DotVVM.Framework/Controls/ComboBox.cs index 00ea299dcf..320a475d9a 100644 --- a/src/DotVVM.Framework/Controls/ComboBox.cs +++ b/src/DotVVM.Framework/Controls/ComboBox.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/CompositeControl.cs b/src/DotVVM.Framework/Controls/CompositeControl.cs index 51acc29b14..5c5f2c3454 100644 Binary files a/src/DotVVM.Framework/Controls/CompositeControl.cs and b/src/DotVVM.Framework/Controls/CompositeControl.cs differ diff --git a/src/DotVVM.Framework/Controls/ConcurrencyQueueSetting.cs b/src/DotVVM.Framework/Controls/ConcurrencyQueueSetting.cs index 97ea39bb78..82beccd23a 100644 --- a/src/DotVVM.Framework/Controls/ConcurrencyQueueSetting.cs +++ b/src/DotVVM.Framework/Controls/ConcurrencyQueueSetting.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using System; namespace DotVVM.Framework.Controls { diff --git a/src/DotVVM.Framework/Controls/ConfigurableHtmlControl.cs b/src/DotVVM.Framework/Controls/ConfigurableHtmlControl.cs index e62419cc61..0e3fc2bc0a 100644 --- a/src/DotVVM.Framework/Controls/ConfigurableHtmlControl.cs +++ b/src/DotVVM.Framework/Controls/ConfigurableHtmlControl.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/ConfirmPostBackHandler.cs b/src/DotVVM.Framework/Controls/ConfirmPostBackHandler.cs index e0491fe813..4c365901f4 100644 --- a/src/DotVVM.Framework/Controls/ConfirmPostBackHandler.cs +++ b/src/DotVVM.Framework/Controls/ConfirmPostBackHandler.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/Content.cs b/src/DotVVM.Framework/Controls/Content.cs index 2b2b8c720e..c3c8d28063 100644 --- a/src/DotVVM.Framework/Controls/Content.cs +++ b/src/DotVVM.Framework/Controls/Content.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Controls/ContentPlaceHolder.cs b/src/DotVVM.Framework/Controls/ContentPlaceHolder.cs index 817bd02578..2fde63489a 100644 --- a/src/DotVVM.Framework/Controls/ContentPlaceHolder.cs +++ b/src/DotVVM.Framework/Controls/ContentPlaceHolder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Controls/ControlMarkupOptionsAttribute.cs b/src/DotVVM.Framework/Controls/ControlMarkupOptionsAttribute.cs index 6eb41c33b0..bf4f60a622 100644 --- a/src/DotVVM.Framework/Controls/ControlMarkupOptionsAttribute.cs +++ b/src/DotVVM.Framework/Controls/ControlMarkupOptionsAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/DataItemContainer.cs b/src/DotVVM.Framework/Controls/DataItemContainer.cs index bbcea12bce..6ba0c7bd61 100644 --- a/src/DotVVM.Framework/Controls/DataItemContainer.cs +++ b/src/DotVVM.Framework/Controls/DataItemContainer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Globalization; diff --git a/src/DotVVM.Framework/Controls/DataPager.cs b/src/DotVVM.Framework/Controls/DataPager.cs index b150315846..d2e231510d 100644 --- a/src/DotVVM.Framework/Controls/DataPager.cs +++ b/src/DotVVM.Framework/Controls/DataPager.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Concurrent; using System.Runtime.CompilerServices; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/Decorator.cs b/src/DotVVM.Framework/Controls/Decorator.cs index 5a9b16e198..0905f1d3f4 100644 --- a/src/DotVVM.Framework/Controls/Decorator.cs +++ b/src/DotVVM.Framework/Controls/Decorator.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/DelegateTemplate.cs b/src/DotVVM.Framework/Controls/DelegateTemplate.cs index 4d51b885ce..909a4f32f5 100644 --- a/src/DotVVM.Framework/Controls/DelegateTemplate.cs +++ b/src/DotVVM.Framework/Controls/DelegateTemplate.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/DotvvmBindableObject.cs b/src/DotVVM.Framework/Controls/DotvvmBindableObject.cs index 05b2bb7b7a..667caca9e8 100644 --- a/src/DotVVM.Framework/Controls/DotvvmBindableObject.cs +++ b/src/DotVVM.Framework/Controls/DotvvmBindableObject.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/DotvvmBindableObjectHelper.cs b/src/DotVVM.Framework/Controls/DotvvmBindableObjectHelper.cs index 3eb1e57ef3..00e0a41ffd 100644 --- a/src/DotVVM.Framework/Controls/DotvvmBindableObjectHelper.cs +++ b/src/DotVVM.Framework/Controls/DotvvmBindableObjectHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/DotvvmControl.cs b/src/DotVVM.Framework/Controls/DotvvmControl.cs index 975cc9098a..6b623a421d 100644 --- a/src/DotVVM.Framework/Controls/DotvvmControl.cs +++ b/src/DotVVM.Framework/Controls/DotvvmControl.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; using DotVVM.Framework.Controls.Infrastructure; diff --git a/src/DotVVM.Framework/Controls/DotvvmControlCollection.cs b/src/DotVVM.Framework/Controls/DotvvmControlCollection.cs index 6787e52ddb..d8c7cfbfe8 100644 --- a/src/DotVVM.Framework/Controls/DotvvmControlCollection.cs +++ b/src/DotVVM.Framework/Controls/DotvvmControlCollection.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/DotvvmControlException.cs b/src/DotVVM.Framework/Controls/DotvvmControlException.cs index 79c2787347..f903cc595a 100644 --- a/src/DotVVM.Framework/Controls/DotvvmControlException.cs +++ b/src/DotVVM.Framework/Controls/DotvvmControlException.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; namespace DotVVM.Framework.Controls { diff --git a/src/DotVVM.Framework/Controls/DotvvmControlProperties.cs b/src/DotVVM.Framework/Controls/DotvvmControlProperties.cs index 5bae16b5e0..bb38269544 100644 --- a/src/DotVVM.Framework/Controls/DotvvmControlProperties.cs +++ b/src/DotVVM.Framework/Controls/DotvvmControlProperties.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/DotvvmMarkupControl.cs b/src/DotVVM.Framework/Controls/DotvvmMarkupControl.cs index e895b10f73..07d5e24c84 100644 --- a/src/DotVVM.Framework/Controls/DotvvmMarkupControl.cs +++ b/src/DotVVM.Framework/Controls/DotvvmMarkupControl.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Controls/EmptyData.cs b/src/DotVVM.Framework/Controls/EmptyData.cs index ce1695ce57..dbfabeec80 100644 --- a/src/DotVVM.Framework/Controls/EmptyData.cs +++ b/src/DotVVM.Framework/Controls/EmptyData.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; using DotVVM.Framework.Binding.Properties; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Controls/EnvironmentView.cs b/src/DotVVM.Framework/Controls/EnvironmentView.cs index f15893c297..4f0a813f7d 100644 --- a/src/DotVVM.Framework/Controls/EnvironmentView.cs +++ b/src/DotVVM.Framework/Controls/EnvironmentView.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Linq; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/Events.cs b/src/DotVVM.Framework/Controls/Events.cs index 6b06012261..bc4863db0c 100644 --- a/src/DotVVM.Framework/Controls/Events.cs +++ b/src/DotVVM.Framework/Controls/Events.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/FileUpload.cs b/src/DotVVM.Framework/Controls/FileUpload.cs index 55e05af6b6..ade0096229 100644 --- a/src/DotVVM.Framework/Controls/FileUpload.cs +++ b/src/DotVVM.Framework/Controls/FileUpload.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Net; using System.Text; diff --git a/src/DotVVM.Framework/Controls/FormControls.cs b/src/DotVVM.Framework/Controls/FormControls.cs index a4d2e26c3a..d750b72cd0 100644 --- a/src/DotVVM.Framework/Controls/FormControls.cs +++ b/src/DotVVM.Framework/Controls/FormControls.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/GridView.cs b/src/DotVVM.Framework/Controls/GridView.cs index 9879ed2843..e9354391aa 100644 --- a/src/DotVVM.Framework/Controls/GridView.cs +++ b/src/DotVVM.Framework/Controls/GridView.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/GridViewCheckBoxColumn.cs b/src/DotVVM.Framework/Controls/GridViewCheckBoxColumn.cs index 1a79478aa1..112ed90b84 100644 --- a/src/DotVVM.Framework/Controls/GridViewCheckBoxColumn.cs +++ b/src/DotVVM.Framework/Controls/GridViewCheckBoxColumn.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Properties; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Controls/GridViewColumn.cs b/src/DotVVM.Framework/Controls/GridViewColumn.cs index 242b5caa22..5ea0576f19 100644 --- a/src/DotVVM.Framework/Controls/GridViewColumn.cs +++ b/src/DotVVM.Framework/Controls/GridViewColumn.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Hosting; using System; @@ -267,7 +266,7 @@ public static IEnumerable ValidateUsage(ResolvedControl contr if (!typeof(GridViewColumn).IsAssignableFrom(property.Key.DeclaringType)) { yield return new ControlUsageError($"The column doesn't support the property {property.Key.FullName}! If you need to set an attached property applied to a table cell, use the CellDecorators property.", - new[] { property.Value.DothtmlNode }.Where(n => n != null)); + property.Value.DothtmlNode); } } } diff --git a/src/DotVVM.Framework/Controls/GridViewTemplateColumn.cs b/src/DotVVM.Framework/Controls/GridViewTemplateColumn.cs index 02cbec0d63..04eec00f55 100644 --- a/src/DotVVM.Framework/Controls/GridViewTemplateColumn.cs +++ b/src/DotVVM.Framework/Controls/GridViewTemplateColumn.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Compilation.ControlTree.Resolved; using DotVVM.Framework.Compilation.Validation; diff --git a/src/DotVVM.Framework/Controls/GridViewTextColumn.cs b/src/DotVVM.Framework/Controls/GridViewTextColumn.cs index 3bada74a18..7ad74c31d9 100644 --- a/src/DotVVM.Framework/Controls/GridViewTextColumn.cs +++ b/src/DotVVM.Framework/Controls/GridViewTextColumn.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Hosting; using System; diff --git a/src/DotVVM.Framework/Controls/HtmlGenericControl.cs b/src/DotVVM.Framework/Controls/HtmlGenericControl.cs index 414d3f669c..f5bfb578c6 100644 --- a/src/DotVVM.Framework/Controls/HtmlGenericControl.cs +++ b/src/DotVVM.Framework/Controls/HtmlGenericControl.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; using DotVVM.Framework.Compilation; @@ -141,7 +140,7 @@ public HtmlCapability HtmlCapability CssStyles = VirtualPropertyGroupDictionary.CreatePropertyDictionary(control, CssStylesGroupDescriptor) }, (control, boxedValue) => { - var value = (HtmlCapability)boxedValue; + var value = (HtmlCapability?)boxedValue ?? new HtmlCapability(); control.SetValue(VisibleProperty, value.Visible); ((HtmlGenericControl)control).Attributes = value.Attributes.ToDictionary(t => t.Key, t => t.Value.BindingOrDefault ?? t.Value.BoxedValue); ((HtmlGenericControl)control).CssClasses.CopyFrom(value.CssClasses, clear: true); diff --git a/src/DotVVM.Framework/Controls/HtmlLiteral.cs b/src/DotVVM.Framework/Controls/HtmlLiteral.cs index c057ee5c1d..4517a15385 100644 --- a/src/DotVVM.Framework/Controls/HtmlLiteral.cs +++ b/src/DotVVM.Framework/Controls/HtmlLiteral.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Controls/HtmlWriter.cs b/src/DotVVM.Framework/Controls/HtmlWriter.cs index d092e317f2..5da29047cb 100644 --- a/src/DotVVM.Framework/Controls/HtmlWriter.cs +++ b/src/DotVVM.Framework/Controls/HtmlWriter.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/IControlWithHtmlAttributes.cs b/src/DotVVM.Framework/Controls/IControlWithHtmlAttributes.cs index da7fdc3d14..828ff7dc7b 100644 --- a/src/DotVVM.Framework/Controls/IControlWithHtmlAttributes.cs +++ b/src/DotVVM.Framework/Controls/IControlWithHtmlAttributes.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/IDotvvmControl.cs b/src/DotVVM.Framework/Controls/IDotvvmControl.cs index 8b3e421ca0..cd61e747b8 100644 --- a/src/DotVVM.Framework/Controls/IDotvvmControl.cs +++ b/src/DotVVM.Framework/Controls/IDotvvmControl.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using DotVVM.Framework.Hosting; using DotVVM.Framework.Runtime; using System; diff --git a/src/DotVVM.Framework/Controls/IEventValidationHandler.cs b/src/DotVVM.Framework/Controls/IEventValidationHandler.cs index 920a2bee36..9406a5ca6b 100644 --- a/src/DotVVM.Framework/Controls/IEventValidationHandler.cs +++ b/src/DotVVM.Framework/Controls/IEventValidationHandler.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/IHtmlAttributeTransformer.cs b/src/DotVVM.Framework/Controls/IHtmlAttributeTransformer.cs index 4e455867e9..10ccb62fa8 100644 --- a/src/DotVVM.Framework/Controls/IHtmlAttributeTransformer.cs +++ b/src/DotVVM.Framework/Controls/IHtmlAttributeTransformer.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Hosting; using DotVVM.Framework.Runtime; diff --git a/src/DotVVM.Framework/Controls/IHtmlWriter.cs b/src/DotVVM.Framework/Controls/IHtmlWriter.cs index 32ab7f9454..7f08fc9004 100644 --- a/src/DotVVM.Framework/Controls/IHtmlWriter.cs +++ b/src/DotVVM.Framework/Controls/IHtmlWriter.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/IRenderable.cs b/src/DotVVM.Framework/Controls/IRenderable.cs index d9f764e062..e0cf2bdded 100644 --- a/src/DotVVM.Framework/Controls/IRenderable.cs +++ b/src/DotVVM.Framework/Controls/IRenderable.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Text; diff --git a/src/DotVVM.Framework/Controls/ITemplate.cs b/src/DotVVM.Framework/Controls/ITemplate.cs index f16636df04..62bce70c22 100644 --- a/src/DotVVM.Framework/Controls/ITemplate.cs +++ b/src/DotVVM.Framework/Controls/ITemplate.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Hosting; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/Infrastructure/BodyResourceLinks.cs b/src/DotVVM.Framework/Controls/Infrastructure/BodyResourceLinks.cs index f2f68dabec..bcda823845 100644 --- a/src/DotVVM.Framework/Controls/Infrastructure/BodyResourceLinks.cs +++ b/src/DotVVM.Framework/Controls/Infrastructure/BodyResourceLinks.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Infrastructure/DotvvmView.cs b/src/DotVVM.Framework/Controls/Infrastructure/DotvvmView.cs index 7bfa5aba24..13cdcd2b1b 100644 --- a/src/DotVVM.Framework/Controls/Infrastructure/DotvvmView.cs +++ b/src/DotVVM.Framework/Controls/Infrastructure/DotvvmView.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Infrastructure/GlobalizeResource.cs b/src/DotVVM.Framework/Controls/Infrastructure/GlobalizeResource.cs index 49ea78aa32..3ea639f475 100644 --- a/src/DotVVM.Framework/Controls/Infrastructure/GlobalizeResource.cs +++ b/src/DotVVM.Framework/Controls/Infrastructure/GlobalizeResource.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Controls/Infrastructure/HeadResourceLinks.cs b/src/DotVVM.Framework/Controls/Infrastructure/HeadResourceLinks.cs index 947c0844d4..299d9156e2 100644 --- a/src/DotVVM.Framework/Controls/Infrastructure/HeadResourceLinks.cs +++ b/src/DotVVM.Framework/Controls/Infrastructure/HeadResourceLinks.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Infrastructure/RawLiteral.cs b/src/DotVVM.Framework/Controls/Infrastructure/RawLiteral.cs index 20c672052c..a777dd02eb 100644 --- a/src/DotVVM.Framework/Controls/Infrastructure/RawLiteral.cs +++ b/src/DotVVM.Framework/Controls/Infrastructure/RawLiteral.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Controls/InlineScript.cs b/src/DotVVM.Framework/Controls/InlineScript.cs index ec2ab5963f..014ba42af1 100644 --- a/src/DotVVM.Framework/Controls/InlineScript.cs +++ b/src/DotVVM.Framework/Controls/InlineScript.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Internal.cs b/src/DotVVM.Framework/Controls/Internal.cs index ccbfc5d5ec..3d4b61ba39 100644 --- a/src/DotVVM.Framework/Controls/Internal.cs +++ b/src/DotVVM.Framework/Controls/Internal.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Controls/ItemsControl.cs b/src/DotVVM.Framework/Controls/ItemsControl.cs index 9000de3f36..5c76590760 100644 --- a/src/DotVVM.Framework/Controls/ItemsControl.cs +++ b/src/DotVVM.Framework/Controls/ItemsControl.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using System; using System.Collections; diff --git a/src/DotVVM.Framework/Controls/KnockoutBindingGroup.cs b/src/DotVVM.Framework/Controls/KnockoutBindingGroup.cs index 3827040e3a..74390cae91 100644 --- a/src/DotVVM.Framework/Controls/KnockoutBindingGroup.cs +++ b/src/DotVVM.Framework/Controls/KnockoutBindingGroup.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/KnockoutHelper.cs b/src/DotVVM.Framework/Controls/KnockoutHelper.cs index 29f017a570..aeed069a65 100644 --- a/src/DotVVM.Framework/Controls/KnockoutHelper.cs +++ b/src/DotVVM.Framework/Controls/KnockoutHelper.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/LinkButton.cs b/src/DotVVM.Framework/Controls/LinkButton.cs index 6d312104e5..0be751d95c 100644 --- a/src/DotVVM.Framework/Controls/LinkButton.cs +++ b/src/DotVVM.Framework/Controls/LinkButton.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/ListBox.cs b/src/DotVVM.Framework/Controls/ListBox.cs index 004496265c..c6bb07b383 100644 --- a/src/DotVVM.Framework/Controls/ListBox.cs +++ b/src/DotVVM.Framework/Controls/ListBox.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Hosting; using DotVVM.Framework.Runtime; diff --git a/src/DotVVM.Framework/Controls/Literal.cs b/src/DotVVM.Framework/Controls/Literal.cs index 8b3c98ef19..6a626c0f6d 100644 --- a/src/DotVVM.Framework/Controls/Literal.cs +++ b/src/DotVVM.Framework/Controls/Literal.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Linq; using System.Net; @@ -24,7 +23,7 @@ public sealed class Literal : HtmlGenericControl /// public string Text { - get { return GetValue(TextProperty)?.ToString(); } + get { return GetValue(TextProperty)?.ToString() ?? ""; } set { SetValue(TextProperty, value); } } diff --git a/src/DotVVM.Framework/Controls/MarkupOptionsAttribute.cs b/src/DotVVM.Framework/Controls/MarkupOptionsAttribute.cs index a7ceac9a44..d371113d6d 100644 --- a/src/DotVVM.Framework/Controls/MarkupOptionsAttribute.cs +++ b/src/DotVVM.Framework/Controls/MarkupOptionsAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Compilation; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/MultiSelect.cs b/src/DotVVM.Framework/Controls/MultiSelect.cs index bc88220337..bd6629f172 100644 --- a/src/DotVVM.Framework/Controls/MultiSelect.cs +++ b/src/DotVVM.Framework/Controls/MultiSelect.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Controls { public class MultiSelect : MultiSelectHtmlControlBase diff --git a/src/DotVVM.Framework/Controls/MultiSelectHtmlControlBase.cs b/src/DotVVM.Framework/Controls/MultiSelectHtmlControlBase.cs index e148c3ae1f..acdcfa20ea 100644 --- a/src/DotVVM.Framework/Controls/MultiSelectHtmlControlBase.cs +++ b/src/DotVVM.Framework/Controls/MultiSelectHtmlControlBase.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Controls/MultiSelector.cs b/src/DotVVM.Framework/Controls/MultiSelector.cs index 40f86861f1..b0e0425041 100644 --- a/src/DotVVM.Framework/Controls/MultiSelector.cs +++ b/src/DotVVM.Framework/Controls/MultiSelector.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/NamedCommand.cs b/src/DotVVM.Framework/Controls/NamedCommand.cs index 664a6a0fac..9577f3f514 100644 --- a/src/DotVVM.Framework/Controls/NamedCommand.cs +++ b/src/DotVVM.Framework/Controls/NamedCommand.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Panel.cs b/src/DotVVM.Framework/Controls/Panel.cs index 31e9903da5..48b542b5bb 100644 --- a/src/DotVVM.Framework/Controls/Panel.cs +++ b/src/DotVVM.Framework/Controls/Panel.cs @@ -1,4 +1,3 @@ -#nullable enable using System; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/Placeholder.cs b/src/DotVVM.Framework/Controls/Placeholder.cs index c60bd8007d..e41c065c42 100644 --- a/src/DotVVM.Framework/Controls/Placeholder.cs +++ b/src/DotVVM.Framework/Controls/Placeholder.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Controls { /// diff --git a/src/DotVVM.Framework/Controls/PostBack.cs b/src/DotVVM.Framework/Controls/PostBack.cs index 2ed165df1d..34f1373096 100644 --- a/src/DotVVM.Framework/Controls/PostBack.cs +++ b/src/DotVVM.Framework/Controls/PostBack.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Linq; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/PostBackHandler.cs b/src/DotVVM.Framework/Controls/PostBackHandler.cs index 2dc6cd9c23..f8432bebb4 100644 --- a/src/DotVVM.Framework/Controls/PostBackHandler.cs +++ b/src/DotVVM.Framework/Controls/PostBackHandler.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using DotVVM.Framework.Binding; using DotVVM.Framework.ViewModel.Serialization; diff --git a/src/DotVVM.Framework/Controls/PostBackHandlerCollection.cs b/src/DotVVM.Framework/Controls/PostBackHandlerCollection.cs index 49c522103e..9c24912f65 100644 --- a/src/DotVVM.Framework/Controls/PostBackHandlerCollection.cs +++ b/src/DotVVM.Framework/Controls/PostBackHandlerCollection.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/PostbackScriptOptions.cs b/src/DotVVM.Framework/Controls/PostbackScriptOptions.cs index 53e17b22bd..f0e91900af 100644 --- a/src/DotVVM.Framework/Controls/PostbackScriptOptions.cs +++ b/src/DotVVM.Framework/Controls/PostbackScriptOptions.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Compilation.Javascript; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/PropertyImmutableHashtable.cs b/src/DotVVM.Framework/Controls/PropertyImmutableHashtable.cs index 75bb615523..b4356c11fa 100644 --- a/src/DotVVM.Framework/Controls/PropertyImmutableHashtable.cs +++ b/src/DotVVM.Framework/Controls/PropertyImmutableHashtable.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Controls/RadioButton.cs b/src/DotVVM.Framework/Controls/RadioButton.cs index ef3f50c812..db5c7a16f9 100644 --- a/src/DotVVM.Framework/Controls/RadioButton.cs +++ b/src/DotVVM.Framework/Controls/RadioButton.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Binding; using DotVVM.Framework.Compilation.ControlTree.Resolved; @@ -120,8 +119,8 @@ protected virtual void RenderCheckedAttribute(IHtmlWriter writer) yield return new ControlUsageError( $"CheckedItem type \'{to}\' must be the same as or a nullable " + $"variant of the CheckedValue type \'{from}\'.", - control.GetValue(CheckedItemProperty).DothtmlNode, - control.GetValue(CheckedValueProperty).DothtmlNode + control.GetValue(CheckedItemProperty)?.DothtmlNode, + control.GetValue(CheckedValueProperty)?.DothtmlNode ); } } diff --git a/src/DotVVM.Framework/Controls/RenderSettings.cs b/src/DotVVM.Framework/Controls/RenderSettings.cs index d509343c3a..3aebff39bf 100644 --- a/src/DotVVM.Framework/Controls/RenderSettings.cs +++ b/src/DotVVM.Framework/Controls/RenderSettings.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Repeater.cs b/src/DotVVM.Framework/Controls/Repeater.cs index d640ea52aa..5d00a5eacf 100644 --- a/src/DotVVM.Framework/Controls/Repeater.cs +++ b/src/DotVVM.Framework/Controls/Repeater.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; using DotVVM.Framework.Compilation.ControlTree.Resolved; diff --git a/src/DotVVM.Framework/Controls/RequiredResource.cs b/src/DotVVM.Framework/Controls/RequiredResource.cs index 966861292e..81c41b89b9 100644 --- a/src/DotVVM.Framework/Controls/RequiredResource.cs +++ b/src/DotVVM.Framework/Controls/RequiredResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/RoleView.cs b/src/DotVVM.Framework/Controls/RoleView.cs index 5587fcddff..98a9f4cde2 100644 --- a/src/DotVVM.Framework/Controls/RoleView.cs +++ b/src/DotVVM.Framework/Controls/RoleView.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Linq; using System.Security.Claims; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/RouteLink.cs b/src/DotVVM.Framework/Controls/RouteLink.cs index 984f516862..8186c99438 100644 --- a/src/DotVVM.Framework/Controls/RouteLink.cs +++ b/src/DotVVM.Framework/Controls/RouteLink.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -81,7 +80,7 @@ public TextOrContentCapability TextOrContentCapability DotvvmCapabilityProperty.RegisterCapability("TextOrContentCapability", typeof(RouteLink), typeof(TextOrContentCapability), control => TextOrContentCapability.FromChildren((RouteLink)control, TextProperty), (control, boxedValue) => { - var value = (TextOrContentCapability)boxedValue; + var value = (TextOrContentCapability?)boxedValue ?? new TextOrContentCapability(); value.WriteToChildren((DotvvmControl)control, TextProperty); } ); @@ -168,10 +167,9 @@ protected virtual void WriteOnClickAttribute(IHtmlWriter writer, IDotvvmRequestC public static IEnumerable ValidateUsage(ResolvedControl control, DotvvmConfiguration configuration) { var routeNameProperty = control.GetValue(RouteNameProperty); - if ((routeNameProperty.As()) == null) + if (routeNameProperty is not ResolvedPropertyValue { Value: string routeName }) yield break; - var routeName = (string)routeNameProperty.CastTo().Value!; if (!configuration.RouteTable.Contains(routeName)) { yield return new ControlUsageError( diff --git a/src/DotVVM.Framework/Controls/RouteLinkHelpers.cs b/src/DotVVM.Framework/Controls/RouteLinkHelpers.cs index 2339b66f89..98903eee33 100644 --- a/src/DotVVM.Framework/Controls/RouteLinkHelpers.cs +++ b/src/DotVVM.Framework/Controls/RouteLinkHelpers.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -83,7 +82,7 @@ private static string GenerateRouteUrlCore(string routeName, RouteLink control, foreach (var param in parameters.Where(p => p.Value is IStaticValueBinding).ToList()) { EnsureValidBindingType((IBinding)param.Value!); - parameters[param.Key] = ((IValueBinding)param.Value).Evaluate(control); // TODO: see below + parameters[param.Key] = ((IValueBinding)param.Value!).Evaluate(control); // TODO: see below } // generate the URL @@ -108,14 +107,7 @@ public static string GenerateKnockoutHrefExpression(string routeName, RouteLink var link = GenerateRouteLinkCore(routeName, control, context); var urlSuffix = GetUrlSuffixExpression(control); - if ((bool)control.GetValue(Internal.IsSpaPageProperty)! && !context.Configuration.UseHistoryApiSpaNavigation) - { - return $"'#!/' + {link}{(urlSuffix == null ? "" : " + " + urlSuffix)}"; - } - else - { - return $"'{context.TranslateVirtualPath("~/")}' + {link}{(urlSuffix == null ? "" : " + " + urlSuffix)}"; - } + return $"'{context.TranslateVirtualPath("~/")}' + {link}{(urlSuffix == null ? "" : " + " + urlSuffix)}"; } private static string? GetUrlSuffixExpression(RouteLink control) diff --git a/src/DotVVM.Framework/Controls/SelectHtmlControlBase.cs b/src/DotVVM.Framework/Controls/SelectHtmlControlBase.cs index e52377d982..74e63500d6 100644 --- a/src/DotVVM.Framework/Controls/SelectHtmlControlBase.cs +++ b/src/DotVVM.Framework/Controls/SelectHtmlControlBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/SelectHtmlControlHelpers.cs b/src/DotVVM.Framework/Controls/SelectHtmlControlHelpers.cs index 2b34fc96d7..87bf851508 100644 --- a/src/DotVVM.Framework/Controls/SelectHtmlControlHelpers.cs +++ b/src/DotVVM.Framework/Controls/SelectHtmlControlHelpers.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Properties; diff --git a/src/DotVVM.Framework/Controls/Selector.cs b/src/DotVVM.Framework/Controls/Selector.cs index 877ad1ee20..3116097105 100644 --- a/src/DotVVM.Framework/Controls/Selector.cs +++ b/src/DotVVM.Framework/Controls/Selector.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Utils; using DotVVM.Framework.Binding; using DotVVM.Framework.Compilation.ControlTree.Resolved; diff --git a/src/DotVVM.Framework/Controls/SelectorBase.cs b/src/DotVVM.Framework/Controls/SelectorBase.cs index 1186bfc0e8..9eb8207613 100644 --- a/src/DotVVM.Framework/Controls/SelectorBase.cs +++ b/src/DotVVM.Framework/Controls/SelectorBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/SelectorItem.cs b/src/DotVVM.Framework/Controls/SelectorItem.cs index e45407036c..3a52337e50 100644 --- a/src/DotVVM.Framework/Controls/SelectorItem.cs +++ b/src/DotVVM.Framework/Controls/SelectorItem.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/SpaContentPlaceHolder.cs b/src/DotVVM.Framework/Controls/SpaContentPlaceHolder.cs index 404308fc77..d32048b62a 100644 --- a/src/DotVVM.Framework/Controls/SpaContentPlaceHolder.cs +++ b/src/DotVVM.Framework/Controls/SpaContentPlaceHolder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Styles.cs b/src/DotVVM.Framework/Controls/Styles.cs index 4c4ecf73a6..1a651269c2 100644 --- a/src/DotVVM.Framework/Controls/Styles.cs +++ b/src/DotVVM.Framework/Controls/Styles.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using DotVVM.Framework.Binding; diff --git a/src/DotVVM.Framework/Controls/SuppressPostBackHandler.cs b/src/DotVVM.Framework/Controls/SuppressPostBackHandler.cs index 21d7e9a5f9..79ffcfd6ec 100644 --- a/src/DotVVM.Framework/Controls/SuppressPostBackHandler.cs +++ b/src/DotVVM.Framework/Controls/SuppressPostBackHandler.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using DotVVM.Framework.Binding; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/TableUtils.cs b/src/DotVVM.Framework/Controls/TableUtils.cs index 0ab74ee41e..5d5642f9fd 100644 --- a/src/DotVVM.Framework/Controls/TableUtils.cs +++ b/src/DotVVM.Framework/Controls/TableUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Binding; +using DotVVM.Framework.Binding; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/TemplateHost.cs b/src/DotVVM.Framework/Controls/TemplateHost.cs index 9639779170..c55b0c6e78 100644 --- a/src/DotVVM.Framework/Controls/TemplateHost.cs +++ b/src/DotVVM.Framework/Controls/TemplateHost.cs @@ -18,12 +18,12 @@ public class TemplateHost : DotvvmControl /// Gets or sets the template that will be rendered inside this control. /// [MarkupOptions(AllowBinding = false, MappingMode = MappingMode.Attribute, Required = true)] - public ITemplate ContentTemplate { get; set; } + public ITemplate? ContentTemplate { get; set; } protected internal override void OnLoad(IDotvvmRequestContext context) { - ContentTemplate.BuildContent(context, this); + ContentTemplate?.BuildContent(context, this); base.OnLoad(context); } } diff --git a/src/DotVVM.Framework/Controls/TextBox.cs b/src/DotVVM.Framework/Controls/TextBox.cs index 64a08e081a..5632db6efc 100644 --- a/src/DotVVM.Framework/Controls/TextBox.cs +++ b/src/DotVVM.Framework/Controls/TextBox.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Controls/TextBoxTypeExtensions.cs b/src/DotVVM.Framework/Controls/TextBoxTypeExtensions.cs index 0e832a8ab5..223f50fc26 100644 --- a/src/DotVVM.Framework/Controls/TextBoxTypeExtensions.cs +++ b/src/DotVVM.Framework/Controls/TextBoxTypeExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/TextOrContentCapability.cs b/src/DotVVM.Framework/Controls/TextOrContentCapability.cs index 998d654fd3..e0edc0d710 100644 --- a/src/DotVVM.Framework/Controls/TextOrContentCapability.cs +++ b/src/DotVVM.Framework/Controls/TextOrContentCapability.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; using DotVVM.Framework.Controls.Infrastructure; using DotVVM.Framework.Utils; diff --git a/src/DotVVM.Framework/Controls/TranslateVirtualPathHtmlAttributeTransformer.cs b/src/DotVVM.Framework/Controls/TranslateVirtualPathHtmlAttributeTransformer.cs index 11543920c7..eda30e284b 100644 --- a/src/DotVVM.Framework/Controls/TranslateVirtualPathHtmlAttributeTransformer.cs +++ b/src/DotVVM.Framework/Controls/TranslateVirtualPathHtmlAttributeTransformer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/UITests.cs b/src/DotVVM.Framework/Controls/UITests.cs index f4c5abd501..d004ef80bb 100644 --- a/src/DotVVM.Framework/Controls/UITests.cs +++ b/src/DotVVM.Framework/Controls/UITests.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Controls/UpdateProgress.cs b/src/DotVVM.Framework/Controls/UpdateProgress.cs index 67473b681a..9b24e217ea 100644 --- a/src/DotVVM.Framework/Controls/UpdateProgress.cs +++ b/src/DotVVM.Framework/Controls/UpdateProgress.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/UploadedFilesCollection.cs b/src/DotVVM.Framework/Controls/UploadedFilesCollection.cs index dbac76afb0..7539528c58 100644 --- a/src/DotVVM.Framework/Controls/UploadedFilesCollection.cs +++ b/src/DotVVM.Framework/Controls/UploadedFilesCollection.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using DotVVM.Core.Storage; diff --git a/src/DotVVM.Framework/Controls/Validation.cs b/src/DotVVM.Framework/Controls/Validation.cs index 4fae6442e3..7e65f30fd1 100644 --- a/src/DotVVM.Framework/Controls/Validation.cs +++ b/src/DotVVM.Framework/Controls/Validation.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Binding; namespace DotVVM.Framework.Controls diff --git a/src/DotVVM.Framework/Controls/ValidationSummary.cs b/src/DotVVM.Framework/Controls/ValidationSummary.cs index f7df58b73a..5c2d7c9b55 100644 --- a/src/DotVVM.Framework/Controls/ValidationSummary.cs +++ b/src/DotVVM.Framework/Controls/ValidationSummary.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Controls/Validator.cs b/src/DotVVM.Framework/Controls/Validator.cs index fcd6db766e..d27116a69d 100644 --- a/src/DotVVM.Framework/Controls/Validator.cs +++ b/src/DotVVM.Framework/Controls/Validator.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs b/src/DotVVM.Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs index 1a96687dcd..b2cb4ac24f 100644 --- a/src/DotVVM.Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs +++ b/src/DotVVM.Framework/DependencyInjection/DotVVMServiceCollectionExtensions.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/DependencyInjection/DotvvmBuilderExtensions.cs b/src/DotVVM.Framework/DependencyInjection/DotvvmBuilderExtensions.cs index 0fb2b743d2..53347d7227 100644 --- a/src/DotVVM.Framework/DependencyInjection/DotvvmBuilderExtensions.cs +++ b/src/DotVVM.Framework/DependencyInjection/DotvvmBuilderExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.IO; using DotVVM.Core.Storage; using DotVVM.Framework.Configuration; diff --git a/src/DotVVM.Framework/DependencyInjection/DotvvmServiceCollection.cs b/src/DotVVM.Framework/DependencyInjection/DotvvmServiceCollection.cs index 81a67960ad..9f94db1efb 100644 --- a/src/DotVVM.Framework/DependencyInjection/DotvvmServiceCollection.cs +++ b/src/DotVVM.Framework/DependencyInjection/DotvvmServiceCollection.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections; using System.Collections.Generic; using DotVVM.Framework.Configuration; diff --git a/src/DotVVM.Framework/DependencyInjection/IDotvvmServiceCollection.cs b/src/DotVVM.Framework/DependencyInjection/IDotvvmServiceCollection.cs index 2a4893d8e4..ac0354634f 100644 --- a/src/DotVVM.Framework/DependencyInjection/IDotvvmServiceCollection.cs +++ b/src/DotVVM.Framework/DependencyInjection/IDotvvmServiceCollection.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using DotVVM.Framework.Configuration; namespace Microsoft.Extensions.DependencyInjection diff --git a/src/DotVVM.Framework/DependencyInjection/RequireDependencyInjectionAttribute.cs b/src/DotVVM.Framework/DependencyInjection/RequireDependencyInjectionAttribute.cs index cae7972907..6ffe3cb075 100755 --- a/src/DotVVM.Framework/DependencyInjection/RequireDependencyInjectionAttribute.cs +++ b/src/DotVVM.Framework/DependencyInjection/RequireDependencyInjectionAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Linq; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Diagnostics/DiagnosticsRequestTracer.cs b/src/DotVVM.Framework/Diagnostics/DiagnosticsRequestTracer.cs index b662fe69bb..e156e0b028 100644 --- a/src/DotVVM.Framework/Diagnostics/DiagnosticsRequestTracer.cs +++ b/src/DotVVM.Framework/Diagnostics/DiagnosticsRequestTracer.cs @@ -38,12 +38,11 @@ public Task TraceEvent(string eventName, IDotvvmRequestContext context) private EventTiming CreateEventTiming(string eventName) { - return new EventTiming - { - Duration = stopwatch.ElapsedMilliseconds - ElapsedMillisSinceLastLog, - TotalDuration = stopwatch.ElapsedMilliseconds, - EventName = eventName - }; + return new EventTiming( + eventName, + stopwatch.ElapsedMilliseconds - ElapsedMillisSinceLastLog, + stopwatch.ElapsedMilliseconds + ); } public Task EndRequest(IDotvvmRequestContext context) @@ -77,26 +76,23 @@ private void Reset() private DiagnosticsInformation BuildDiagnosticsData(IDotvvmRequestContext request) { - return new DiagnosticsInformation - { - RequestDiagnostics = BuildRequestDiagnostics(request), - ResponseDiagnostics = BuildResponseDiagnostics(request), - EventTimings = events, - TotalDuration = stopwatch.ElapsedMilliseconds - }; + return new DiagnosticsInformation( + BuildRequestDiagnostics(request), + BuildResponseDiagnostics(request), + events, + stopwatch.ElapsedMilliseconds + ); } private RequestDiagnostics BuildRequestDiagnostics(IDotvvmRequestContext request) { - return new RequestDiagnostics - { - RequestType = RequestTypeFromContext(request), - Method = request.HttpContext.Request.Method, - Url = request.HttpContext.Request.Url.AbsolutePath, - Headers = request.HttpContext.Request.Headers.Select(HttpHeaderItem.FromKeyValuePair) - .ToList(), - ViewModelJson = request.ReceivedViewModelJson?.GetValue("viewModel")?.ToString() - }; + return new RequestDiagnostics( + RequestTypeFromContext(request), + request.HttpContext.Request.Method, + request.HttpContext.Request.Url.AbsolutePath, + request.HttpContext.Request.Headers.Select(HttpHeaderItem.FromKeyValuePair), + request.ReceivedViewModelJson?.GetValue("viewModel")?.ToString() + ); } private RequestType RequestTypeFromContext(IDotvvmRequestContext context) @@ -130,4 +126,4 @@ private ResponseDiagnostics BuildResponseDiagnostics(IDotvvmRequestContext reque } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Diagnostics/DiagnosticsServerConfiguration.cs b/src/DotVVM.Framework/Diagnostics/DiagnosticsServerConfiguration.cs index 5c31888a9e..bd3f792629 100644 --- a/src/DotVVM.Framework/Diagnostics/DiagnosticsServerConfiguration.cs +++ b/src/DotVVM.Framework/Diagnostics/DiagnosticsServerConfiguration.cs @@ -9,10 +9,10 @@ namespace DotVVM.Framework.Diagnostics public class DiagnosticsServerConfiguration { [JsonIgnore] - public static string DiagnosticsFilePath => Environment.GetEnvironmentVariable("TEMP") is string tmpPath ? Path.Combine(tmpPath, "DotVVM/diagnosticsConfiguration.json") : null; + public static string? DiagnosticsFilePath => Environment.GetEnvironmentVariable("TEMP") is string tmpPath ? Path.Combine(tmpPath, "DotVVM/diagnosticsConfiguration.json") : null; - public string HostName { get; set; } + public string? HostName { get; set; } public int Port { get; set; } } diff --git a/src/DotVVM.Framework/Diagnostics/DiagnosticsStartupTracer.cs b/src/DotVVM.Framework/Diagnostics/DiagnosticsStartupTracer.cs index 4982d61ac7..922b5aa8cb 100644 --- a/src/DotVVM.Framework/Diagnostics/DiagnosticsStartupTracer.cs +++ b/src/DotVVM.Framework/Diagnostics/DiagnosticsStartupTracer.cs @@ -20,7 +20,7 @@ public class DiagnosticsStartupTracer : IStartupTracer private long ElapsedMillisecondsSinceLastLog => events.Sum(e => e.Duration); - private event Func LateInfoReported; + private event Func? LateInfoReported; public void TraceEvent(string eventName) { @@ -67,23 +67,27 @@ private EventTiming CreateEventTiming(string eventName) { var elapsedMilliseconds = stopwatch.ElapsedMilliseconds; - return new EventTiming { - Duration = elapsedMilliseconds - ElapsedMillisecondsSinceLastLog, - TotalDuration = elapsedMilliseconds, - EventName = eventName - }; + return new EventTiming( + eventName, + elapsedMilliseconds - ElapsedMillisecondsSinceLastLog, + elapsedMilliseconds + ); } private DiagnosticsInformation BuildDiagnosticsInformation(IList eventTimings) { - return new DiagnosticsInformation() { - RequestDiagnostics = new RequestDiagnostics() { - Url = "{APPLICATION_STARTUP}" - }, - ResponseDiagnostics = new ResponseDiagnostics(), - EventTimings = eventTimings, - TotalDuration = stopwatch.ElapsedMilliseconds - }; + return new DiagnosticsInformation( + new RequestDiagnostics( + RequestType.Init, + "", + "{APPLICATION_STARTUP}", + Enumerable.Empty(), + null + ), + new ResponseDiagnostics(), + eventTimings, + stopwatch.ElapsedMilliseconds + ); } } } diff --git a/src/DotVVM.Framework/Diagnostics/DotvvmDiagnosticsConfiguration.cs b/src/DotVVM.Framework/Diagnostics/DotvvmDiagnosticsConfiguration.cs index fe3f8543a9..289e2630ab 100644 --- a/src/DotVVM.Framework/Diagnostics/DotvvmDiagnosticsConfiguration.cs +++ b/src/DotVVM.Framework/Diagnostics/DotvvmDiagnosticsConfiguration.cs @@ -10,10 +10,10 @@ namespace DotVVM.Framework.Diagnostics public class DotvvmDiagnosticsConfiguration { - private DiagnosticsServerConfiguration configuration; + private DiagnosticsServerConfiguration? configuration; private DateTime configurationLastWriteTimeUtc; - public string GetDiagnosticsServerHostname() + public string? GetDiagnosticsServerHostname() { RefreshConfiguration(); return configuration?.HostName; diff --git a/src/DotVVM.Framework/Diagnostics/Models/DiagnosticsInformation.cs b/src/DotVVM.Framework/Diagnostics/Models/DiagnosticsInformation.cs index d90f27c627..5d47506171 100644 --- a/src/DotVVM.Framework/Diagnostics/Models/DiagnosticsInformation.cs +++ b/src/DotVVM.Framework/Diagnostics/Models/DiagnosticsInformation.cs @@ -9,6 +9,14 @@ namespace DotVVM.Framework.Diagnostics.Models public class DiagnosticsInformation { + public DiagnosticsInformation(RequestDiagnostics requestDiagnostics, ResponseDiagnostics responseDiagnostics, IList eventTimings, long totalDuration) + { + RequestDiagnostics = requestDiagnostics; + ResponseDiagnostics = responseDiagnostics; + EventTimings = eventTimings; + TotalDuration = totalDuration; + } + public RequestDiagnostics RequestDiagnostics { get; set; } public ResponseDiagnostics ResponseDiagnostics { get; set; } public IList EventTimings { get; set; } diff --git a/src/DotVVM.Framework/Diagnostics/Models/EventTiming.cs b/src/DotVVM.Framework/Diagnostics/Models/EventTiming.cs index 2e4d59e3dc..23f4868bd5 100644 --- a/src/DotVVM.Framework/Diagnostics/Models/EventTiming.cs +++ b/src/DotVVM.Framework/Diagnostics/Models/EventTiming.cs @@ -2,9 +2,16 @@ namespace DotVVM.Framework.Diagnostics.Models { public class EventTiming { + public EventTiming(string eventName, long duration, long totalDuration) + { + EventName = eventName; + Duration = duration; + TotalDuration = totalDuration; + } + public string EventName { get; set; } public long Duration { get; set; } public long TotalDuration { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Diagnostics/Models/HttpHeaderItem.cs b/src/DotVVM.Framework/Diagnostics/Models/HttpHeaderItem.cs index f515d62c56..0f45f056a5 100644 --- a/src/DotVVM.Framework/Diagnostics/Models/HttpHeaderItem.cs +++ b/src/DotVVM.Framework/Diagnostics/Models/HttpHeaderItem.cs @@ -4,16 +4,18 @@ namespace DotVVM.Framework.Diagnostics.Models { public class HttpHeaderItem { + public HttpHeaderItem(string key, string value) + { + Key = key; + Value = value; + } + public string Key { get; set; } public string Value { get; set; } public static HttpHeaderItem FromKeyValuePair(KeyValuePair pair) { - return new HttpHeaderItem - { - Key = pair.Key, - Value = string.Join("; ", pair.Value) - }; + return new HttpHeaderItem(pair.Key, string.Join("; ", pair.Value)); } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Diagnostics/Models/RequestDiagnostics.cs b/src/DotVVM.Framework/Diagnostics/Models/RequestDiagnostics.cs index 23a3d54004..e300f6b5d9 100644 --- a/src/DotVVM.Framework/Diagnostics/Models/RequestDiagnostics.cs +++ b/src/DotVVM.Framework/Diagnostics/Models/RequestDiagnostics.cs @@ -7,6 +7,7 @@ namespace DotVVM.Framework.Diagnostics.Models public enum RequestType { + Init, Get, Command, StaticCommand @@ -14,10 +15,19 @@ public enum RequestType public class RequestDiagnostics { + public RequestDiagnostics(RequestType requestType, string method, string url, IEnumerable headers, string? viewModelJson) + { + RequestType = requestType; + Method = method; + Url = url; + Headers = headers.ToList(); + ViewModelJson = viewModelJson; + } + public RequestType RequestType { get; set; } public string Method { get; set; } public string Url { get; set; } public IList Headers { get; set; } - public string ViewModelJson { get; set; } + public string? ViewModelJson { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Diagnostics/Models/ResponseDiagnostics.cs b/src/DotVVM.Framework/Diagnostics/Models/ResponseDiagnostics.cs index 7b2f73468f..b45a90b9d1 100644 --- a/src/DotVVM.Framework/Diagnostics/Models/ResponseDiagnostics.cs +++ b/src/DotVVM.Framework/Diagnostics/Models/ResponseDiagnostics.cs @@ -8,11 +8,11 @@ namespace DotVVM.Framework.Diagnostics.Models public class ResponseDiagnostics { public int StatusCode { get; set; } - public IList Headers { get; set; } - public string ViewModelJson { get; set; } - public string ViewModelDiff { get; set; } + public IList? Headers { get; set; } + public string? ViewModelJson { get; set; } + public string? ViewModelDiff { get; set; } public long ResponseSize { get; set; } public long CompressedResponseSize { get; set; } - public string ExceptionStackTrace { get; set; } + public string? ExceptionStackTrace { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/DotVVM.Framework.csproj b/src/DotVVM.Framework/DotVVM.Framework.csproj index 9a5cebf2ed..90aa8128a1 100644 --- a/src/DotVVM.Framework/DotVVM.Framework.csproj +++ b/src/DotVVM.Framework/DotVVM.Framework.csproj @@ -26,7 +26,7 @@ false true 9.0 - + enable diff --git a/src/DotVVM.Framework/Hosting/AggregateMarkupFileLoader.cs b/src/DotVVM.Framework/Hosting/AggregateMarkupFileLoader.cs index 9a1e834d1b..49427fcfba 100644 --- a/src/DotVVM.Framework/Hosting/AggregateMarkupFileLoader.cs +++ b/src/DotVVM.Framework/Hosting/AggregateMarkupFileLoader.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Hosting/CustomResponsePropertiesManager.cs b/src/DotVVM.Framework/Hosting/CustomResponsePropertiesManager.cs index 49b4b8c1fd..e629ff3a7d 100644 --- a/src/DotVVM.Framework/Hosting/CustomResponsePropertiesManager.cs +++ b/src/DotVVM.Framework/Hosting/CustomResponsePropertiesManager.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; namespace DotVVM.Framework.Hosting diff --git a/src/DotVVM.Framework/Hosting/DefaultMarkupFileLoader.cs b/src/DotVVM.Framework/Hosting/DefaultMarkupFileLoader.cs index 8827155940..d97d2ce1d9 100644 --- a/src/DotVVM.Framework/Hosting/DefaultMarkupFileLoader.cs +++ b/src/DotVVM.Framework/Hosting/DefaultMarkupFileLoader.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Hosting/DotvvmFileStorageMissingException.cs b/src/DotVVM.Framework/Hosting/DotvvmFileStorageMissingException.cs index fa898d7e08..3c0da504a1 100644 --- a/src/DotVVM.Framework/Hosting/DotvvmFileStorageMissingException.cs +++ b/src/DotVVM.Framework/Hosting/DotvvmFileStorageMissingException.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; namespace DotVVM.Framework.Hosting { diff --git a/src/DotVVM.Framework/Hosting/DotvvmHttpException.cs b/src/DotVVM.Framework/Hosting/DotvvmHttpException.cs index f26fbf4bdf..35cd6ac29c 100644 --- a/src/DotVVM.Framework/Hosting/DotvvmHttpException.cs +++ b/src/DotVVM.Framework/Hosting/DotvvmHttpException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Hosting/DotvvmInterruptRequestExecutionException.cs b/src/DotVVM.Framework/Hosting/DotvvmInterruptRequestExecutionException.cs index 21886d73e4..524ef2ea70 100644 --- a/src/DotVVM.Framework/Hosting/DotvvmInterruptRequestExecutionException.cs +++ b/src/DotVVM.Framework/Hosting/DotvvmInterruptRequestExecutionException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Hosting/DotvvmPresenter.cs b/src/DotVVM.Framework/Hosting/DotvvmPresenter.cs index f4172eae22..931ae361df 100644 --- a/src/DotVVM.Framework/Hosting/DotvvmPresenter.cs +++ b/src/DotVVM.Framework/Hosting/DotvvmPresenter.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; @@ -232,12 +231,12 @@ public async Task ProcessRequestCore(IDotvvmRequestContext context) await requestTracer.TraceEvent(RequestTracingConstants.LoadCompleted, context); // invoke the postback command - var actionInfo = ViewModelSerializer.ResolveCommand(context, page); + var actionInfo = ViewModelSerializer.ResolveCommand(context, page).NotNull("Command not found?"); // get filters var methodFilters = context.Configuration.Runtime.GlobalFilters.OfType() .Concat(ActionFilterHelper.GetActionFilters(context.ViewModel.GetType())); - if (actionInfo.Binding.GetProperty(ErrorHandlingMode.ReturnNull) is ActionFiltersBindingProperty filters) + if (actionInfo.Binding?.GetProperty(ErrorHandlingMode.ReturnNull) is ActionFiltersBindingProperty filters) methodFilters = methodFilters.Concat(filters.Filters.OfType()); commandResult = await ExecuteCommand(actionInfo, context, methodFilters); @@ -257,7 +256,7 @@ public async Task ProcessRequestCore(IDotvvmRequestContext context) await requestTracer.TraceEvent(RequestTracingConstants.PreRenderCompleted, context); // generate CSRF token if required - if (string.IsNullOrEmpty(context.CsrfToken) && !context.Configuration.ExperimentalFeatures.LazyCsrfToken.IsEnabledForRoute(context.Route!.RouteName)) + if (string.IsNullOrEmpty(context.CsrfToken) && !context.Configuration.ExperimentalFeatures.LazyCsrfToken.IsEnabledForRoute(context.Route?.RouteName)) { context.CsrfToken = CsrfProtector.GenerateToken(context); } @@ -330,14 +329,14 @@ public async Task ProcessRequestCore(IDotvvmRequestContext context) private object? ExecuteStaticCommandPlan(StaticCommandInvocationPlan plan, Queue arguments, IDotvvmRequestContext context) { var methodArgs = plan.Arguments.Select((a, index) => - a.Type == StaticCommandParameterType.Argument ? arguments.Dequeue().ToObject((Type)a.Arg) : + a.Type == StaticCommandParameterType.Argument ? arguments.Dequeue().ToObject((Type)a.Arg!) : a.Type == StaticCommandParameterType.Constant || a.Type == StaticCommandParameterType.DefaultValue ? a.Arg : a.Type == StaticCommandParameterType.Inject ? #pragma warning disable CS0618 - StaticCommandServiceLoader.GetStaticCommandService((Type)a.Arg, context) : + StaticCommandServiceLoader.GetStaticCommandService((Type)a.Arg!, context) : #pragma warning restore CS0618 - a.Type == StaticCommandParameterType.Invocation ? ExecuteStaticCommandPlan((StaticCommandInvocationPlan)a.Arg, arguments, context) : + a.Type == StaticCommandParameterType.Invocation ? ExecuteStaticCommandPlan((StaticCommandInvocationPlan)a.Arg!, arguments, context) : throw new NotSupportedException("" + a.Type) ).ToArray(); return plan.Method.Invoke(plan.Method.IsStatic ? null : methodArgs.First(), plan.Method.IsStatic ? methodArgs : methodArgs.Skip(1).ToArray()); @@ -363,10 +362,11 @@ public async Task ProcessStaticCommandRequest(IDotvvmRequestContext context) StaticCommandExecutionPlanSerializer.DecryptJson(Convert.FromBase64String(command), context.Services.GetRequiredService()) .Apply(StaticCommandExecutionPlanSerializer.DeserializePlan); - var actionInfo = new ActionInfo { - IsControlCommand = false, - Action = () => { return ExecuteStaticCommandPlan(executionPlan, new Queue(arguments.NotNull()), context); } - }; + var actionInfo = new ActionInfo( + binding: null, + () => { return ExecuteStaticCommandPlan(executionPlan, new Queue(arguments.NotNull()), context); }, + false + ); var filters = context.Configuration.Runtime.GlobalFilters.OfType() .Concat(executionPlan.GetAllMethods().SelectMany(m => ActionFilterHelper.GetActionFilters(m))) .ToArray(); diff --git a/src/DotVVM.Framework/Hosting/DotvvmRequestContext.cs b/src/DotVVM.Framework/Hosting/DotvvmRequestContext.cs index 97bd1f9b6d..833a2ef879 100644 --- a/src/DotVVM.Framework/Hosting/DotvvmRequestContext.cs +++ b/src/DotVVM.Framework/Hosting/DotvvmRequestContext.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Hosting/DotvvmRequestContextExtensions.cs b/src/DotVVM.Framework/Hosting/DotvvmRequestContextExtensions.cs index 68f622e540..f08a77595d 100644 --- a/src/DotVVM.Framework/Hosting/DotvvmRequestContextExtensions.cs +++ b/src/DotVVM.Framework/Hosting/DotvvmRequestContextExtensions.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Globalization; diff --git a/src/DotVVM.Framework/Hosting/EmbeddedMarkupFileLoader.cs b/src/DotVVM.Framework/Hosting/EmbeddedMarkupFileLoader.cs index 2909facd7f..2abaeb0017 100644 --- a/src/DotVVM.Framework/Hosting/EmbeddedMarkupFileLoader.cs +++ b/src/DotVVM.Framework/Hosting/EmbeddedMarkupFileLoader.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.IO; using System.Reflection; diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/DictionarySection.cs b/src/DotVVM.Framework/Hosting/ErrorPages/DictionarySection.cs index 761e61d140..0ce9fb25ff 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/DictionarySection.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/DictionarySection.cs @@ -13,25 +13,19 @@ public class DictionarySection : IErrorSectionFormatter public IEnumerable Keys { get; set; } public IEnumerable Values { get; set; } - public DictionarySection(string name, string id) + public DictionarySection(string name, string id, IEnumerable keys, IEnumerable values) { DisplayName = name; Id = id; + Keys = keys; + Values = values; } public static DictionarySection Create(string name, string id, IDictionary dictionary) - => new DictionarySection(name, id) - { - Keys = dictionary.Keys, - Values = dictionary.Values - }; + => new DictionarySection(name, id, dictionary.Keys, dictionary.Values); public static DictionarySection Create(string name, string id, IEnumerable> kvps) - => new DictionarySection(name, id) - { - Keys = kvps.Select(kvp => kvp.Key).ToArray(), - Values = kvps.Select(kvp => kvp.Value).ToArray() - }; + => new DictionarySection(name, id, kvps.Select(kvp => kvp.Key), kvps.Select(kvp => kvp.Value)); public void WriteBody(IErrorWriter writer) { @@ -42,4 +36,4 @@ public void WriteHead(IErrorWriter writer) { } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmErrorPageRenderer.cs b/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmErrorPageRenderer.cs index c29eb10b01..dbbcc019b3 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmErrorPageRenderer.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmErrorPageRenderer.cs @@ -12,7 +12,7 @@ namespace DotVVM.Framework.Hosting.ErrorPages public class DotvvmErrorPageRenderer { - public ErrorFormatter Formatter { get; set; } + public ErrorFormatter? Formatter { get; set; } /// /// Renders the error response. diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmMarkupErrorSection.cs b/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmMarkupErrorSection.cs index 4ff3c45903..5d5237bcdd 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmMarkupErrorSection.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/DotvvmMarkupErrorSection.cs @@ -45,7 +45,7 @@ protected virtual void WriteException(IErrorWriter w, Exception exc) w.WriteUnencoded("
"); } - public virtual SourceModel ExtractSource(Exception exc) + public virtual SourceModel? ExtractSource(Exception exc) { if (exc is DotvvmCompilationException) { @@ -65,7 +65,7 @@ public virtual SourceModel ExtractSource(Exception exc) return null; } - private SourceModel ExtractSourceFromDotvvmCompilationException(DotvvmCompilationException compilationException) + private SourceModel? ExtractSourceFromDotvvmCompilationException(DotvvmCompilationException compilationException) { if (compilationException.Tokens != null && compilationException.Tokens.Any()) { @@ -88,7 +88,7 @@ private SourceModel ExtractSourceFromDotvvmCompilationException(DotvvmCompilatio return null; } - private SourceModel ExtractSourceFromBindingCompilationException(BindingCompilationException bce) + private SourceModel? ExtractSourceFromBindingCompilationException(BindingCompilationException bce) { if (bce.Expression != null) { @@ -124,7 +124,7 @@ private SourceModel CreateAnonymousLine(string line, int column = 0, int length public void WriteHead(IErrorWriter w) { } - public static DotvvmMarkupErrorSection Create(Exception ex) + public static DotvvmMarkupErrorSection? Create(Exception ex) { var iex = ex; while (iex != null) diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/ErrorFormatter.cs b/src/DotVVM.Framework/Hosting/ErrorPages/ErrorFormatter.cs index 92f3048a62..b7b530abda 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/ErrorFormatter.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/ErrorFormatter.cs @@ -18,44 +18,47 @@ namespace DotVVM.Framework.Hosting.ErrorPages { public class ErrorFormatter { - public ExceptionModel LoadException(Exception exception, StackFrameModel[] existingTrace = null, Func stackFrameGetter = null, - Func methodFormatter = null) + public ExceptionModel LoadException(Exception exception, StackFrameModel[]? existingTrace = null, Func? stackFrameGetter = null, + Func? methodFormatter = null) { stackFrameGetter = stackFrameGetter ?? (ex => new StackTrace(ex, true).GetFrames()); - var m = new ExceptionModel { - Message = exception.Message, - OriginalException = exception, - TypeName = exception.GetType().FullName - }; - var frames = stackFrameGetter(exception) ?? new StackFrame[0]; var stack = new List(); bool skipping = existingTrace != null; for (int i = frames.Length - 1; i >= 0; i--) { var f = frames[i]; - if (skipping && existingTrace.Length > i && f.GetMethod() == existingTrace[i].Method) continue; + if (skipping && existingTrace!.Length > i && f.GetMethod() == existingTrace[i].Method) continue; skipping = false; - stack.Add(AddMoreInfo(new StackFrameModel { - Method = f.GetMethod(), - FormattedMethod = methodFormatter?.Invoke(f), - At = LoadSourcePiece(f.GetFileName(), f.GetFileLineNumber(), - errorColumn: f.GetFileColumnNumber()) - })); - - //Adding additional information to ExceptionModel from InfoLoaders and InfoCollectionLoader - m.AdditionalInfo = InfoLoaders.Select(info => info(exception)) - .Where(info => info != null && info.Objects != null).ToArray() - .Union(InfoCollectionLoader.Select(infoCollection => infoCollection(exception)) - .Where(infoCollection => infoCollection != null) - .SelectMany(infoCollection => infoCollection) - .Where(info => info != null && info.Objects != null).ToArray()) - .ToArray(); + stack.Add(AddMoreInfo(new StackFrameModel( + f.GetMethod(), + methodFormatter?.Invoke(f), + LoadSourcePiece(f.GetFileName(), f.GetFileLineNumber(), + errorColumn: f.GetFileColumnNumber()), + null + ))); + } + //Adding additional information to ExceptionModel from InfoLoaders and InfoCollectionLoader + var additionalInfos = InfoLoaders.Select(info => info(exception)) + .Where(info => info != null && info.Objects != null).ToArray() + .Union(InfoCollectionLoader.Select(infoCollection => infoCollection(exception)) + .Where(infoCollection => infoCollection != null) + .SelectMany(infoCollection => infoCollection) + .Where(info => info != null && info.Objects != null).ToArray()) + .ToArray(); + stack.Reverse(); - m.Stack = stack.ToArray(); + + var m = new ExceptionModel( + exception.GetType().FullName, + exception.Message, + stack.ToArray(), + exception, + additionalInfos! + ); if (exception.InnerException != null) m.InnerException = LoadException(exception.InnerException, m.Stack, stackFrameGetter, methodFormatter); return m; } @@ -64,7 +67,7 @@ private StackFrameModel AddMoreInfo(StackFrameModel frame) { try { - frame.MoreInfo = FrameInfoLoaders.Select(f => f(frame)).Where(f => f != null).ToArray(); + frame.MoreInfo = FrameInfoLoaders.Select(f => f(frame)).Where(f => f != null).ToArray()!; } catch { @@ -74,15 +77,15 @@ private StackFrameModel AddMoreInfo(StackFrameModel frame) return frame; } - public List> FrameInfoLoaders = - new List>() + public List> FrameInfoLoaders = + new List>() { CreateDotvvmDocsLink, CreateReferenceSourceLink, CreateGithubLink }; - protected static IFrameMoreInfo CreateDotvvmDocsLink(StackFrameModel frame) + protected static IFrameMoreInfo? CreateDotvvmDocsLink(StackFrameModel frame) { const string DotvvmThumb = "https://dotvvm.com/Content/assets/ico/favicon.png"; var type = frame.Method?.DeclaringType; @@ -97,29 +100,30 @@ protected static IFrameMoreInfo CreateDotvvmDocsLink(StackFrameModel frame) return null; } - protected static IFrameMoreInfo CreateGithubLink(StackFrameModel frame) + protected static IFrameMoreInfo? CreateGithubLink(StackFrameModel frame) { const string GithubUrl = @"https://github.com/riganti/dotvvm/blob/master/src/"; const string Octocat = @"https://assets-cdn.github.com/favicon.ico"; if (frame.Method?.DeclaringType?.Assembly == typeof(ErrorFormatter).Assembly) { + var fileName = frame.At?.FileName; // dotvvm github - if (!string.IsNullOrEmpty(frame.At?.FileName)) + if (!string.IsNullOrEmpty(fileName)) { - var fileName = - frame.At.FileName.Substring( - frame.At.FileName.LastIndexOf("DotVVM.Framework", StringComparison.Ordinal)); - var url = GithubUrl + fileName.Replace('\\', '/').TrimStart('/') + "#L" + frame.At.LineNumber; + var urlFileName = + fileName.Substring( + fileName.LastIndexOf("DotVVM.Framework", StringComparison.Ordinal)); + var url = GithubUrl + fileName.Replace('\\', '/').TrimStart('/') + "#L" + frame.At!.LineNumber; return FrameMoreInfo.CreateThumbLink(url, Octocat); } else { // guess by method name - var fileName = frame.Method.DeclaringType.FullName.Replace("DotVVM.Framework", "") + var urlFileName = frame.Method.DeclaringType.FullName.Replace("DotVVM.Framework", "") .Replace('.', '/'); - if (fileName.Contains("+")) - fileName = fileName.Remove(fileName.IndexOf('+')); // remove nested class - var url = GithubUrl + "DotVVM.Framework" + fileName + ".cs"; + if (urlFileName.Contains("+")) + urlFileName = urlFileName.Remove(urlFileName.IndexOf('+')); // remove nested class + var url = GithubUrl + "DotVVM.Framework" + urlFileName + ".cs"; return FrameMoreInfo.CreateThumbLink(url, Octocat); } } @@ -176,7 +180,7 @@ protected static IFrameMoreInfo CreateGithubLink(StackFrameModel frame) "System.Private.CoreLib" }; - protected static IFrameMoreInfo CreateReferenceSourceLink(StackFrameModel frame) + protected static IFrameMoreInfo? CreateReferenceSourceLink(StackFrameModel frame) { const string DotNetIcon = "http://referencesource.microsoft.com/favicon.ico"; const string SourceUrl = "http://referencesource.microsoft.com/"; @@ -231,11 +235,9 @@ protected static string GetGenericFullName(Type type) return sb.ToString(); } - public List>> InfoCollectionLoader = - new List>>(); + public List?>> InfoCollectionLoader = new(); - public List> InfoLoaders = - new List>(); + public List> InfoLoaders = new(); public void AddInfoLoader(Func func) where T : Exception @@ -251,7 +253,7 @@ public void AddInfoLoader(Func func) ///
/// type of the exception /// function that returns a collection of ExceptionAdditionalInfo - public void AddInfoCollectionLoader(Func> func) + public void AddInfoCollectionLoader(Func?> func) where T : Exception { InfoCollectionLoader.Add(e => { @@ -260,7 +262,7 @@ public void AddInfoCollectionLoader(Func> Formatters = - new List>(); + public List> Formatters = new(); public string ErrorHtml(Exception exception, IHttpContext context) { @@ -343,17 +344,17 @@ public static ErrorFormatter CreateDefault() .Select(a => new KeyValuePair(a.name, a.value)) ).ToArray()); }); - f.AddInfoLoader(e => new ExceptionAdditionalInfo { - Title = "Loader Exceptions", - Objects = e.LoaderExceptions.Select(lde => lde.GetType().Name + ": " + lde.Message).ToArray(), - Display = ExceptionAdditionalInfo.DisplayMode.ToString - }); + f.AddInfoLoader(e => new ExceptionAdditionalInfo( + "Loader Exceptions", + e.LoaderExceptions.Select(lde => lde.GetType().Name + ": " + lde.Message).ToArray(), + ExceptionAdditionalInfo.DisplayMode.ToString + )); f.AddInfoLoader(e => { - var info = new ExceptionAdditionalInfo() { - Title = "DotVVM Compiler", - Objects = null, - Display = ExceptionAdditionalInfo.DisplayMode.ToString - }; + var info = new ExceptionAdditionalInfo( + "DotVVM Compiler", + null, + ExceptionAdditionalInfo.DisplayMode.ToString + ); if (e.Tokens != null && e.Tokens.Any()) { info.Objects = new object[] @@ -372,11 +373,11 @@ public static ErrorFormatter CreateDefault() var infos = new List(); foreach (var data in e.AdditionData) { - infos.Add(new ExceptionAdditionalInfo() { - Title = data.Key, - Objects = data.Value, - Display = ExceptionAdditionalInfo.DisplayMode.ToHtmlList - }); + infos.Add(new ExceptionAdditionalInfo( + data.Key, + data.Value, + ExceptionAdditionalInfo.DisplayMode.ToHtmlList + )); } return infos; }); diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionAdditionalInfo.cs b/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionAdditionalInfo.cs index 23a17f71e1..9cae64f40d 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionAdditionalInfo.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionAdditionalInfo.cs @@ -8,8 +8,15 @@ namespace DotVVM.Framework.Hosting.ErrorPages { public class ExceptionAdditionalInfo { + public ExceptionAdditionalInfo(string title, object[]? objects, DisplayMode display) + { + Title = title; + Objects = objects; + Display = display; + } + public string Title { get; set; } - public object[] Objects { get; set; } + public object[]? Objects { get; set; } public DisplayMode Display { get; set; } public enum DisplayMode diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionModel.cs b/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionModel.cs index f87600bf33..d3683703cd 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionModel.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/ExceptionModel.cs @@ -8,10 +8,19 @@ namespace DotVVM.Framework.Hosting.ErrorPages { public class ExceptionModel { + public ExceptionModel(string typeName, string message, StackFrameModel[] stack, Exception originalException, ExceptionAdditionalInfo[] additionalInfos) + { + TypeName = typeName; + Message = message; + Stack = stack; + OriginalException = originalException; + AdditionalInfo = additionalInfos; + } + public string TypeName { get; set; } public string Message { get; set; } public StackFrameModel[] Stack { get; set; } - public ExceptionModel InnerException { get; set; } + public ExceptionModel? InnerException { get; set; } public Exception OriginalException { get; set; } public ExceptionAdditionalInfo[] AdditionalInfo { get; set; } } diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/IErrorWriter.cs b/src/DotVVM.Framework/Hosting/ErrorPages/IErrorWriter.cs index 420ed90d65..c54bdc8add 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/IErrorWriter.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/IErrorWriter.cs @@ -11,7 +11,7 @@ public interface IErrorWriter { void WriteUnencoded(string str); void WriteText(string str); - void ObjectBrowser(object obj); + void ObjectBrowser(object? obj); void WriteKVTable(IEnumerable keys, IEnumerable values); void WriteSourceCode(SourceModel source, bool collapse = true); } diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/SourceModel.cs b/src/DotVVM.Framework/Hosting/ErrorPages/SourceModel.cs index 719e48a119..0a4ed7ec3a 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/SourceModel.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/SourceModel.cs @@ -9,12 +9,12 @@ namespace DotVVM.Framework.Hosting.ErrorPages { public class SourceModel { - public string FileName { get; set; } - public string SystemFileName => FileName?.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); + public string? FileName { get; set; } + public string? SystemFileName => FileName?.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); public bool LoadFailed { get; set; } - public string[] PreLines { get; set; } - public string CurrentLine { get; set; } - public string[] PostLines { get; set; } + public string[]? PreLines { get; set; } + public string? CurrentLine { get; set; } + public string[]? PostLines { get; set; } public int LineNumber { get; set; } public int ErrorColumn { get; set; } public int ErrorLength { get; set; } diff --git a/src/DotVVM.Framework/Hosting/ErrorPages/StackFrameModel.cs b/src/DotVVM.Framework/Hosting/ErrorPages/StackFrameModel.cs index e47596b451..0b25bb9909 100644 --- a/src/DotVVM.Framework/Hosting/ErrorPages/StackFrameModel.cs +++ b/src/DotVVM.Framework/Hosting/ErrorPages/StackFrameModel.cs @@ -9,8 +9,16 @@ namespace DotVVM.Framework.Hosting.ErrorPages { public class StackFrameModel { + public StackFrameModel(MethodBase method, string? formattedMethod, SourceModel at, IFrameMoreInfo[]? moreInfo) + { + Method = method; + FormattedMethod = formattedMethod; + At = at; + MoreInfo = moreInfo ?? new IFrameMoreInfo[0]; + } + public MethodBase Method { get; set; } - public string FormattedMethod { get; set; } + public string? FormattedMethod { get; set; } public SourceModel At { get; set; } public IFrameMoreInfo[] MoreInfo { get; set; } } diff --git a/src/DotVVM.Framework/Hosting/HttpRedirectService.cs b/src/DotVVM.Framework/Hosting/HttpRedirectService.cs index c2a4013671..6b165fed5b 100644 --- a/src/DotVVM.Framework/Hosting/HttpRedirectService.cs +++ b/src/DotVVM.Framework/Hosting/HttpRedirectService.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.CodeDom; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Hosting/ICookieCollection.cs b/src/DotVVM.Framework/Hosting/ICookieCollection.cs index 7133f42c80..89ca0b8c02 100644 --- a/src/DotVVM.Framework/Hosting/ICookieCollection.cs +++ b/src/DotVVM.Framework/Hosting/ICookieCollection.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; namespace DotVVM.Framework.Hosting { diff --git a/src/DotVVM.Framework/Hosting/IDotvvmPresenter.cs b/src/DotVVM.Framework/Hosting/IDotvvmPresenter.cs index 3c36b77360..6fe0932b3a 100644 --- a/src/DotVVM.Framework/Hosting/IDotvvmPresenter.cs +++ b/src/DotVVM.Framework/Hosting/IDotvvmPresenter.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Hosting/IDotvvmRequestContext.cs b/src/DotVVM.Framework/Hosting/IDotvvmRequestContext.cs index ae89882125..86de607e09 100644 --- a/src/DotVVM.Framework/Hosting/IDotvvmRequestContext.cs +++ b/src/DotVVM.Framework/Hosting/IDotvvmRequestContext.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Linq; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Hosting/IEnvironmentNameProvider.cs b/src/DotVVM.Framework/Hosting/IEnvironmentNameProvider.cs index 8476f29a1b..2a250d3ad5 100644 --- a/src/DotVVM.Framework/Hosting/IEnvironmentNameProvider.cs +++ b/src/DotVVM.Framework/Hosting/IEnvironmentNameProvider.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace DotVVM.Framework.Hosting +namespace DotVVM.Framework.Hosting { public interface IEnvironmentNameProvider { diff --git a/src/DotVVM.Framework/Hosting/IHeaderCollection.cs b/src/DotVVM.Framework/Hosting/IHeaderCollection.cs index e6f6484092..dc6185f295 100644 --- a/src/DotVVM.Framework/Hosting/IHeaderCollection.cs +++ b/src/DotVVM.Framework/Hosting/IHeaderCollection.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; namespace DotVVM.Framework.Hosting { diff --git a/src/DotVVM.Framework/Hosting/IHttpContext.cs b/src/DotVVM.Framework/Hosting/IHttpContext.cs index 0986f83487..055f828873 100644 --- a/src/DotVVM.Framework/Hosting/IHttpContext.cs +++ b/src/DotVVM.Framework/Hosting/IHttpContext.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Security.Claims; diff --git a/src/DotVVM.Framework/Hosting/IHttpRequest.cs b/src/DotVVM.Framework/Hosting/IHttpRequest.cs index ab627cf3a8..e5a34c7522 100644 --- a/src/DotVVM.Framework/Hosting/IHttpRequest.cs +++ b/src/DotVVM.Framework/Hosting/IHttpRequest.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.IO; namespace DotVVM.Framework.Hosting diff --git a/src/DotVVM.Framework/Hosting/IHttpResponse.cs b/src/DotVVM.Framework/Hosting/IHttpResponse.cs index 10762af4ab..c850698063 100644 --- a/src/DotVVM.Framework/Hosting/IHttpResponse.cs +++ b/src/DotVVM.Framework/Hosting/IHttpResponse.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections; +using System.Collections; using System.IO; using System.Threading; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Hosting/IMarkupFileLoader.cs b/src/DotVVM.Framework/Hosting/IMarkupFileLoader.cs index 81833bd07d..1eb6f4bd69 100644 --- a/src/DotVVM.Framework/Hosting/IMarkupFileLoader.cs +++ b/src/DotVVM.Framework/Hosting/IMarkupFileLoader.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Hosting/IPathString.cs b/src/DotVVM.Framework/Hosting/IPathString.cs index 02bdf16a25..88d65dd274 100644 --- a/src/DotVVM.Framework/Hosting/IPathString.cs +++ b/src/DotVVM.Framework/Hosting/IPathString.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; namespace DotVVM.Framework.Hosting { diff --git a/src/DotVVM.Framework/Hosting/IQueryCollection.cs b/src/DotVVM.Framework/Hosting/IQueryCollection.cs index aef5c1322e..8f59869358 100644 --- a/src/DotVVM.Framework/Hosting/IQueryCollection.cs +++ b/src/DotVVM.Framework/Hosting/IQueryCollection.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace DotVVM.Framework.Hosting diff --git a/src/DotVVM.Framework/Hosting/LocalizablePresenter.cs b/src/DotVVM.Framework/Hosting/LocalizablePresenter.cs index 93c39e95d7..361c65c2fd 100644 --- a/src/DotVVM.Framework/Hosting/LocalizablePresenter.cs +++ b/src/DotVVM.Framework/Hosting/LocalizablePresenter.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/DotVVM.Framework/Hosting/MarkupFile.cs b/src/DotVVM.Framework/Hosting/MarkupFile.cs index f5d8bd79e9..6ded9acf6e 100644 --- a/src/DotVVM.Framework/Hosting/MarkupFile.cs +++ b/src/DotVVM.Framework/Hosting/MarkupFile.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Hosting/Middlewares/DotvvmCsrfTokenMiddleware.cs b/src/DotVVM.Framework/Hosting/Middlewares/DotvvmCsrfTokenMiddleware.cs index b1e5fa85cc..5870b9ab36 100644 --- a/src/DotVVM.Framework/Hosting/Middlewares/DotvvmCsrfTokenMiddleware.cs +++ b/src/DotVVM.Framework/Hosting/Middlewares/DotvvmCsrfTokenMiddleware.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Hosting/Middlewares/DotvvmFileUploadMiddleware.cs b/src/DotVVM.Framework/Hosting/Middlewares/DotvvmFileUploadMiddleware.cs index d2e797ecef..a78d7f2730 100644 --- a/src/DotVVM.Framework/Hosting/Middlewares/DotvvmFileUploadMiddleware.cs +++ b/src/DotVVM.Framework/Hosting/Middlewares/DotvvmFileUploadMiddleware.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; @@ -122,8 +121,7 @@ private async Task SaveFiles(IHttpContext context, Group boundary, List new { offset = 0, start = (string)null, name = di.GetEraName(era) }).ToArray(), + eras = di.Calendar.Eras.Select(era => new { offset = 0, start = (string?)null, name = di.GetEraName(era) }).ToArray(), twoDigitYearMax = di.Calendar.TwoDigitYearMax, patterns = new { diff --git a/src/DotVVM.Framework/ResourceManagement/DefaultResourceHashService.cs b/src/DotVVM.Framework/ResourceManagement/DefaultResourceHashService.cs index c918a965f2..b639a4224d 100644 --- a/src/DotVVM.Framework/ResourceManagement/DefaultResourceHashService.cs +++ b/src/DotVVM.Framework/ResourceManagement/DefaultResourceHashService.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/ResourceManagement/DotvvmResourceException.cs b/src/DotVVM.Framework/ResourceManagement/DotvvmResourceException.cs index fbdc027bf3..d274978edd 100644 --- a/src/DotVVM.Framework/ResourceManagement/DotvvmResourceException.cs +++ b/src/DotVVM.Framework/ResourceManagement/DotvvmResourceException.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; namespace DotVVM.Framework.ResourceManagement { diff --git a/src/DotVVM.Framework/ResourceManagement/DotvvmResourceRepository.cs b/src/DotVVM.Framework/ResourceManagement/DotvvmResourceRepository.cs index fe98a97999..ea0d56eeef 100644 --- a/src/DotVVM.Framework/ResourceManagement/DotvvmResourceRepository.cs +++ b/src/DotVVM.Framework/ResourceManagement/DotvvmResourceRepository.cs @@ -1,5 +1,4 @@ -#nullable enable using Newtonsoft.Json; using System; using System.Collections.Concurrent; diff --git a/src/DotVVM.Framework/ResourceManagement/EmbeddedResourceLocation.cs b/src/DotVVM.Framework/ResourceManagement/EmbeddedResourceLocation.cs index 984fbc671d..8e838a261b 100644 --- a/src/DotVVM.Framework/ResourceManagement/EmbeddedResourceLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/EmbeddedResourceLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.IO; +using System.IO; using DotVVM.Framework.Hosting; using System.Reflection; using Newtonsoft.Json; diff --git a/src/DotVVM.Framework/ResourceManagement/FileResourceLocation.cs b/src/DotVVM.Framework/ResourceManagement/FileResourceLocation.cs index 03fc585e3a..1f1b827dd6 100644 --- a/src/DotVVM.Framework/ResourceManagement/FileResourceLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/FileResourceLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.IO; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/ResourceManagement/IDebugFileLocalLocation.cs b/src/DotVVM.Framework/ResourceManagement/IDebugFileLocalLocation.cs index 7535ee9da1..bdd6dfc6c9 100644 --- a/src/DotVVM.Framework/ResourceManagement/IDebugFileLocalLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/IDebugFileLocalLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; namespace DotVVM.Framework.ResourceManagement { diff --git a/src/DotVVM.Framework/ResourceManagement/IDotvvmResourceRepository.cs b/src/DotVVM.Framework/ResourceManagement/IDotvvmResourceRepository.cs index 8bfca254d6..57cef2389f 100644 --- a/src/DotVVM.Framework/ResourceManagement/IDotvvmResourceRepository.cs +++ b/src/DotVVM.Framework/ResourceManagement/IDotvvmResourceRepository.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/ILinkResource.cs b/src/DotVVM.Framework/ResourceManagement/ILinkResource.cs index e83800cd85..10121b9e2e 100644 --- a/src/DotVVM.Framework/ResourceManagement/ILinkResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/ILinkResource.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/ResourceManagement/ILocalResourceLocation.cs b/src/DotVVM.Framework/ResourceManagement/ILocalResourceLocation.cs index 5247c1d513..374263251c 100644 --- a/src/DotVVM.Framework/ResourceManagement/ILocalResourceLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/ILocalResourceLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/ResourceManagement/ILocalResourceUrlManager.cs b/src/DotVVM.Framework/ResourceManagement/ILocalResourceUrlManager.cs index 0c238583c3..51c68f9e27 100644 --- a/src/DotVVM.Framework/ResourceManagement/ILocalResourceUrlManager.cs +++ b/src/DotVVM.Framework/ResourceManagement/ILocalResourceUrlManager.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/ResourceManagement/IPreloadResource.cs b/src/DotVVM.Framework/ResourceManagement/IPreloadResource.cs index c42ea40107..4f198538d4 100644 --- a/src/DotVVM.Framework/ResourceManagement/IPreloadResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/IPreloadResource.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Controls; +using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; namespace DotVVM.Framework.ResourceManagement diff --git a/src/DotVVM.Framework/ResourceManagement/IResource.cs b/src/DotVVM.Framework/ResourceManagement/IResource.cs index 799c424cca..db82726662 100644 --- a/src/DotVVM.Framework/ResourceManagement/IResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/IResource.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Controls; +using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/ResourceManagement/IResourceHashService.cs b/src/DotVVM.Framework/ResourceManagement/IResourceHashService.cs index 05e827eefd..e20e8d2ff5 100644 --- a/src/DotVVM.Framework/ResourceManagement/IResourceHashService.cs +++ b/src/DotVVM.Framework/ResourceManagement/IResourceHashService.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/IResourceLocation.cs b/src/DotVVM.Framework/ResourceManagement/IResourceLocation.cs index 242aaa1059..163ff175f9 100644 --- a/src/DotVVM.Framework/ResourceManagement/IResourceLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/IResourceLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/IResourceProcessor.cs b/src/DotVVM.Framework/ResourceManagement/IResourceProcessor.cs index 41f9b22f64..c9a77a75d5 100644 --- a/src/DotVVM.Framework/ResourceManagement/IResourceProcessor.cs +++ b/src/DotVVM.Framework/ResourceManagement/IResourceProcessor.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/InlineScriptResource.cs b/src/DotVVM.Framework/ResourceManagement/InlineScriptResource.cs index ef2c78de7a..a7bbc30627 100644 --- a/src/DotVVM.Framework/ResourceManagement/InlineScriptResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/InlineScriptResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/InlineStylesheetResource.cs b/src/DotVVM.Framework/ResourceManagement/InlineStylesheetResource.cs index 535a1ed111..efac2a1062 100644 --- a/src/DotVVM.Framework/ResourceManagement/InlineStylesheetResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/InlineStylesheetResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.IO; using System.Threading; diff --git a/src/DotVVM.Framework/ResourceManagement/LinkResourceBase.cs b/src/DotVVM.Framework/ResourceManagement/LinkResourceBase.cs index 3413320bf4..064180b23d 100644 --- a/src/DotVVM.Framework/ResourceManagement/LinkResourceBase.cs +++ b/src/DotVVM.Framework/ResourceManagement/LinkResourceBase.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Controls; diff --git a/src/DotVVM.Framework/ResourceManagement/LocalResourceLocation.cs b/src/DotVVM.Framework/ResourceManagement/LocalResourceLocation.cs index b9da05eb63..57e74c9be6 100644 --- a/src/DotVVM.Framework/ResourceManagement/LocalResourceLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/LocalResourceLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/LocalResourceUrlManager.cs b/src/DotVVM.Framework/ResourceManagement/LocalResourceUrlManager.cs index 85113c2787..1790e23ed1 100644 --- a/src/DotVVM.Framework/ResourceManagement/LocalResourceUrlManager.cs +++ b/src/DotVVM.Framework/ResourceManagement/LocalResourceUrlManager.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Configuration; +using DotVVM.Framework.Configuration; using DotVVM.Framework.Hosting; using DotVVM.Framework.Hosting.Middlewares; using DotVVM.Framework.Routing; diff --git a/src/DotVVM.Framework/ResourceManagement/NamedResource.cs b/src/DotVVM.Framework/ResourceManagement/NamedResource.cs index cf47ebb580..c282bc96b6 100644 --- a/src/DotVVM.Framework/ResourceManagement/NamedResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/NamedResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/NullResource.cs b/src/DotVVM.Framework/ResourceManagement/NullResource.cs index 755e812126..0e1a3ceb80 100644 --- a/src/DotVVM.Framework/ResourceManagement/NullResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/NullResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/ResourceManagement/ReflectionAssemblyJsonConverter.cs b/src/DotVVM.Framework/ResourceManagement/ReflectionAssemblyJsonConverter.cs index 4920443233..44b59bd6ff 100644 --- a/src/DotVVM.Framework/ResourceManagement/ReflectionAssemblyJsonConverter.cs +++ b/src/DotVVM.Framework/ResourceManagement/ReflectionAssemblyJsonConverter.cs @@ -1,5 +1,4 @@ -#nullable enable -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/RegistrationUtils.cs b/src/DotVVM.Framework/ResourceManagement/RegistrationUtils.cs index b9a57fafe9..f8aa04f1f5 100644 --- a/src/DotVVM.Framework/ResourceManagement/RegistrationUtils.cs +++ b/src/DotVVM.Framework/ResourceManagement/RegistrationUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Utils; +using DotVVM.Framework.Utils; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/ResourceBase.cs b/src/DotVVM.Framework/ResourceManagement/ResourceBase.cs index cec8dec3f4..341cd3623e 100644 --- a/src/DotVVM.Framework/ResourceManagement/ResourceBase.cs +++ b/src/DotVVM.Framework/ResourceManagement/ResourceBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/ResourceManager.cs b/src/DotVVM.Framework/ResourceManagement/ResourceManager.cs index 967f719c89..7e8d92f6b1 100644 --- a/src/DotVVM.Framework/ResourceManagement/ResourceManager.cs +++ b/src/DotVVM.Framework/ResourceManagement/ResourceManager.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/ResourceRenderPosition.cs b/src/DotVVM.Framework/ResourceManagement/ResourceRenderPosition.cs index 2652572f4f..90ab154b08 100644 --- a/src/DotVVM.Framework/ResourceManagement/ResourceRenderPosition.cs +++ b/src/DotVVM.Framework/ResourceManagement/ResourceRenderPosition.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/ResourceRepositoryJsonConverter.cs b/src/DotVVM.Framework/ResourceManagement/ResourceRepositoryJsonConverter.cs index 9cd19dfc2c..24839da0c1 100644 --- a/src/DotVVM.Framework/ResourceManagement/ResourceRepositoryJsonConverter.cs +++ b/src/DotVVM.Framework/ResourceManagement/ResourceRepositoryJsonConverter.cs @@ -1,4 +1,3 @@ -#nullable enable using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; @@ -45,7 +44,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { DeserializeResources((JObject)prop.Value, r.type, serializer, repo); } - else if (CompiledAssemblyCache.Instance.FindType(prop.Key) is Type resourceType) + else if (CompiledAssemblyCache.Instance!.FindType(prop.Key) is Type resourceType) { DeserializeResources((JObject)prop.Value, resourceType, serializer, repo); } diff --git a/src/DotVVM.Framework/ResourceManagement/ResourceUtils.cs b/src/DotVVM.Framework/ResourceManagement/ResourceUtils.cs index 309b8269a8..7ba87de3e5 100644 --- a/src/DotVVM.Framework/ResourceManagement/ResourceUtils.cs +++ b/src/DotVVM.Framework/ResourceManagement/ResourceUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Controls; +using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; using DotVVM.Framework.Utils; using System; diff --git a/src/DotVVM.Framework/ResourceManagement/ResourcesRenderer.cs b/src/DotVVM.Framework/ResourceManagement/ResourcesRenderer.cs index 12870159bb..212205ffd8 100644 --- a/src/DotVVM.Framework/ResourceManagement/ResourcesRenderer.cs +++ b/src/DotVVM.Framework/ResourceManagement/ResourcesRenderer.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Controls; +using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/ResourceManagement/ScriptModuleResource.cs b/src/DotVVM.Framework/ResourceManagement/ScriptModuleResource.cs index 4b6f03a68c..c624b06265 100644 --- a/src/DotVVM.Framework/ResourceManagement/ScriptModuleResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/ScriptModuleResource.cs @@ -3,6 +3,7 @@ using System.Linq; using DotVVM.Framework.Controls; using DotVVM.Framework.Hosting; +using DotVVM.Framework.Utils; namespace DotVVM.Framework.ResourceManagement { @@ -12,12 +13,12 @@ namespace DotVVM.Framework.ResourceManagement public class ScriptModuleResource : LinkResourceBase, IPreloadResource, IDeferrableResource { /// Location of a fallback script for the case that the browser does not support ES6 modules. May be null, if the fallback is not needed. There is no way to put a CDN fallback nor integrity hash, so it should simply point to a local resource - public IResourceLocation NomoduleLocation { get; } + public IResourceLocation? NomoduleLocation { get; } /// If `defer` attribute should be used. public bool Defer { get; } - public ScriptModuleResource(IResourceLocation location, IResourceLocation nomoduleLocation = null, bool defer = true) - : base(defer ? ResourceRenderPosition.Anywhere : ResourceRenderPosition.Body, "text/javascript", location ?? nomoduleLocation) + public ScriptModuleResource(IResourceLocation location, IResourceLocation? nomoduleLocation = null, bool defer = true) + : base(defer ? ResourceRenderPosition.Anywhere : ResourceRenderPosition.Body, "text/javascript", location ?? nomoduleLocation!) { this.NomoduleLocation = nomoduleLocation; this.Defer = defer; @@ -56,9 +57,9 @@ public void RenderPreloadLink(IHtmlWriter writer, IDotvvmRequestContext context, writer.RenderEndTag(); } - public override IEnumerable GetLocations(string type = null) + public override IEnumerable GetLocations(string? type = null) { - if (type == "nomodule") return new IResourceLocation[] { NomoduleLocation }; + if (type == "nomodule") return new IResourceLocation[] { NomoduleLocation.NotNull() }; else return base.GetLocations(type); } diff --git a/src/DotVVM.Framework/ResourceManagement/ScriptResource.cs b/src/DotVVM.Framework/ResourceManagement/ScriptResource.cs index 82f245edb6..dec886f26c 100644 --- a/src/DotVVM.Framework/ResourceManagement/ScriptResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/ScriptResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/ResourceManagement/SingleResourceProcessorBase.cs b/src/DotVVM.Framework/ResourceManagement/SingleResourceProcessorBase.cs index 917791bd8e..57af842144 100644 --- a/src/DotVVM.Framework/ResourceManagement/SingleResourceProcessorBase.cs +++ b/src/DotVVM.Framework/ResourceManagement/SingleResourceProcessorBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/StylesheetResource.cs b/src/DotVVM.Framework/ResourceManagement/StylesheetResource.cs index f81f65d8a6..1b6235a32e 100644 --- a/src/DotVVM.Framework/ResourceManagement/StylesheetResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/StylesheetResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/TemplateResource.cs b/src/DotVVM.Framework/ResourceManagement/TemplateResource.cs index 9c5051a7cd..c2923ddcaf 100644 --- a/src/DotVVM.Framework/ResourceManagement/TemplateResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/TemplateResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/ResourceManagement/UrlResourceLocation.cs b/src/DotVVM.Framework/ResourceManagement/UrlResourceLocation.cs index ba985b4a9b..0eec8a3616 100644 --- a/src/DotVVM.Framework/ResourceManagement/UrlResourceLocation.cs +++ b/src/DotVVM.Framework/ResourceManagement/UrlResourceLocation.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/ResourceManagement/ViewModuleImportResource.cs b/src/DotVVM.Framework/ResourceManagement/ViewModuleImportResource.cs index 75e5b2f00a..6e2235e696 100644 --- a/src/DotVVM.Framework/ResourceManagement/ViewModuleImportResource.cs +++ b/src/DotVVM.Framework/ResourceManagement/ViewModuleImportResource.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Routing/DefaultRouteStrategy.cs b/src/DotVVM.Framework/Routing/DefaultRouteStrategy.cs index 4452591a00..ca28aecd42 100644 --- a/src/DotVVM.Framework/Routing/DefaultRouteStrategy.cs +++ b/src/DotVVM.Framework/Routing/DefaultRouteStrategy.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Configuration; using DotVVM.Framework.Hosting; using System; diff --git a/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertReason.cs b/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertReason.cs index 6ddcdedbfd..9762050602 100644 --- a/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertReason.cs +++ b/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertReason.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace DotVVM.Framework.Routing +namespace DotVVM.Framework.Routing { internal enum DotvvmConfigurationAssertReason { diff --git a/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertResult.cs b/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertResult.cs index ddececa7e8..38b3ef20bf 100644 --- a/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertResult.cs +++ b/src/DotVVM.Framework/Routing/DotvvmConfigurationAssertResult.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace DotVVM.Framework.Routing +namespace DotVVM.Framework.Routing { internal class DotvvmConfigurationAssertResult { diff --git a/src/DotVVM.Framework/Routing/DotvvmRoute.cs b/src/DotVVM.Framework/Routing/DotvvmRoute.cs index d61999b43a..ab2d96de66 100644 --- a/src/DotVVM.Framework/Routing/DotvvmRoute.cs +++ b/src/DotVVM.Framework/Routing/DotvvmRoute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Routing/DotvvmRouteException.cs b/src/DotVVM.Framework/Routing/DotvvmRouteException.cs index 152de452ca..f721e242da 100644 --- a/src/DotVVM.Framework/Routing/DotvvmRouteException.cs +++ b/src/DotVVM.Framework/Routing/DotvvmRouteException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; namespace DotVVM.Framework.Routing diff --git a/src/DotVVM.Framework/Routing/DotvvmRouteParser.cs b/src/DotVVM.Framework/Routing/DotvvmRouteParser.cs index d9255e1a14..0ba8ab26d4 100644 --- a/src/DotVVM.Framework/Routing/DotvvmRouteParser.cs +++ b/src/DotVVM.Framework/Routing/DotvvmRouteParser.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Routing/DotvvmRouteStrategyException.cs b/src/DotVVM.Framework/Routing/DotvvmRouteStrategyException.cs index 2a21504772..527dfadfee 100644 --- a/src/DotVVM.Framework/Routing/DotvvmRouteStrategyException.cs +++ b/src/DotVVM.Framework/Routing/DotvvmRouteStrategyException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; namespace DotVVM.Framework.Routing diff --git a/src/DotVVM.Framework/Routing/DotvvmRouteTable.cs b/src/DotVVM.Framework/Routing/DotvvmRouteTable.cs index 65bedac2e3..d10f500fc0 100644 --- a/src/DotVVM.Framework/Routing/DotvvmRouteTable.cs +++ b/src/DotVVM.Framework/Routing/DotvvmRouteTable.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Routing/GenericRouteParameterType.cs b/src/DotVVM.Framework/Routing/GenericRouteParameterType.cs index bd26ee6b87..c8595d3fc5 100644 --- a/src/DotVVM.Framework/Routing/GenericRouteParameterType.cs +++ b/src/DotVVM.Framework/Routing/GenericRouteParameterType.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; diff --git a/src/DotVVM.Framework/Routing/IRouteParameterConstraint.cs b/src/DotVVM.Framework/Routing/IRouteParameterConstraint.cs index 02aebeda1b..1208251311 100644 --- a/src/DotVVM.Framework/Routing/IRouteParameterConstraint.cs +++ b/src/DotVVM.Framework/Routing/IRouteParameterConstraint.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Routing/IRoutingStrategy.cs b/src/DotVVM.Framework/Routing/IRoutingStrategy.cs index 6bbd987c1e..b457583665 100644 --- a/src/DotVVM.Framework/Routing/IRoutingStrategy.cs +++ b/src/DotVVM.Framework/Routing/IRoutingStrategy.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; namespace DotVVM.Framework.Routing diff --git a/src/DotVVM.Framework/Routing/RouteBase.cs b/src/DotVVM.Framework/Routing/RouteBase.cs index aa6b8a3e02..53f992848c 100644 --- a/src/DotVVM.Framework/Routing/RouteBase.cs +++ b/src/DotVVM.Framework/Routing/RouteBase.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Routing/RouteHelper.cs b/src/DotVVM.Framework/Routing/RouteHelper.cs index ca8306d4ee..0be7b55fad 100644 --- a/src/DotVVM.Framework/Routing/RouteHelper.cs +++ b/src/DotVVM.Framework/Routing/RouteHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Configuration; +using DotVVM.Framework.Configuration; using DotVVM.Framework.ViewModel; using Microsoft.CodeAnalysis.CSharp.Syntax; using System; diff --git a/src/DotVVM.Framework/Routing/RouteStrategyMarkupFileInfo.cs b/src/DotVVM.Framework/Routing/RouteStrategyMarkupFileInfo.cs index 376fa07638..da7d0fff45 100644 --- a/src/DotVVM.Framework/Routing/RouteStrategyMarkupFileInfo.cs +++ b/src/DotVVM.Framework/Routing/RouteStrategyMarkupFileInfo.cs @@ -1,3 +1,4 @@ +#nullable disable namespace DotVVM.Framework.Routing { public class RouteStrategyMarkupFileInfo diff --git a/src/DotVVM.Framework/Routing/RouteTableGroup.cs b/src/DotVVM.Framework/Routing/RouteTableGroup.cs index 659666154d..a0619a8e85 100644 --- a/src/DotVVM.Framework/Routing/RouteTableGroup.cs +++ b/src/DotVVM.Framework/Routing/RouteTableGroup.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Routing/RouteTableJsonConverter.cs b/src/DotVVM.Framework/Routing/RouteTableJsonConverter.cs index a478a38686..0cce01e1fa 100644 --- a/src/DotVVM.Framework/Routing/RouteTableJsonConverter.cs +++ b/src/DotVVM.Framework/Routing/RouteTableJsonConverter.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using DotVVM.Framework.Hosting; +using System.Diagnostics.CodeAnalysis; namespace DotVVM.Framework.Routing { @@ -14,7 +15,7 @@ public class RouteTableJsonConverter : JsonConverter { public override bool CanConvert(Type objectType) => objectType == typeof(DotvvmRouteTable); - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var rt = existingValue as DotvvmRouteTable; if (rt == null) return null; @@ -27,7 +28,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist } catch (Exception error) { - rt.Add(prop.Key, new ErrorRoute(route["url"].Value(), route["virtualPath"].Value(), prop.Key, route["defaultValues"].ToObject>(), error)); + rt.Add(prop.Key, new ErrorRoute(route["url"].Value(), route["virtualPath"].Value(), prop.Key, route["defaultValues"].ToObject>(), error)); } } return rt; @@ -54,7 +55,7 @@ sealed class ErrorRoute : RouteBase { private readonly Exception error; - public ErrorRoute(string url, string virtualPath, string name, IDictionary defaultValues, Exception error) : base(url, virtualPath, name, defaultValues) + public ErrorRoute(string url, string virtualPath, string name, IDictionary? defaultValues, Exception error) : base(url, virtualPath, name, defaultValues) { this.error = error; } @@ -65,9 +66,9 @@ public ErrorRoute(string url, string virtualPath, string name, IDictionary throw new InvalidOperationException($"Could not create route {RouteName}", error); - public override bool IsMatch(string url, out IDictionary values) => throw new InvalidOperationException($"Could not create route {RouteName}", error); + public override bool IsMatch(string url, [MaybeNullWhen(false)] out IDictionary values) => throw new InvalidOperationException($"Could not create route {RouteName}", error); - protected override string BuildUrlCore(Dictionary values) => throw new InvalidOperationException($"Could not create route {RouteName}", error); + protected override string BuildUrlCore(Dictionary values) => throw new InvalidOperationException($"Could not create route {RouteName}", error); protected override void Freeze2() { // no mutable properties in this class diff --git a/src/DotVVM.Framework/Routing/UrlHelper.cs b/src/DotVVM.Framework/Routing/UrlHelper.cs index cabd42c8df..00fff757f9 100644 --- a/src/DotVVM.Framework/Routing/UrlHelper.cs +++ b/src/DotVVM.Framework/Routing/UrlHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Reflection; using System.Text; diff --git a/src/DotVVM.Framework/Runtime/AttributeViewModelParameterBinder.cs b/src/DotVVM.Framework/Runtime/AttributeViewModelParameterBinder.cs index 275f6aad3c..c69e782b36 100644 --- a/src/DotVVM.Framework/Runtime/AttributeViewModelParameterBinder.cs +++ b/src/DotVVM.Framework/Runtime/AttributeViewModelParameterBinder.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -95,7 +94,7 @@ private Expression GenerateParameterBindStatement(Type viewModelType, Expression /// /// Called from the generated lambda expressions to perform the parameter binding. /// - private static T SetProperty(IDotvvmRequestContext context, ParameterBindingAttribute attribute, T defaultValue) + private static T? SetProperty(IDotvvmRequestContext context, ParameterBindingAttribute attribute, T? defaultValue) { if (attribute.TryGetValue(context, out var result)) { diff --git a/src/DotVVM.Framework/Runtime/Caching/DefaultDotvvmCacheAdapter.cs b/src/DotVVM.Framework/Runtime/Caching/DefaultDotvvmCacheAdapter.cs index 1db9e4821a..322d2425e6 100644 --- a/src/DotVVM.Framework/Runtime/Caching/DefaultDotvvmCacheAdapter.cs +++ b/src/DotVVM.Framework/Runtime/Caching/DefaultDotvvmCacheAdapter.cs @@ -4,21 +4,21 @@ namespace DotVVM.Framework.Runtime.Caching { public class DefaultDotvvmCacheAdapter : IDotvvmCacheAdapter { - readonly SimpleLruDictionary lru; + readonly SimpleLruDictionary lru; public DefaultDotvvmCacheAdapter(int generationSize = 1000, int generationTickTimeSec = 5 * 60) { - lru = new SimpleLruDictionary(generationSize, TimeSpan.FromSeconds(generationTickTimeSec)); + lru = new(generationSize, TimeSpan.FromSeconds(generationTickTimeSec)); } - public T Get(object key) => lru.TryGetValue(key, out var result) ? (T)result : default!; + public T? Get(object key) => lru.TryGetValue(key, out var result) ? (T?)result : default; public T GetOrAdd(TKey key, Func> factoryFunc) where TKey : notnull => (T)lru.GetOrCreate(key, key => { if (factoryFunc == null) return default; var v = factoryFunc((TKey)key); if(v is object)return v.Value; return default; - }); - public object Remove(object key) => lru.Remove(key, out var oldValue) ? oldValue : null; + })!; + public object? Remove(object key) => lru.Remove(key, out var oldValue) ? oldValue : null; } } diff --git a/src/DotVVM.Framework/Runtime/Caching/IDotvvmCacheAdapter.cs b/src/DotVVM.Framework/Runtime/Caching/IDotvvmCacheAdapter.cs index 6fdf9857cd..cd529251cb 100644 --- a/src/DotVVM.Framework/Runtime/Caching/IDotvvmCacheAdapter.cs +++ b/src/DotVVM.Framework/Runtime/Caching/IDotvvmCacheAdapter.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; @@ -10,7 +9,7 @@ public interface IDotvvmCacheAdapter T GetOrAdd(TKey key, Func> factoryFunc) where TKey: notnull; - T Get(object key); + T? Get(object key); object? Remove(object key); } diff --git a/src/DotVVM.Framework/Runtime/Caching/SimpleLruDictionary.cs b/src/DotVVM.Framework/Runtime/Caching/SimpleLruDictionary.cs index 41e9236c92..3c937860cb 100644 --- a/src/DotVVM.Framework/Runtime/Caching/SimpleLruDictionary.cs +++ b/src/DotVVM.Framework/Runtime/Caching/SimpleLruDictionary.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Concurrent; using System; @@ -16,7 +15,7 @@ namespace DotVVM.Framework.Runtime.Caching /// Actually, the entries are not removed, the reference is just weakened, so GC can collect it. If the object is actually from another place, it will stay in the cache. /// public class SimpleLruDictionary - where TValue : class + where TValue : class? where TKey : notnull { // new generation @@ -74,7 +73,7 @@ private void CleanDeadReferences() } } - public bool TryGetValue(TKey key, [NotNullWhen(true)] out TValue? value) + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue? value) { if (hot.TryGetValue(key, out value)) return true; diff --git a/src/DotVVM.Framework/Runtime/CommandTaskSequenceHelper.cs b/src/DotVVM.Framework/Runtime/CommandTaskSequenceHelper.cs index 21626565c0..3da01b20a7 100644 --- a/src/DotVVM.Framework/Runtime/CommandTaskSequenceHelper.cs +++ b/src/DotVVM.Framework/Runtime/CommandTaskSequenceHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Runtime/Commands/CandidateBindings.cs b/src/DotVVM.Framework/Runtime/Commands/CandidateBindings.cs index 2920a77d9e..9dd7f3aa47 100644 --- a/src/DotVVM.Framework/Runtime/Commands/CandidateBindings.cs +++ b/src/DotVVM.Framework/Runtime/Commands/CandidateBindings.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.Linq; using DotVVM.Framework.Binding.Expressions; diff --git a/src/DotVVM.Framework/Runtime/Commands/CommandResolver.cs b/src/DotVVM.Framework/Runtime/Commands/CommandResolver.cs index d5fad76a86..7809825d84 100644 --- a/src/DotVVM.Framework/Runtime/Commands/CommandResolver.cs +++ b/src/DotVVM.Framework/Runtime/Commands/CommandResolver.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Binding; using DotVVM.Framework.Controls; @@ -26,13 +25,13 @@ public ActionInfo GetFunction(DotvvmControl? targetControl, DotvvmControl viewRo eventValidator.ValidateCommand(path, commandId, viewRootControl, validationTargetPath) : eventValidator.ValidateControlCommand(path, commandId, viewRootControl, targetControl, validationTargetPath); - context.ModelState.ValidationTarget = findResult.Control.GetValue(DotVVM.Framework.Controls.Validation.TargetProperty) ?? context.ViewModel; + context.ModelState.ValidationTarget = findResult.Control!.GetValue(DotVVM.Framework.Controls.Validation.TargetProperty) ?? context.ViewModel; - return new ActionInfo { - Action = () => findResult.Binding.Evaluate(findResult.Control, args), - Binding = findResult.Binding, - IsControlCommand = targetControl != null - }; + return new ActionInfo( + findResult.Binding, + () => findResult.Binding!.Evaluate(findResult.Control, args), + targetControl != null + ); } /// diff --git a/src/DotVVM.Framework/Runtime/Commands/EventValidator.cs b/src/DotVVM.Framework/Runtime/Commands/EventValidator.cs index 652d984162..c6615af374 100644 --- a/src/DotVVM.Framework/Runtime/Commands/EventValidator.cs +++ b/src/DotVVM.Framework/Runtime/Commands/EventValidator.cs @@ -31,7 +31,7 @@ public FindBindingResult ValidateCommand(string[] path, string commandId, Dotvvm // validate the command against the control if (result.Control is IEventValidationHandler) { - if (!((IEventValidationHandler)result.Control).ValidateCommand(result.Property)) + if (!((IEventValidationHandler)result.Control).ValidateCommand(result.Property!)) { throw EventValidationException(result?.ErrorMessage, result?.CandidateBindings); } @@ -50,18 +50,18 @@ public FindBindingResult ValidateCommand(string[] path, string commandId, Dotvvm /// Determinate whether finding control command binding or not /// private FindBindingResult FindCommandBinding(string[] path, string commandId, - DotvvmBindableObject viewRootControl, DotvvmBindableObject targetControl, - string validationTargetPath, bool findControl) + DotvvmBindableObject viewRootControl, DotvvmBindableObject? targetControl, + string? validationTargetPath, bool findControl) { // walk the control tree and find the path - CommandBindingExpression resultBinding = null; - DotvvmBindableObject resultControl = null; - DotvvmProperty resultProperty = null; + CommandBindingExpression? resultBinding = null; + DotvvmBindableObject? resultControl = null; + DotvvmProperty? resultProperty = null; bool checkControl; bool bindingInPath = false; var candidateBindings = new Dictionary(); - string errorMessage = null; + string? errorMessage = null; var walker = new ControlTreeWalker(viewRootControl); walker.ProcessControlTree((control) => @@ -191,17 +191,17 @@ private FindBindingResult FindControlCommandBinding(string[] path, string comman /// /// Throws the event validation exception. /// - private InvalidCommandInvocationException EventValidationException(string errorMessage = null, Dictionary data = null) + private InvalidCommandInvocationException EventValidationException(string? errorMessage = null, Dictionary? data = null) => new InvalidCommandInvocationException(errorMessage == null ? "Invalid command invocation!" : errorMessage, data); } public class FindBindingResult { - public string ErrorMessage { get; set; } - public Dictionary CandidateBindings { get; set; } + public string? ErrorMessage { get; set; } + public Dictionary CandidateBindings { get; set; } = new(); - public CommandBindingExpression Binding { get; set; } - public DotvvmBindableObject Control { get; set; } - public DotvvmProperty Property { get; set; } + public CommandBindingExpression? Binding { get; set; } + public DotvvmBindableObject? Control { get; set; } + public DotvvmProperty? Property { get; set; } } } diff --git a/src/DotVVM.Framework/Runtime/Commands/InvalidCommandInvocationException.cs b/src/DotVVM.Framework/Runtime/Commands/InvalidCommandInvocationException.cs index e1aaf11c1c..84085d3f47 100644 --- a/src/DotVVM.Framework/Runtime/Commands/InvalidCommandInvocationException.cs +++ b/src/DotVVM.Framework/Runtime/Commands/InvalidCommandInvocationException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; @@ -20,13 +19,13 @@ public InvalidCommandInvocationException(string message, Exception innerExceptio } - public InvalidCommandInvocationException(string message, Dictionary data) + public InvalidCommandInvocationException(string message, Dictionary? data) : this(message, (Exception?)null, data) { } - public InvalidCommandInvocationException(string message, Exception? innerException, Dictionary data) + public InvalidCommandInvocationException(string message, Exception? innerException, Dictionary? data) : base(message, innerException) { if(data != null) diff --git a/src/DotVVM.Framework/Runtime/Commands/ViewModelPathComparer.cs b/src/DotVVM.Framework/Runtime/Commands/ViewModelPathComparer.cs index c078253213..8ad1c51129 100644 --- a/src/DotVVM.Framework/Runtime/Commands/ViewModelPathComparer.cs +++ b/src/DotVVM.Framework/Runtime/Commands/ViewModelPathComparer.cs @@ -1,4 +1,3 @@ -#nullable enable namespace DotVVM.Framework.Runtime.Commands { public class ViewModelPathComparer diff --git a/src/DotVVM.Framework/Runtime/ControlTreeWalker.cs b/src/DotVVM.Framework/Runtime/ControlTreeWalker.cs index aa1be78f36..df81d04ada 100644 --- a/src/DotVVM.Framework/Runtime/ControlTreeWalker.cs +++ b/src/DotVVM.Framework/Runtime/ControlTreeWalker.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -12,9 +11,9 @@ public class ControlTreeWalker private DotvvmBindableObject root; - public Stack CurrentPath { get; private set; } = null!; + public Stack CurrentPath { get; } = new Stack(); - public string[]? CurrentPathArray { get; private set; } + public string[] CurrentPathArray { get; private set; } = new string[0]; /// /// Initializes a new instance of the class. @@ -30,7 +29,7 @@ public ControlTreeWalker(DotvvmBindableObject root) /// public void ProcessControlTree(Action action) { - CurrentPath = new Stack(); + CurrentPath.Clear(); RefreshCurrentPathArray(); ProcessControlTreeCore(root, action); diff --git a/src/DotVVM.Framework/Runtime/DefaultDotvvmViewBuilder.cs b/src/DotVVM.Framework/Runtime/DefaultDotvvmViewBuilder.cs index 8e0caa55ec..2185c55a81 100644 --- a/src/DotVVM.Framework/Runtime/DefaultDotvvmViewBuilder.cs +++ b/src/DotVVM.Framework/Runtime/DefaultDotvvmViewBuilder.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/DefaultOutputRenderer.cs b/src/DotVVM.Framework/Runtime/DefaultOutputRenderer.cs index 6080abce19..1f78f3071d 100644 --- a/src/DotVVM.Framework/Runtime/DefaultOutputRenderer.cs +++ b/src/DotVVM.Framework/Runtime/DefaultOutputRenderer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Runtime/DefaultStaticCommandServiceLoader.cs b/src/DotVVM.Framework/Runtime/DefaultStaticCommandServiceLoader.cs index 8836286fab..76f892d757 100644 --- a/src/DotVVM.Framework/Runtime/DefaultStaticCommandServiceLoader.cs +++ b/src/DotVVM.Framework/Runtime/DefaultStaticCommandServiceLoader.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/DotvvmRuntimeWarning.cs b/src/DotVVM.Framework/Runtime/DotvvmRuntimeWarning.cs index 86ace8e6b0..dcf9edf8c6 100644 --- a/src/DotVVM.Framework/Runtime/DotvvmRuntimeWarning.cs +++ b/src/DotVVM.Framework/Runtime/DotvvmRuntimeWarning.cs @@ -8,7 +8,7 @@ namespace DotVVM.Framework.Runtime { public class DotvvmRuntimeWarning { - public DotvvmRuntimeWarning(string message, Exception relatedException = null, DotvvmBindableObject relatedControl = null) + public DotvvmRuntimeWarning(string message, Exception? relatedException = null, DotvvmBindableObject? relatedControl = null) { this.Message = message ?? throw new ArgumentNullException(nameof(message)); this.RelatedException = relatedException; @@ -16,12 +16,12 @@ public DotvvmRuntimeWarning(string message, Exception relatedException = null, D } public string Message { get; } - public Exception RelatedException { get; } - public DotvvmBindableObject RelatedControl { get; } + public Exception? RelatedException { get; } + public DotvvmBindableObject? RelatedControl { get; } public override string ToString() { - var sections = new string[] { + var sections = new string?[] { Message, RelatedControl?.Apply(c => "related to:\n" + c.DebugString()), RelatedException?.ToString(), diff --git a/src/DotVVM.Framework/Runtime/Filters/ActionFilterAttribute.cs b/src/DotVVM.Framework/Runtime/Filters/ActionFilterAttribute.cs index 37c7b3cf80..07a1882be5 100644 --- a/src/DotVVM.Framework/Runtime/Filters/ActionFilterAttribute.cs +++ b/src/DotVVM.Framework/Runtime/Filters/ActionFilterAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Filters/ActionFilterHelper.cs b/src/DotVVM.Framework/Runtime/Filters/ActionFilterHelper.cs index 99401ece32..331a45bc2f 100644 --- a/src/DotVVM.Framework/Runtime/Filters/ActionFilterHelper.cs +++ b/src/DotVVM.Framework/Runtime/Filters/ActionFilterHelper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/src/DotVVM.Framework/Runtime/Filters/ActionInfo.cs b/src/DotVVM.Framework/Runtime/Filters/ActionInfo.cs index 5fa1d46c0f..d2cce1d4e9 100644 --- a/src/DotVVM.Framework/Runtime/Filters/ActionInfo.cs +++ b/src/DotVVM.Framework/Runtime/Filters/ActionInfo.cs @@ -10,9 +10,16 @@ namespace DotVVM.Framework.Runtime.Filters { public class ActionInfo { - public ICommandBinding Binding { get; set; } + public ActionInfo(ICommandBinding? binding, Func action, bool isControlCommand) + { + Binding = binding; + IsControlCommand = isControlCommand; + Action = action; + } + + public ICommandBinding? Binding { get; set; } public bool IsControlCommand { get; internal set; } - public Func Action { get; set; } + public Func Action { get; set; } } } diff --git a/src/DotVVM.Framework/Runtime/Filters/ActionParameterInfo.cs b/src/DotVVM.Framework/Runtime/Filters/ActionParameterInfo.cs deleted file mode 100644 index 99d8f61d11..0000000000 --- a/src/DotVVM.Framework/Runtime/Filters/ActionParameterInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace DotVVM.Framework.Runtime.Filters -{ - public class ActionParameterInfo - { - - public string Name { get; internal set; } - - public Type Type { get; internal set; } - - public object Value { get; internal set; } - - public ParameterInfo ParameterInfo { get; internal set; } - - } -} \ No newline at end of file diff --git a/src/DotVVM.Framework/Runtime/Filters/ExceptionFilterAttribute.cs b/src/DotVVM.Framework/Runtime/Filters/ExceptionFilterAttribute.cs index dd70105e5c..a521019778 100644 --- a/src/DotVVM.Framework/Runtime/Filters/ExceptionFilterAttribute.cs +++ b/src/DotVVM.Framework/Runtime/Filters/ExceptionFilterAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Filters/IActionFilter.cs b/src/DotVVM.Framework/Runtime/Filters/IActionFilter.cs index 0cd8c39b59..ddce1c1f66 100644 --- a/src/DotVVM.Framework/Runtime/Filters/IActionFilter.cs +++ b/src/DotVVM.Framework/Runtime/Filters/IActionFilter.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Runtime/Filters/ICommandActionFilter.cs b/src/DotVVM.Framework/Runtime/Filters/ICommandActionFilter.cs index d26bcbcb6b..5d00a987a9 100644 --- a/src/DotVVM.Framework/Runtime/Filters/ICommandActionFilter.cs +++ b/src/DotVVM.Framework/Runtime/Filters/ICommandActionFilter.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/Filters/IPageActionFilter.cs b/src/DotVVM.Framework/Runtime/Filters/IPageActionFilter.cs index ba178b95d3..0b94de2b6e 100644 --- a/src/DotVVM.Framework/Runtime/Filters/IPageActionFilter.cs +++ b/src/DotVVM.Framework/Runtime/Filters/IPageActionFilter.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/Filters/IPresenterActionFilter.cs b/src/DotVVM.Framework/Runtime/Filters/IPresenterActionFilter.cs index fc7f9d3ed9..82dd9a2a31 100644 --- a/src/DotVVM.Framework/Runtime/Filters/IPresenterActionFilter.cs +++ b/src/DotVVM.Framework/Runtime/Filters/IPresenterActionFilter.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Filters/IViewModelActionFilter.cs b/src/DotVVM.Framework/Runtime/Filters/IViewModelActionFilter.cs index 96d6c11410..954a6b15a1 100644 --- a/src/DotVVM.Framework/Runtime/Filters/IViewModelActionFilter.cs +++ b/src/DotVVM.Framework/Runtime/Filters/IViewModelActionFilter.cs @@ -1,5 +1,4 @@ -#nullable enable -using DotVVM.Framework.Hosting; +using DotVVM.Framework.Hosting; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/Filters/ModelValidationFilterAttribute.cs b/src/DotVVM.Framework/Runtime/Filters/ModelValidationFilterAttribute.cs index 10c94d43df..6e7c2bcd9e 100644 --- a/src/DotVVM.Framework/Runtime/Filters/ModelValidationFilterAttribute.cs +++ b/src/DotVVM.Framework/Runtime/Filters/ModelValidationFilterAttribute.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Threading.Tasks; using DotVVM.Framework.Hosting; using DotVVM.Framework.Utils; diff --git a/src/DotVVM.Framework/Runtime/IDotvvmViewBuilder.cs b/src/DotVVM.Framework/Runtime/IDotvvmViewBuilder.cs index 7833fe6e6a..61be732ac7 100644 --- a/src/DotVVM.Framework/Runtime/IDotvvmViewBuilder.cs +++ b/src/DotVVM.Framework/Runtime/IDotvvmViewBuilder.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/IOutputRenderer.cs b/src/DotVVM.Framework/Runtime/IOutputRenderer.cs index 1340166fef..619475241c 100644 --- a/src/DotVVM.Framework/Runtime/IOutputRenderer.cs +++ b/src/DotVVM.Framework/Runtime/IOutputRenderer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Runtime/IStaticCommandServiceLoader.cs b/src/DotVVM.Framework/Runtime/IStaticCommandServiceLoader.cs index 36a38170e5..892482e7ea 100644 --- a/src/DotVVM.Framework/Runtime/IStaticCommandServiceLoader.cs +++ b/src/DotVVM.Framework/Runtime/IStaticCommandServiceLoader.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/IViewModelParameterBinder.cs b/src/DotVVM.Framework/Runtime/IViewModelParameterBinder.cs index 4b0dcc96d3..9932670ec9 100644 --- a/src/DotVVM.Framework/Runtime/IViewModelParameterBinder.cs +++ b/src/DotVVM.Framework/Runtime/IViewModelParameterBinder.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Tracing/AggregateRequestTracer.cs b/src/DotVVM.Framework/Runtime/Tracing/AggregateRequestTracer.cs index d809893d8c..363dc63b95 100644 --- a/src/DotVVM.Framework/Runtime/Tracing/AggregateRequestTracer.cs +++ b/src/DotVVM.Framework/Runtime/Tracing/AggregateRequestTracer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Tracing/IRequestTracer.cs b/src/DotVVM.Framework/Runtime/Tracing/IRequestTracer.cs index ed9cd04177..1f28c9bb62 100644 --- a/src/DotVVM.Framework/Runtime/Tracing/IRequestTracer.cs +++ b/src/DotVVM.Framework/Runtime/Tracing/IRequestTracer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Tracing/NullRequestTracer.cs b/src/DotVVM.Framework/Runtime/Tracing/NullRequestTracer.cs index d9011c86fe..507ecf54d9 100644 --- a/src/DotVVM.Framework/Runtime/Tracing/NullRequestTracer.cs +++ b/src/DotVVM.Framework/Runtime/Tracing/NullRequestTracer.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Runtime/Tracing/RequestTracingExtensions.cs b/src/DotVVM.Framework/Runtime/Tracing/RequestTracingExtensions.cs index d8d0b88a9c..daec9e97d7 100644 --- a/src/DotVVM.Framework/Runtime/Tracing/RequestTracingExtensions.cs +++ b/src/DotVVM.Framework/Runtime/Tracing/RequestTracingExtensions.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Security/CorruptedCsrfTokenException.cs b/src/DotVVM.Framework/Security/CorruptedCsrfTokenException.cs index 3dfeea17c4..01ed679bdc 100644 --- a/src/DotVVM.Framework/Security/CorruptedCsrfTokenException.cs +++ b/src/DotVVM.Framework/Security/CorruptedCsrfTokenException.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Security/FakeViewModelProtector.cs b/src/DotVVM.Framework/Security/FakeViewModelProtector.cs index 133ba67c96..2d6611cfcc 100644 --- a/src/DotVVM.Framework/Security/FakeViewModelProtector.cs +++ b/src/DotVVM.Framework/Security/FakeViewModelProtector.cs @@ -1,5 +1,4 @@ -#nullable enable - + using DotVVM.Framework.Hosting; namespace DotVVM.Framework.Security diff --git a/src/DotVVM.Framework/Security/ICsrfProtector.cs b/src/DotVVM.Framework/Security/ICsrfProtector.cs index 076a43c15b..a6dd91c477 100644 --- a/src/DotVVM.Framework/Security/ICsrfProtector.cs +++ b/src/DotVVM.Framework/Security/ICsrfProtector.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Security/IViewModelProtector.cs b/src/DotVVM.Framework/Security/IViewModelProtector.cs index b8e0d144c6..1f0b87ead6 100644 --- a/src/DotVVM.Framework/Security/IViewModelProtector.cs +++ b/src/DotVVM.Framework/Security/IViewModelProtector.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Security/ProtectionHelpers.cs b/src/DotVVM.Framework/Security/ProtectionHelpers.cs index 2722508d44..8de529c6e1 100644 --- a/src/DotVVM.Framework/Security/ProtectionHelpers.cs +++ b/src/DotVVM.Framework/Security/ProtectionHelpers.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Testing/SimpleDictionaryCacheAdapter.cs b/src/DotVVM.Framework/Testing/SimpleDictionaryCacheAdapter.cs index f87b4be66a..d30f60dbb1 100644 --- a/src/DotVVM.Framework/Testing/SimpleDictionaryCacheAdapter.cs +++ b/src/DotVVM.Framework/Testing/SimpleDictionaryCacheAdapter.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Testing/TestCookieCollection.cs b/src/DotVVM.Framework/Testing/TestCookieCollection.cs index afc1a47f61..5d1ef906c8 100644 --- a/src/DotVVM.Framework/Testing/TestCookieCollection.cs +++ b/src/DotVVM.Framework/Testing/TestCookieCollection.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Testing/TestDotvvmRequestContext.cs b/src/DotVVM.Framework/Testing/TestDotvvmRequestContext.cs index 19c8de4bc1..92cb6d017a 100644 --- a/src/DotVVM.Framework/Testing/TestDotvvmRequestContext.cs +++ b/src/DotVVM.Framework/Testing/TestDotvvmRequestContext.cs @@ -1,3 +1,4 @@ +#nullable disable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Framework/Testing/TestHeaderCollection.cs b/src/DotVVM.Framework/Testing/TestHeaderCollection.cs index 4686574c5e..53e08b423e 100644 --- a/src/DotVVM.Framework/Testing/TestHeaderCollection.cs +++ b/src/DotVVM.Framework/Testing/TestHeaderCollection.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Testing/TestHttpContext.cs b/src/DotVVM.Framework/Testing/TestHttpContext.cs index 3362ac543d..d13b33f059 100644 --- a/src/DotVVM.Framework/Testing/TestHttpContext.cs +++ b/src/DotVVM.Framework/Testing/TestHttpContext.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Testing/TestHttpRequest.cs b/src/DotVVM.Framework/Testing/TestHttpRequest.cs index 9eef1a18b7..c97f484421 100644 --- a/src/DotVVM.Framework/Testing/TestHttpRequest.cs +++ b/src/DotVVM.Framework/Testing/TestHttpRequest.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Testing/TestHttpResponse.cs b/src/DotVVM.Framework/Testing/TestHttpResponse.cs index 5d66541e8f..be5315a07a 100644 --- a/src/DotVVM.Framework/Testing/TestHttpResponse.cs +++ b/src/DotVVM.Framework/Testing/TestHttpResponse.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.IO; diff --git a/src/DotVVM.Framework/Testing/TestPathString.cs b/src/DotVVM.Framework/Testing/TestPathString.cs index 581a031a72..a7e488921c 100644 --- a/src/DotVVM.Framework/Testing/TestPathString.cs +++ b/src/DotVVM.Framework/Testing/TestPathString.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Testing/TestQueryCollection.cs b/src/DotVVM.Framework/Testing/TestQueryCollection.cs index 80b31a6f83..f066e9de63 100644 --- a/src/DotVVM.Framework/Testing/TestQueryCollection.cs +++ b/src/DotVVM.Framework/Testing/TestQueryCollection.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Utils/AssemblyLoader.cs b/src/DotVVM.Framework/Utils/AssemblyLoader.cs index 5089e086a8..736a9acf55 100644 --- a/src/DotVVM.Framework/Utils/AssemblyLoader.cs +++ b/src/DotVVM.Framework/Utils/AssemblyLoader.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/DotVVM.Framework/Utils/DotvvmRequestContextUtils.cs b/src/DotVVM.Framework/Utils/DotvvmRequestContextUtils.cs index aa321ae8d7..2c7c1b63d7 100644 --- a/src/DotVVM.Framework/Utils/DotvvmRequestContextUtils.cs +++ b/src/DotVVM.Framework/Utils/DotvvmRequestContextUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Net; +using System.Net; using System.Threading.Tasks; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/Utils/ExceptionUtils.cs b/src/DotVVM.Framework/Utils/ExceptionUtils.cs index 9622213025..26ed11b6c6 100644 --- a/src/DotVVM.Framework/Utils/ExceptionUtils.cs +++ b/src/DotVVM.Framework/Utils/ExceptionUtils.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Utils/ExpressionComparer.cs b/src/DotVVM.Framework/Utils/ExpressionComparer.cs index 8284c8ea50..6cd3ea89f9 100644 --- a/src/DotVVM.Framework/Utils/ExpressionComparer.cs +++ b/src/DotVVM.Framework/Utils/ExpressionComparer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; diff --git a/src/DotVVM.Framework/Utils/ExpressionUtils.cs b/src/DotVVM.Framework/Utils/ExpressionUtils.cs index 7a035e8a1f..ecd66104aa 100644 --- a/src/DotVVM.Framework/Utils/ExpressionUtils.cs +++ b/src/DotVVM.Framework/Utils/ExpressionUtils.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/src/DotVVM.Framework/Utils/FunctionalExtensions.cs b/src/DotVVM.Framework/Utils/FunctionalExtensions.cs index a0ab22bfc4..60dbaa6598 100644 --- a/src/DotVVM.Framework/Utils/FunctionalExtensions.cs +++ b/src/DotVVM.Framework/Utils/FunctionalExtensions.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -56,9 +55,10 @@ private static string GetDebugFunctionInfo(Delegate func) return $"'{funcName}' with closure [{fieldsFormatted}]"; } - public static TOut CastTo(this object original) + [return: NotNullIfNotNull("original")] + public static TOut? CastTo(this object? original) where TOut : class - => (TOut)original; + => (TOut?)original; public static TOut? As(this object? original) where TOut : class diff --git a/src/DotVVM.Framework/Utils/HashUtils.cs b/src/DotVVM.Framework/Utils/HashUtils.cs index 1dcb3783ae..638998b4f6 100644 --- a/src/DotVVM.Framework/Utils/HashUtils.cs +++ b/src/DotVVM.Framework/Utils/HashUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Text; namespace DotVVM.Framework.Utils diff --git a/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartReader.cs b/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartReader.cs index aeb6577d44..d3ceed8f43 100644 --- a/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartReader.cs +++ b/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartReader.cs @@ -52,7 +52,7 @@ public MultipartReader(string boundary, Stream stream, int bufferSize) /// public int TotalHeaderSizeLimit { get; set; } - public async Task ReadNextSectionAsync(CancellationToken cancellationToken = new CancellationToken()) + public async Task ReadNextSectionAsync(CancellationToken cancellationToken = new CancellationToken()) { // Drain the prior section. await _currentStream.DrainAsync(cancellationToken); @@ -95,4 +95,4 @@ private async Task> ReadHeadersAsync(CancellationT return accumulator.GetResults(); } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartSection.cs b/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartSection.cs index f8f1486295..5f7f26e872 100644 --- a/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartSection.cs +++ b/src/DotVVM.Framework/Utils/HttpAbstractions/MultipartSection.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // This class comes from https://github.com/aspnet/HttpAbstractions and was slightly modified to support good old .NET Framework 4.5.1 - +#nullable disable using System.Collections.Generic; using System.IO; @@ -46,4 +46,4 @@ public string ContentDisposition /// public long? BaseStreamOffset { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/Utils/Invariant.cs b/src/DotVVM.Framework/Utils/Invariant.cs index 066d743e5b..135f3b4441 100644 --- a/src/DotVVM.Framework/Utils/Invariant.cs +++ b/src/DotVVM.Framework/Utils/Invariant.cs @@ -1,5 +1,4 @@ -#nullable enable -using System.Globalization; +using System.Globalization; namespace DotVVM.Framework.Utils { diff --git a/src/DotVVM.Framework/Utils/JsonUtils.cs b/src/DotVVM.Framework/Utils/JsonUtils.cs index 9864a4386a..b37930a591 100644 --- a/src/DotVVM.Framework/Utils/JsonUtils.cs +++ b/src/DotVVM.Framework/Utils/JsonUtils.cs @@ -1,4 +1,3 @@ -#nullable enable using Newtonsoft.Json.Linq; using System.Linq; using System; diff --git a/src/DotVVM.Framework/Utils/NamingUtils.cs b/src/DotVVM.Framework/Utils/NamingUtils.cs index 9c44d62855..1bf49b67dc 100644 --- a/src/DotVVM.Framework/Utils/NamingUtils.cs +++ b/src/DotVVM.Framework/Utils/NamingUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/Utils/ReflectionUtils.cs b/src/DotVVM.Framework/Utils/ReflectionUtils.cs index c2909752e3..a6eb6f91dc 100644 --- a/src/DotVVM.Framework/Utils/ReflectionUtils.cs +++ b/src/DotVVM.Framework/Utils/ReflectionUtils.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Controls; using System; using System.Collections; diff --git a/src/DotVVM.Framework/Utils/SecureGuidGenerator.cs b/src/DotVVM.Framework/Utils/SecureGuidGenerator.cs index 5e38edf403..9bfd9642c4 100644 --- a/src/DotVVM.Framework/Utils/SecureGuidGenerator.cs +++ b/src/DotVVM.Framework/Utils/SecureGuidGenerator.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Security.Cryptography; namespace DotVVM.Framework.Utils diff --git a/src/DotVVM.Framework/Utils/StringUtils.cs b/src/DotVVM.Framework/Utils/StringUtils.cs index d9260c0c45..4e7a07c01d 100644 --- a/src/DotVVM.Framework/Utils/StringUtils.cs +++ b/src/DotVVM.Framework/Utils/StringUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -namespace DotVVM.Framework.Utils +namespace DotVVM.Framework.Utils { public static class StringUtils { diff --git a/src/DotVVM.Framework/Utils/TaskUtils.cs b/src/DotVVM.Framework/Utils/TaskUtils.cs index b8ea202ef6..ff7b1cb7f8 100644 --- a/src/DotVVM.Framework/Utils/TaskUtils.cs +++ b/src/DotVVM.Framework/Utils/TaskUtils.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Linq; using System.Reflection; using System.Threading.Tasks; diff --git a/src/DotVVM.Framework/Utils/TupleComparer.cs b/src/DotVVM.Framework/Utils/TupleComparer.cs index a34bdfb6f0..e0c3780e2a 100644 --- a/src/DotVVM.Framework/Utils/TupleComparer.cs +++ b/src/DotVVM.Framework/Utils/TupleComparer.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Text; @@ -7,10 +6,10 @@ namespace DotVVM.Framework.Utils { public class TupleComparer : IEqualityComparer<(T1, T2)> { - private readonly IEqualityComparer comparer1; - private readonly IEqualityComparer comparer2; + private readonly IEqualityComparer? comparer1; + private readonly IEqualityComparer? comparer2; - public TupleComparer(IEqualityComparer comparer1, IEqualityComparer comparer2) + public TupleComparer(IEqualityComparer? comparer1, IEqualityComparer? comparer2) { this.comparer1 = comparer1; this.comparer2 = comparer2; diff --git a/src/DotVVM.Framework/ViewModel/ClientExtenderAttribute.cs b/src/DotVVM.Framework/ViewModel/ClientExtenderAttribute.cs index a590e8b15f..0d2ce35734 100644 --- a/src/DotVVM.Framework/ViewModel/ClientExtenderAttribute.cs +++ b/src/DotVVM.Framework/ViewModel/ClientExtenderAttribute.cs @@ -13,11 +13,11 @@ public class ClientExtenderAttribute : Attribute public int Order { get; set; } - public object Parameter { get; set; } + public object? Parameter { get; set; } - public ClientExtenderAttribute(string name, object parameter = null, int order = 0) + public ClientExtenderAttribute(string name, object? parameter = null, int order = 0) { - this.Name = name; + this.Name = name ?? throw new ArgumentNullException(nameof(name)); this.Parameter = parameter; this.Order = order; } diff --git a/src/DotVVM.Framework/ViewModel/DotvvmViewModelBase.cs b/src/DotVVM.Framework/ViewModel/DotvvmViewModelBase.cs index 5da597e1ab..249e268c6d 100644 --- a/src/DotVVM.Framework/ViewModel/DotvvmViewModelBase.cs +++ b/src/DotVVM.Framework/ViewModel/DotvvmViewModelBase.cs @@ -11,12 +11,12 @@ namespace DotVVM.Framework.ViewModel { public class DotvvmViewModelBase : IDotvvmViewModel { - private IDotvvmRequestContext _context; + private IDotvvmRequestContext? _context; [JsonIgnore] public IDotvvmRequestContext Context { - get { return _context; } + get { return _context!; } set { _context = value; @@ -91,4 +91,4 @@ internal void ExecuteOnViewModelRecursive(Action action) } } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/ViewModel/FromQueryAttribute.cs b/src/DotVVM.Framework/ViewModel/FromQueryAttribute.cs index 2103587aab..24299198bf 100644 --- a/src/DotVVM.Framework/ViewModel/FromQueryAttribute.cs +++ b/src/DotVVM.Framework/ViewModel/FromQueryAttribute.cs @@ -1,4 +1,5 @@ -using DotVVM.Framework.Hosting; +using System.Diagnostics.CodeAnalysis; +using DotVVM.Framework.Hosting; namespace DotVVM.Framework.ViewModel { @@ -15,7 +16,7 @@ public FromQueryAttribute(string parameterName) ParameterName = parameterName; } - protected override bool TryGetValueCore(IDotvvmRequestContext context, out object value) + protected override bool TryGetValueCore(IDotvvmRequestContext context, [MaybeNullWhen(false)] out object value) { var isPresent = context.Query.TryGetValue(ParameterName, out var stringValue); value = stringValue; @@ -23,4 +24,4 @@ protected override bool TryGetValueCore(IDotvvmRequestContext context, out objec } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/ViewModel/FromRouteAttribute.cs b/src/DotVVM.Framework/ViewModel/FromRouteAttribute.cs index a1ab8a9c15..150868d95b 100644 --- a/src/DotVVM.Framework/ViewModel/FromRouteAttribute.cs +++ b/src/DotVVM.Framework/ViewModel/FromRouteAttribute.cs @@ -15,9 +15,9 @@ public FromRouteAttribute(string parameterName) ParameterName = parameterName; } - protected override bool TryGetValueCore(IDotvvmRequestContext context, out object value) + protected override bool TryGetValueCore(IDotvvmRequestContext context, out object? value) { - return context.Parameters.TryGetValue(ParameterName, out value); + return context.Parameters!.TryGetValue(ParameterName, out value); } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/ViewModel/ParameterBindingAttribute.cs b/src/DotVVM.Framework/ViewModel/ParameterBindingAttribute.cs index aa3707efe0..db9ece7f1a 100644 --- a/src/DotVVM.Framework/ViewModel/ParameterBindingAttribute.cs +++ b/src/DotVVM.Framework/ViewModel/ParameterBindingAttribute.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text; using DotVVM.Framework.Hosting; using DotVVM.Framework.Utils; @@ -15,13 +16,13 @@ public virtual void SetOptions(ViewModelPropertyMap map) map.TransferAfterPostback = map.TransferToServer = map.TransferToServerOnlyInPath = false; } - public bool TryGetValue(IDotvvmRequestContext context, out T value) + public bool TryGetValue(IDotvvmRequestContext context, out T? value) { if (TryGetValueCore(context, out var valueUnconverted)) { try { - value = (T) ConvertValue(valueUnconverted, typeof(T)); + value = (T?) ConvertValue(valueUnconverted, typeof(T)); return true; } catch @@ -34,12 +35,12 @@ public bool TryGetValue(IDotvvmRequestContext context, out T value) return false; } - protected virtual object ConvertValue(object valueUnconverted, Type targetType) + protected virtual object? ConvertValue(object? valueUnconverted, Type targetType) { return ReflectionUtils.ConvertValue(valueUnconverted, targetType); } - protected abstract bool TryGetValueCore(IDotvvmRequestContext context, out object value); + protected abstract bool TryGetValueCore(IDotvvmRequestContext context, out object? value); } } diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ClientExtenderInfo.cs b/src/DotVVM.Framework/ViewModel/Serialization/ClientExtenderInfo.cs index 731f11fd7a..f9cbc1913d 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/ClientExtenderInfo.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/ClientExtenderInfo.cs @@ -1,12 +1,19 @@ +using System; using Newtonsoft.Json; namespace DotVVM.Framework.ViewModel.Serialization { public class ClientExtenderInfo { + public ClientExtenderInfo(string name, object? parameter) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Parameter = parameter; + } + [JsonProperty("name")] public string Name { get; set; } [JsonProperty("parameter")] - public object Parameter { get; set; } + public object? Parameter { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelLoader.cs b/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelLoader.cs index e15aa81a01..3c430ea587 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelLoader.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelLoader.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using DotVVM.Framework.Controls.Infrastructure; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelSerializer.cs b/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelSerializer.cs index 2c3cb4ae0c..e959fe7219 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelSerializer.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/DefaultViewModelSerializer.cs @@ -52,6 +52,7 @@ public DefaultViewModelSerializer(DotvvmConfiguration configuration, IViewModelP /// public string SerializeViewModel(IDotvvmRequestContext context) { + context.ViewModelJson ??= new JObject(); if (SendDiff && context.ReceivedViewModelJson != null && context.ViewModelJson["viewModel"] != null) { context.ViewModelJson["viewModelDiff"] = JsonUtils.Diff((JObject)context.ReceivedViewModelJson["viewModel"], (JObject)context.ViewModelJson["viewModel"], false, i => ShouldIncludeProperty(i.TypeId, i.Property)); @@ -82,13 +83,11 @@ public string SerializeViewModel(IDotvvmRequestContext context) /// /// Builds the view model for the client. /// - public void BuildViewModel(IDotvvmRequestContext context, object commandResult) + public void BuildViewModel(IDotvvmRequestContext context, object? commandResult) { // serialize the ViewModel var serializer = CreateJsonSerializer(); - var viewModelConverter = new ViewModelJsonConverter(context.IsPostBack, viewModelMapper, context.Services) { - UsedSerializationMaps = new HashSet() - }; + var viewModelConverter = new ViewModelJsonConverter(context.IsPostBack, viewModelMapper, context.Services); serializer.Converters.Add(viewModelConverter); var writer = new JTokenWriter(); try @@ -97,12 +96,12 @@ public void BuildViewModel(IDotvvmRequestContext context, object commandResult) } catch (Exception ex) { - throw new Exception($"Could not serialize viewModel of type { context.ViewModel.GetType().Name }. Serialization failed at property { writer.Path }. {GeneralViewModelRecommendations}", ex); + throw new Exception($"Could not serialize viewModel of type { context.ViewModel!.GetType().Name }. Serialization failed at property { writer.Path }. {GeneralViewModelRecommendations}", ex); } var viewModelToken = writer.Token; - string viewModelCacheId = null; - if (context.Configuration.ExperimentalFeatures.ServerSideViewModelCache.IsEnabledForRoute(context.Route.RouteName)) + string? viewModelCacheId = null; + if (context.Configuration.ExperimentalFeatures.ServerSideViewModelCache.IsEnabledForRoute(context.Route?.RouteName)) { viewModelCacheId = viewModelServerCache.StoreViewModel(context, (JObject)viewModelToken); } @@ -166,15 +165,13 @@ public void AddNewResources(IDotvvmRequestContext context) var renderedResources = new HashSet(context.ReceivedViewModelJson?["renderedResources"]?.Values() ?? new string[] { }); var resourcesObject = BuildResourcesJson(context, rn => !renderedResources.Contains(rn)); if (resourcesObject.Count > 0) - context.ViewModelJson["resources"] = resourcesObject; + context.ViewModelJson!["resources"] = resourcesObject; } - public string BuildStaticCommandResponse(IDotvvmRequestContext context, object result) + public string BuildStaticCommandResponse(IDotvvmRequestContext context, object? result) { var serializer = CreateJsonSerializer(); - var viewModelConverter = new ViewModelJsonConverter(context.IsPostBack, viewModelMapper, context.Services) { - UsedSerializationMaps = new HashSet() - }; + var viewModelConverter = new ViewModelJsonConverter(context.IsPostBack, viewModelMapper, context.Services); serializer.Converters.Add(viewModelConverter); var response = new JObject(); response["result"] = WriteCommandData(result, serializer, "the static command result"); @@ -195,7 +192,7 @@ private static void AddCustomPropertiesIfAny(IDotvvmRequestContext context, Json context.CustomResponseProperties.PropertiesSerialized = true; } - private static JToken WriteCommandData(object data, JsonSerializer serializer, string description) + private static JToken WriteCommandData(object? data, JsonSerializer serializer, string description) { var writer = new JTokenWriter(); try @@ -204,7 +201,7 @@ private static JToken WriteCommandData(object data, JsonSerializer serializer, s } catch (Exception ex) { - throw new Exception($"Could not serialize {description} of type '{ data.GetType().FullName}'. Serialization failed at property { writer.Path }. {GeneralViewModelRecommendations}", ex); + throw new Exception($"Could not serialize {description} of type '{ data?.GetType().FullName ?? "null"}'. Serialization failed at property { writer.Path }. {GeneralViewModelRecommendations}", ex); } return writer.Token; } @@ -306,7 +303,7 @@ public void PopulateViewModel(IDotvvmRequestContext context, string serializedPo JObject viewModelToken; if (data["viewModelCacheId"] != null) { - if (!context.Configuration.ExperimentalFeatures.ServerSideViewModelCache.IsEnabledForRoute(context.Route.RouteName)) + if (!context.Configuration.ExperimentalFeatures.ServerSideViewModelCache.IsEnabledForRoute(context.Route?.RouteName)) { throw new InvalidOperationException("The server-side viewmodel caching is not enabled for the current route!"); } @@ -339,18 +336,18 @@ public void PopulateViewModel(IDotvvmRequestContext context, string serializedPo serializer.Converters.Add(viewModelConverter); try { - viewModelConverter.Populate(viewModelToken.CreateReader(), serializer, context.ViewModel); + viewModelConverter.Populate(viewModelToken.CreateReader(), serializer, context.ViewModel!); } catch (Exception ex) { - throw new Exception($"Could not deserialize viewModel of type { context.ViewModel.GetType().Name }. {GeneralViewModelRecommendations}", ex); + throw new Exception($"Could not deserialize viewModel of type { context.ViewModel?.GetType().Name ?? "null" }. {GeneralViewModelRecommendations}", ex); } } /// /// Resolves the command for the specified post data. /// - public ActionInfo ResolveCommand(IDotvvmRequestContext context, DotvvmView view) + public ActionInfo? ResolveCommand(IDotvvmRequestContext context, DotvvmView view) { // get properties var data = context.ReceivedViewModelJson ?? throw new NotSupportedException("Could not find ReceivedViewModelJson in request context."); diff --git a/src/DotVVM.Framework/ViewModel/Serialization/DotvvmByteArrayConverter.cs b/src/DotVVM.Framework/ViewModel/Serialization/DotvvmByteArrayConverter.cs index 1283773dd2..9451357cb7 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/DotvvmByteArrayConverter.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/DotvvmByteArrayConverter.cs @@ -9,7 +9,7 @@ namespace DotVVM.Framework.ViewModel.Serialization { public class DotvvmByteArrayConverter : JsonConverter { - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { diff --git a/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDateTimeConverter.cs b/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDateTimeConverter.cs index eb2109302a..381684bac5 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDateTimeConverter.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDateTimeConverter.cs @@ -20,7 +20,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s } } - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { diff --git a/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDictionaryConverter.cs b/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDictionaryConverter.cs index 795f9a2cd7..1b44b276f2 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDictionaryConverter.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/DotvvmDictionaryConverter.cs @@ -46,7 +46,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s } } - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) { diff --git a/src/DotVVM.Framework/ViewModel/Serialization/EncryptedValuesReader.cs b/src/DotVVM.Framework/ViewModel/Serialization/EncryptedValuesReader.cs index d4d9cd2b23..33e5bc526b 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/EncryptedValuesReader.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/EncryptedValuesReader.cs @@ -11,7 +11,7 @@ namespace DotVVM.Framework.ViewModel.Serialization public class EncryptedValuesReader { JsonSerializer serializer; - Stack<(int prop, JObject obj)> stack = new Stack<(int prop, JObject obj)>(); + Stack<(int prop, JObject? obj)> stack = new(); int virtualNests = 0; int lastPropertyIndex = -1; public bool Suppressed { get; private set; } = false; @@ -22,9 +22,9 @@ public EncryptedValuesReader(JObject json) this.serializer = new JsonSerializer(); } - private JObject json => stack.Peek().obj; + private JObject? json => stack.Peek().obj; - private JProperty Property(int index) + private JProperty? Property(int index) { var name = index.ToString(); return virtualNests == 0 ? json?.Property(name) : null; @@ -46,7 +46,7 @@ public void Nest(int property) { virtualNests++; } - stack.Push((property, (JObject)prop?.Value)); + stack.Push((property, (JObject?)prop?.Value)); // remove read nodes and then make sure that JObject is empty prop?.Remove(); lastPropertyIndex = -1; @@ -63,7 +63,7 @@ public void AssertEnd() } else { - if (json.Properties().Count() > 0) + if (json!.Properties().Count() > 0) throw SecurityError(); } lastPropertyIndex = stack.Pop().prop; diff --git a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelLoader.cs b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelLoader.cs index 57650694f1..377aac8f70 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelLoader.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelLoader.cs @@ -1,4 +1,3 @@ -#nullable enable using DotVVM.Framework.Controls.Infrastructure; using DotVVM.Framework.Hosting; diff --git a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializationMapper.cs b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializationMapper.cs index 7fa845a54d..057c64efd8 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializationMapper.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializationMapper.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializer.cs b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializer.cs index ab4be617c7..ecbf7ed0e7 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializer.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelSerializer.cs @@ -7,9 +7,9 @@ namespace DotVVM.Framework.ViewModel.Serialization { public interface IViewModelSerializer { - void BuildViewModel(IDotvvmRequestContext context, object commandResult); + void BuildViewModel(IDotvvmRequestContext context, object? commandResult); - string BuildStaticCommandResponse(IDotvvmRequestContext context, object commandResult); + string BuildStaticCommandResponse(IDotvvmRequestContext context, object? commandResult); string SerializeViewModel(IDotvvmRequestContext context); @@ -17,7 +17,7 @@ public interface IViewModelSerializer void PopulateViewModel(IDotvvmRequestContext context, string serializedPostData); - ActionInfo ResolveCommand(IDotvvmRequestContext context, DotvvmView view); + ActionInfo? ResolveCommand(IDotvvmRequestContext context, DotvvmView view); void AddPostBackUpdatedControls(IDotvvmRequestContext context, IEnumerable<(string name, string html)> postbackUpdatedControls); void AddNewResources(IDotvvmRequestContext context); diff --git a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelServerStore.cs b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelServerStore.cs index 6d1822524a..14d1d33ad2 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelServerStore.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelServerStore.cs @@ -9,7 +9,7 @@ public interface IViewModelServerStore void Store(string hash, byte[] cacheData); - byte[] Retrieve(string hash); + byte[]? Retrieve(string hash); } } diff --git a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelTypeMetadataSerializer.cs b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelTypeMetadataSerializer.cs index 33b82dcd84..e5b3f8e12b 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/IViewModelTypeMetadataSerializer.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/IViewModelTypeMetadataSerializer.cs @@ -5,7 +5,7 @@ namespace DotVVM.Framework.ViewModel.Serialization { public interface IViewModelTypeMetadataSerializer { - JToken SerializeTypeMetadata(IEnumerable usedSerializationMaps, ISet knownTypeIds = null); + JToken SerializeTypeMetadata(IEnumerable usedSerializationMaps, ISet? knownTypeIds = null); } } diff --git a/src/DotVVM.Framework/ViewModel/Serialization/InMemoryViewModelServerStore.cs b/src/DotVVM.Framework/ViewModel/Serialization/InMemoryViewModelServerStore.cs index d907b81ca8..87fbd7a4af 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/InMemoryViewModelServerStore.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/InMemoryViewModelServerStore.cs @@ -16,7 +16,7 @@ public InMemoryViewModelServerStore(IDotvvmCacheAdapter cacheAdapter, IOptions(BuildKey(hash)); } diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelJsonConverter.cs b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelJsonConverter.cs index b5f72f9e50..cfdb07eb96 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelJsonConverter.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelJsonConverter.cs @@ -19,7 +19,7 @@ public class ViewModelJsonConverter : JsonConverter { private readonly IViewModelSerializationMapper viewModelSerializationMapper; - public ViewModelJsonConverter(bool isPostback, IViewModelSerializationMapper viewModelSerializationMapper, IServiceProvider services, JObject encryptedValues = null) + public ViewModelJsonConverter(bool isPostback, IViewModelSerializationMapper viewModelSerializationMapper, IServiceProvider services, JObject? encryptedValues = null) { Services = services; IsPostback = isPostback; @@ -40,7 +40,7 @@ public ViewModelJsonConverter(bool isPostback, IViewModelSerializationMapper vie private Lazy evWriter; - public HashSet UsedSerializationMaps { get; set; } + public HashSet UsedSerializationMaps { get; } = new(); public IServiceProvider Services { get; } public bool IsPostback { get; private set; } @@ -66,7 +66,7 @@ public override bool CanConvert(Type objectType) /// /// Reads the JSON representation of the object. /// - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + public override object? ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { // handle null keyword if (reader.TokenType == JsonToken.Null) diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelPropertyMap.cs b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelPropertyMap.cs index 91b4d59408..46a122b219 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelPropertyMap.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelPropertyMap.cs @@ -11,17 +11,29 @@ namespace DotVVM.Framework.ViewModel.Serialization { public class ViewModelPropertyMap { + public ViewModelPropertyMap(PropertyInfo propertyInfo, string name, ProtectMode viewModelProtection, Type type, bool transferToServer, bool transferAfterPostback, bool transferFirstRequest, bool populate) + { + PropertyInfo = propertyInfo; + Name = name; + ViewModelProtection = viewModelProtection; + Type = type; + TransferToServer = transferToServer; + TransferAfterPostback = transferAfterPostback; + TransferFirstRequest = transferFirstRequest; + Populate = populate; + } + public PropertyInfo PropertyInfo { get; set; } public string Name { get; set; } - public List ClientExtenders { get; set; } + public List ClientExtenders { get; } = new(); public ProtectMode ViewModelProtection { get; set; } public Type Type { get; set; } - public Direction BindDirection { get; set; } + public Direction BindDirection { get; set; } = Direction.None; public bool TransferToServer { get; set; } public bool TransferToServerOnlyInPath { get; set; } @@ -30,14 +42,14 @@ public class ViewModelPropertyMap public bool TransferFirstRequest { get; set; } public bool Populate { get; set; } - public List ValidationRules { get; set; } + public List ValidationRules { get; } = new(); public IEnumerable ClientValidationRules { get { return ValidationRules.Where(r => !string.IsNullOrEmpty(r.ClientRuleName)); } } - public JsonConverter JsonConverter { get; set; } + public JsonConverter? JsonConverter { get; set; } /// /// Gets whether the property is transferred both ways. diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs index 49dde94a79..f38d65277b 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMap.cs @@ -43,17 +43,17 @@ public void ResetFunctions() writerFactory = null; } - private ReaderDelegate readerFactory; + private ReaderDelegate? readerFactory; /// /// Gets the JSON reader factory. /// public ReaderDelegate ReaderFactory => readerFactory ?? (readerFactory = CreateReaderFactory()); - private WriterDelegate writerFactory; + private WriterDelegate? writerFactory; /// /// Gets the JSON writer factory. /// public WriterDelegate WriterFactory => writerFactory ?? (writerFactory = CreateWriterFactory()); - private Func constructorFactory; + private Func? constructorFactory; /// /// Gets the constructor factory. /// @@ -295,7 +295,7 @@ private static void Serialize(JsonSerializer serializer, JsonWriter writer, View } } - private static object Deserialize(JsonSerializer serializer, JsonReader reader, ViewModelPropertyMap property, object existingValue) + private static object? Deserialize(JsonSerializer serializer, JsonReader reader, ViewModelPropertyMap property, object existingValue) { if (property.JsonConverter != null && property.JsonConverter.CanRead && property.JsonConverter.CanConvert(property.Type)) { diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMapper.cs b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMapper.cs index f1e8a2e128..686d8c7a17 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMapper.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelSerializationMapper.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -51,17 +50,17 @@ protected virtual IEnumerable GetProperties(Type type) { if (property.GetCustomAttribute() != null) continue; - var propertyMap = new ViewModelPropertyMap() { - PropertyInfo = property, - Name = propertySerialization.ResolveName(property), - ViewModelProtection = ProtectMode.None, - Type = property.PropertyType, - TransferAfterPostback = property.GetMethod != null && property.GetMethod.IsPublic, - TransferFirstRequest = property.GetMethod != null && property.GetMethod.IsPublic, - TransferToServer = IsSetterSupported(property), - JsonConverter = GetJsonConverter(property), - Populate = ViewModelJsonConverter.CanConvertType(property.PropertyType) && property.GetMethod != null - }; + var propertyMap = new ViewModelPropertyMap( + property, + propertySerialization.ResolveName(property), + ProtectMode.None, + property.PropertyType, + transferToServer: IsSetterSupported(property), + transferAfterPostback: property.GetMethod != null && property.GetMethod.IsPublic, + transferFirstRequest: property.GetMethod != null && property.GetMethod.IsPublic, + populate: ViewModelJsonConverter.CanConvertType(property.PropertyType) && property.GetMethod != null + ); + propertyMap.JsonConverter = GetJsonConverter(property); foreach (ISerializationInfoAttribute attr in property.GetCustomAttributes().OfType()) { @@ -80,14 +79,14 @@ protected virtual IEnumerable GetProperties(Type type) propertyMap.ViewModelProtection = viewModelProtectionAttribute.Settings; } - propertyMap.ClientExtenders = + propertyMap.ClientExtenders.AddRange( property.GetCustomAttributes() .OrderBy(c => c.Order) - .Select(extender => new ClientExtenderInfo() { Name = extender.Name, Parameter = extender.Parameter }) - .ToList(); + .Select(extender => new ClientExtenderInfo(extender.Name, extender.Parameter)) + ); var validationAttributes = validationMetadataProvider.GetAttributesForProperty(property); - propertyMap.ValidationRules = validationRuleTranslator.TranslateValidationRules(property, validationAttributes).ToList(); + propertyMap.ValidationRules.AddRange(validationRuleTranslator.TranslateValidationRules(property, validationAttributes)); propertyMap.ValidateSettings(); diff --git a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelTypeMetadataSerializer.cs b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelTypeMetadataSerializer.cs index ebe32c6fdb..90e20a1ebd 100644 --- a/src/DotVVM.Framework/ViewModel/Serialization/ViewModelTypeMetadataSerializer.cs +++ b/src/DotVVM.Framework/ViewModel/Serialization/ViewModelTypeMetadataSerializer.cs @@ -46,7 +46,7 @@ public ViewModelTypeMetadataSerializer(IViewModelSerializationMapper viewModelSe this.viewModelSerializationMapper = viewModelSerializationMapper; } - public JToken SerializeTypeMetadata(IEnumerable usedSerializationMaps, ISet ignoredTypes = null) + public JToken SerializeTypeMetadata(IEnumerable usedSerializationMaps, ISet? ignoredTypes = null) { var dependentEnumTypes = new HashSet(); var resultJson = new JObject(); @@ -183,7 +183,7 @@ internal JToken GetTypeIdentifier(Type type, HashSet dependentObjectTypes, } else if (ReflectionUtils.IsCollection(type)) { - return new JArray(GetTypeIdentifier(ReflectionUtils.GetEnumerableType(type), dependentObjectTypes, dependentEnumTypes)); + return new JArray(GetTypeIdentifier(ReflectionUtils.GetEnumerableType(type)!, dependentObjectTypes, dependentEnumTypes)); } else { diff --git a/src/DotVVM.Framework/ViewModel/Validation/AttributeViewModelValidationMetadataProvider.cs b/src/DotVVM.Framework/ViewModel/Validation/AttributeViewModelValidationMetadataProvider.cs index 2c0d960e1b..c13b793022 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/AttributeViewModelValidationMetadataProvider.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/AttributeViewModelValidationMetadataProvider.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Reflection; diff --git a/src/DotVVM.Framework/ViewModel/Validation/IValidationRuleTranslator.cs b/src/DotVVM.Framework/ViewModel/Validation/IValidationRuleTranslator.cs index 24f09aa33c..a176f6fa90 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/IValidationRuleTranslator.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/IValidationRuleTranslator.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; diff --git a/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidationMetadataProvider.cs b/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidationMetadataProvider.cs index 06f790f247..2554ba81f3 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidationMetadataProvider.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidationMetadataProvider.cs @@ -1,4 +1,3 @@ -#nullable enable using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Reflection; diff --git a/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidator.cs b/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidator.cs index 2025571022..c3f5e37fb9 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidator.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/IViewModelValidator.cs @@ -1,5 +1,4 @@ -#nullable enable -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/DotVVM.Framework/ViewModel/Validation/ValidationErrorFactory.cs b/src/DotVVM.Framework/ViewModel/Validation/ValidationErrorFactory.cs index 2b58231244..dd4687043c 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/ValidationErrorFactory.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/ValidationErrorFactory.cs @@ -107,7 +107,7 @@ protected override Expression VisitMember(MemberExpression node) return base.VisitMember(node); } - private object Expand(Expression current) + private object? Expand(Expression current) { if (current is ConstantExpression constant) { diff --git a/src/DotVVM.Framework/ViewModel/Validation/ViewModelPropertyValidationRule.cs b/src/DotVVM.Framework/ViewModel/Validation/ViewModelPropertyValidationRule.cs index a84da9b0d7..fff2f8231a 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/ViewModelPropertyValidationRule.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/ViewModelPropertyValidationRule.cs @@ -7,13 +7,13 @@ namespace DotVVM.Framework.ViewModel.Validation public class ViewModelPropertyValidationRule { [JsonProperty("ruleName")] - public string ClientRuleName { get; set; } + public string? ClientRuleName { get; set; } [JsonProperty("errorMessage")] public string ErrorMessage => SourceValidationAttribute.FormatErrorMessage(PropertyName); [JsonProperty("parameters")] - public object[] Parameters { get; set; } + public object?[] Parameters { get; set; } [JsonIgnore] public ValidationAttribute SourceValidationAttribute { get; set; } @@ -25,10 +25,10 @@ public class ViewModelPropertyValidationRule public string StaticPropertyName { get; set; } [JsonIgnore] - public Func PropertyNameResolver { get; set; } + public Func? PropertyNameResolver { get; set; } public ViewModelPropertyValidationRule(ValidationAttribute sourceValidationAttribute, string staticPropertyName, - string clientRuleName = null, params object[] parameters) + string? clientRuleName = null, params object?[] parameters) { SourceValidationAttribute = sourceValidationAttribute ?? throw new ArgumentNullException(nameof(sourceValidationAttribute)); StaticPropertyName = staticPropertyName ?? throw new ArgumentNullException(nameof(staticPropertyName)); diff --git a/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationError.cs b/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationError.cs index a2063e7eff..ce67cbb30f 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationError.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationError.cs @@ -1,3 +1,4 @@ +#nullable disable using Newtonsoft.Json; namespace DotVVM.Framework.ViewModel.Validation @@ -17,4 +18,4 @@ public class ViewModelValidationError [JsonProperty("errorMessage")] public string ErrorMessage { get; set; } } -} \ No newline at end of file +} diff --git a/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationRuleTranslator.cs b/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationRuleTranslator.cs index d6b72dd5c4..123f971bb3 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationRuleTranslator.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidationRuleTranslator.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; diff --git a/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidator.cs b/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidator.cs index 896e7262e0..3b38279b72 100644 --- a/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidator.cs +++ b/src/DotVVM.Framework/ViewModel/Validation/ViewModelValidator.cs @@ -1,4 +1,3 @@ -#nullable enable using System; using System.Collections; using System.Collections.Generic; diff --git a/src/DotVVM.Samples.Common/DotvvmStartup.cs b/src/DotVVM.Samples.Common/DotvvmStartup.cs index 6c437f76e3..1a86100a1d 100644 --- a/src/DotVVM.Samples.Common/DotvvmStartup.cs +++ b/src/DotVVM.Samples.Common/DotvvmStartup.cs @@ -39,7 +39,6 @@ public class DotvvmStartup : IDotvvmStartup, IDotvvmServiceConfigurator public void Configure(DotvvmConfiguration config, string applicationPath) { config.DefaultCulture = "en-US"; - config.UseHistoryApiSpaNavigation = true; AddControls(config); AddStyles(config);