Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into system.text.json
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Jul 12, 2024
2 parents f7fa2e7 + b44b396 commit 5b5b962
Show file tree
Hide file tree
Showing 91 changed files with 1,242 additions and 413 deletions.
2 changes: 1 addition & 1 deletion .github/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs:
shell: bash
# .NET
- uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
Expand Down
4 changes: 2 additions & 2 deletions src/Analyzers/Analyzers.Tests/DotVVM.Analyzers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.MSTest" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.MSTest" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Analyzers.Serializability;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Xunit;

using VerifyCS = DotVVM.Analyzers.Tests.CSharpAnalyzerVerifier<
Expand All @@ -14,7 +10,7 @@ namespace DotVVM.Analyzers.Tests.Serializability
public class ViewModelSerializabilityTest
{
[Fact]
public async void Test_NotSerializableProperty_RegularClass()
public async Task Test_NotSerializableProperty_RegularClass()
{
var test = @"
using System;
Expand All @@ -33,7 +29,7 @@ public class RegularClass
}

[Fact]
public async void Test_NotSerializableProperty_ViewModel()
public async Task Test_NotSerializableProperty_ViewModel()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.ViewModel;
Expand All @@ -54,7 +50,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_SerializableRecordProperty_ViewModel()
public async Task Test_SerializableRecordProperty_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -81,7 +77,7 @@ internal static class IsExternalInit {}
}

[Fact]
public async void Test_NotSerializableList_ViewModel()
public async Task Test_NotSerializableList_ViewModel()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.ViewModel;
Expand All @@ -103,7 +99,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_WarnAboutInterface_ViewModel()
public async Task Test_WarnAboutInterface_ViewModel()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.ViewModel;
Expand All @@ -124,7 +120,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_Primitives_AreSerializableAndSupported_ViewModel()
public async Task Test_Primitives_AreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand Down Expand Up @@ -155,7 +151,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_Enums_AreSerializableAndSupported_ViewModel()
public async Task Test_Enums_AreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -180,7 +176,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_DotVVMFriendlyObjects_AreSerializableAndSupported_ViewModel()
public async Task Test_DotVVMFriendlyObjects_AreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -205,7 +201,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_NullablePrimitives_AreSerializableAndSupported_ViewModel()
public async Task Test_NullablePrimitives_AreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand Down Expand Up @@ -236,7 +232,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_NullableStructs_AreSerializableAndSupported_ViewModel()
public async Task Test_NullableStructs_AreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -258,7 +254,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_NullableReferenceTypes_AreSerializableAndSupported_ViewModel()
public async Task Test_NullableReferenceTypes_AreSerializableAndSupported_ViewModel()
{
var test = @"
#nullable enable
Expand All @@ -285,7 +281,7 @@ public class Test
}

[Fact]
public async void Test_CommonTypesAreSerializableAndSupported_ViewModel()
public async Task Test_CommonTypesAreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -309,7 +305,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_CollectionAreSerializableAndSupported_ViewModel()
public async Task Test_CollectionAreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -330,7 +326,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_NoWarningsForEnumerables_ViewModel()
public async Task Test_NoWarningsForEnumerables_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -352,7 +348,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_UserTypesAreSerializableAndSupported_ViewModel()
public async Task Test_UserTypesAreSerializableAndSupported_ViewModel()
{
var test = @"
using DotVVM.Framework.ViewModel;
Expand Down Expand Up @@ -381,7 +377,7 @@ public class UserType
}

[Fact]
public async void Test_NotSupportedProperty_ViewModel()
public async Task Test_NotSupportedProperty_ViewModel()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.ViewModel;
Expand All @@ -402,7 +398,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_PublicFieldsInViewModel()
public async Task Test_PublicFieldsInViewModel()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.ViewModel;
Expand All @@ -421,7 +417,7 @@ public class DefaultViewModel : DotvvmViewModelBase
VerifyCS.Diagnostic(ViewModelSerializabilityAnalyzer.DoNotUseFieldsRule).WithLocation(0));
}
[Fact]
public async void Test_ConstFieldsInViewModel()
public async Task Test_ConstFieldsInViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -441,7 +437,7 @@ public class DefaultViewModel : DotvvmViewModelBase


[Fact]
public async void Test_StaticPropertiesInViewModel()
public async Task Test_StaticPropertiesInViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -463,7 +459,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_StaticFieldsInViewModel()
public async Task Test_StaticFieldsInViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -485,7 +481,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_NonPublicFieldsInViewModel()
public async Task Test_NonPublicFieldsInViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -505,7 +501,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_NonPublicPropertiesInViewModel()
public async Task Test_NonPublicPropertiesInViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -525,7 +521,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_IgnoreNonSerializedMembers_BindDirectionNone_ViewModel()
public async Task Test_IgnoreNonSerializedMembers_BindDirectionNone_ViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -552,7 +548,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_SelfReferencingTypes_GenericArgs_ViewModel()
public async Task Test_SelfReferencingTypes_GenericArgs_ViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -571,7 +567,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_SelfReferencingTypes_Properties_ViewModel()
public async Task Test_SelfReferencingTypes_Properties_ViewModel()
{
var text = @"
using DotVVM.Framework.ViewModel;
Expand All @@ -591,7 +587,7 @@ public class DefaultViewModel : DotvvmViewModelBase


[Fact]
public async void Test_WhiteListedDotvvmTypes_Properties_ViewModel()
public async Task Test_WhiteListedDotvvmTypes_Properties_ViewModel()
{
var text = @"
using DotVVM.Framework.Controls;
Expand All @@ -612,7 +608,7 @@ public class DefaultViewModel : DotvvmViewModelBase
}

[Fact]
public async void Test_OverridenSerialization_OnProperty_ViewModel()
public async Task Test_OverridenSerialization_OnProperty_ViewModel()
{
var text = @"
using DotVVM.Framework.Controls;
Expand Down Expand Up @@ -640,7 +636,7 @@ public class NonSerializable
}

[Fact]
public async void Test_OverridenSerialization_OnTypeDeclaration_ViewModel()
public async Task Test_OverridenSerialization_OnTypeDeclaration_ViewModel()
{
var text = @"
using DotVVM.Framework.Controls;
Expand Down Expand Up @@ -668,7 +664,7 @@ public class NonSerializable
}

[Fact]
public async void Test_InnerTypesWithNonSerializableProperties_RegularClass()
public async Task Test_InnerTypesWithNonSerializableProperties_RegularClass()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.Controls;
Expand All @@ -695,7 +691,7 @@ public class Entry
}

