Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate DotVVM.Framework to nullable references #1118

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions src/DotVVM.Core/Utils/TextUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using DotVVM;
using DotVVM;

namespace DotVVM.Core.Utils
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/DotVVM.Framework.Testing/BindingTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
4 changes: 2 additions & 2 deletions src/DotVVM.Framework.Testing/ControlTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/DotVVM.Framework.Testing/FakeCommandBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FakeCommandBinding(ParametrizedCode commandJavascript, BindingDelegate bi

public ImmutableArray<IActionFilter> ActionFilters => ImmutableArray<IActionFilter>.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;
Expand Down
65 changes: 32 additions & 33 deletions src/DotVVM.Framework.Tests/Binding/CustomExtensionMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expression>(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") });
var result = Expression.Lambda<Func<int>>(expression).Compile().Invoke();
Expand All @@ -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<Expression>(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding.AmbiguousExtensions") });
var result = Expression.Lambda<Func<int>>(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<Expression>(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding.AmbiguousExtensions") });
Expand All @@ -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<Expression>(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding.AmbiguousExtensions") });
var result = Expression.Lambda<Func<int>>(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<Expression>(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding") });
Expand All @@ -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<Expression>(), new[] { new NamespaceImport("DotVVM.Framework.Tests.Binding"), new NamespaceImport("DotVVM.Framework.Tests.Binding") });
Expand All @@ -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") });
Expand All @@ -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<Expression>(),
Expand Down
40 changes: 20 additions & 20 deletions src/DotVVM.Framework.Tests/Binding/ExpressionHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/DotVVM.Framework.Tests/DotVVM.Framework.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<!-- This async method lacks 'await' -->
<NoWarn>$(NoWarn);CS1998</NoWarn>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<SignAssembly>True</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ public void AuxOptions()
c.ApplicationPhysicalPath = "/opt/myApp";
c.ClientSideValidation = false;
c.DefaultCulture = "cs-CZ";
c.UseHistoryApiSpaNavigation = true;

checkConfig(c);
}
Expand Down
4 changes: 1 addition & 3 deletions src/DotVVM.Framework.Tests/ViewModel/SerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ static ViewModelJsonConverter CreateConverter(bool isPostback, JObject encrypted
config.ServiceProvider.GetRequiredService<IViewModelSerializationMapper>(),
config.ServiceProvider,
encryptedValues
) {
UsedSerializationMaps = new HashSet<ViewModelSerializationMap>()
};
);
}

static string Serialize<T>(T viewModel, out JObject encryptedValues, bool isPostback = false)
Expand Down
3 changes: 1 addition & 2 deletions src/DotVVM.Framework/Binding/ActiveDotvvmProperty.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using DotVVM.Framework.Controls;
using DotVVM.Framework.Controls;
using DotVVM.Framework.Runtime;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion src/DotVVM.Framework/Binding/ActiveDotvvmPropertyGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
1 change: 0 additions & 1 deletion src/DotVVM.Framework/Binding/AttachedPropertyAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
5 changes: 2 additions & 3 deletions src/DotVVM.Framework/Binding/BindingCollectionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using DotVVM.Framework.Hosting;
using DotVVM.Framework.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -29,7 +28,7 @@ internal static void RegisterJavascriptTranslations(JavascriptTranslatableMethod
IJavascriptMethodTranslator memberAccess(string name) =>
new GenericMethodCompiler(
builder: a => a[0].CastTo<JsObjectExpression>().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)));
Expand Down
1 change: 0 additions & 1 deletion src/DotVVM.Framework/Binding/BindingCombinator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System.Runtime.CompilerServices;
using System;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System;
using System;
using System.Collections.Generic;
using System.Text;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System;
using System;
using System.Collections.Immutable;
using System.Linq;

Expand Down
3 changes: 1 addition & 2 deletions src/DotVVM.Framework/Binding/BindingCompilationService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down
3 changes: 1 addition & 2 deletions src/DotVVM.Framework/Binding/BindingFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down
5 changes: 2 additions & 3 deletions src/DotVVM.Framework/Binding/BindingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using DotVVM.Framework.Controls;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -235,7 +234,7 @@ public static T GetCommandDelegate<T>(this ICommandBinding<T> binding, DotvvmBin
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)
{
Expand All @@ -251,7 +250,7 @@ public static object GetBindingValue(this IBinding binding, DotvvmBindableObject
/// <summary>
/// Creates new `TBinding` with the original DataContextStack, LocationInfo, AdditionalResolvers and BindingCompilationService.
/// </summary>
public static TBinding DeriveBinding<TBinding>(this TBinding binding, DataContextStack newDataContext, Expression expression, params object[] properties)
public static TBinding DeriveBinding<TBinding>(this TBinding binding, DataContextStack newDataContext, Expression expression, params object?[] properties)
where TBinding : IBinding
{
return binding.DeriveBinding(
Expand Down
3 changes: 1 addition & 2 deletions src/DotVVM.Framework/Binding/BindingPageInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using DotVVM.Framework.Hosting;
using DotVVM.Framework.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
5 changes: 2 additions & 3 deletions src/DotVVM.Framework/Binding/BindingProperties.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/DotVVM.Framework/Binding/BindingPropertyException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down