[Fact]
public async void Test_GenericReferenceType_Properties_ViewModel()
public async Task Test_GenericReferenceType_Properties_ViewModel()
{
await VerifyCS.VerifyAnalyzerAsync(@"
using DotVVM.Framework.Controls;
Expand Down Expand Up @@ -724,7 +720,7 @@ public class WrappedValue<T>
}

[Fact]
public async void Test_GenericViewModelType_Properties_ViewModel()
public async Task Test_GenericViewModelType_Properties_ViewModel()
{
var text = @"
using DotVVM.Framework.Controls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public override DotvvmControl CreateControl(PropertyDisplayMetadata property, Au
LocalizableString.CreateNullable(displayAttribute?.Name, displayAttribute?.ResourceType) ??
LocalizableString.Constant(name.Humanize());
var title = LocalizableString.CreateNullable(displayAttribute?.Description, displayAttribute?.ResourceType);
return (name, displayName, title);
})
.Select(e => new SelectorItem(e.displayName.ToBinding(context.BindingService), new(Enum.Parse(enumType, e.name)))
.AddAttribute("title", e.title?.ToBinding(context.BindingService)));
var enumJsString = ReflectionUtils.ToEnumString(enumType, name);

return new SelectorItem(displayName.ToBinding(context.BindingService), new(enumJsString))
.AddAttribute("title", title?.ToBinding(context.BindingService));
});

var control = new ComboBox()
.SetCapability(props.Html)
Expand Down
9 changes: 9 additions & 0 deletions src/Framework/Framework/Binding/ValueOrBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ public TResult ProcessValueBinding<TResult>(DotvvmBindableObject control, Func<T
return processValue(this.Evaluate(control)!);
}

/// <summary> If this contains a `resource` binding, it is evaluated and its value placed in <see cref="ValueOrDefault" /> property. `value`, and all other bindings are untouched and remain in the <see cref="BindingOrDefault"/> property. </summary>
public ValueOrBinding<T?> EvaluateResourceBinding(DotvvmBindableObject control)
{
if (binding is null or IValueBinding or not IStaticValueBinding) return this;

var value = this.Evaluate(control);
return new ValueOrBinding<T?>(value);
}

public static explicit operator ValueOrBinding<T>(T val) => new ValueOrBinding<T>(val);

public const string EqualsDisabledReason = "Equals is disabled on ValueOrBinding<T> as it may lead to unexpected behavior. Please use object.ReferenceEquals for reference comparison or evaluate the ValueOrBinding<T> and compare the value. Or use IsNull/NotNull for nullchecks on bindings.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public IControlResolverMetadata ResolveControl(IControlType controlType)
/// </summary>
protected abstract IControlType FindMarkupControl(string file);

/// <summary> Returns a list of possible DotVVM controls. </summary>
/// <remark>Used only for smart error handling, the list isn't necessarily complete, but doesn't contain false positives.</remark>
public abstract IEnumerable<(string tagPrefix, string? tagName, IControlType type)> EnumerateControlTypes();

/// <summary>
/// Gets the control metadata.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Compilation.Parser.Dothtml.Parser;

Expand All @@ -7,7 +8,7 @@ namespace DotVVM.Framework.Compilation.ControlTree
public static class ControlTreeHelper
{
public static bool HasEmptyContent(this IAbstractControl control)
=> control.Content.All(c => !DothtmlNodeHelper.IsNotEmpty(c.DothtmlNode)); // allow only whitespace literals
=> control.Content.All(c => DothtmlNodeHelper.IsEmpty(c.DothtmlNode)); // allow only whitespace literals

public static bool HasProperty(this IAbstractControl control, IPropertyDescriptor property)
{
Expand All @@ -27,6 +28,19 @@ public static bool HasPropertyValue(this IAbstractControl control, IPropertyDesc
return value;
}

public static Dictionary<string, IAbstractPropertySetter> GetPropertyGroup(this IAbstractControl control, IPropertyGroupDescriptor group)
{
var result = new Dictionary<string, IAbstractPropertySetter>();
foreach (var prop in control.Properties)
{
if (prop.Key is IGroupedPropertyDescriptor member && member.PropertyGroup == group)
{
result.Add(member.GroupMemberName, prop.Value);
}
}
return result;
}

public static IPropertyDescriptor GetHtmlAttributeDescriptor(this IControlResolverMetadata metadata, string name)
=> metadata.GetPropertyGroupMember("", name);
public static IPropertyDescriptor GetPropertyGroupMember(this IControlResolverMetadata metadata, string prefix, string name)
Expand Down
Loading

0 comments on commit 5b5b962

Please sign in to comment.