Skip to content

Commit 10002de

Browse files
committed
Fix some issues with incorrect binding result types
* ExpectedType property can now be null, when the assigned property is unknwon: - this means that CreateBinding will actually create a strongly typed instance, instead of just ValueBindingExpression<object> or similar * AutoUI uses props.Property instead of CreateValueBinding where possible
1 parent 3019446 commit 10002de

File tree

10 files changed

+27
-19
lines changed

10 files changed

+27
-19
lines changed

src/AutoUI/Core/PropertyHandlers/FormEditors/EnumComboBoxFormEditorProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public override DotvvmControl CreateControl(PropertyDisplayMetadata property, Au
4242
.SetCapability(props.Html)
4343
.SetProperty(c => c.Enabled, props.Enabled)
4444
.SetProperty(c => c.SelectionChanged, props.Changed)
45-
.SetProperty(c => c.SelectedValue, (IValueBinding)context.CreateValueBinding(property));
45+
.SetProperty(c => c.SelectedValue, props.Property);
4646

4747
if (isNullable)
4848
{

src/AutoUI/Core/PropertyHandlers/GridColumns/CheckBoxGridColumnProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public override bool CanHandleProperty(PropertyDisplayMetadata property, AutoUIC
1515
protected override GridViewColumn CreateColumnCore(PropertyDisplayMetadata property, AutoGridViewColumn.Props props, AutoUIContext context)
1616
{
1717
var column = new GridViewCheckBoxColumn();
18-
column.SetBinding(GridViewCheckBoxColumn.ValueBindingProperty, context.CreateValueBinding(property));
18+
column.SetBinding(GridViewCheckBoxColumn.ValueBindingProperty, props.Property);
1919
return column;
2020
}
2121
}

src/Framework/Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,20 @@ expression is JsNewExpression ||
174174

175175
public ResultTypeBindingProperty GetResultType(ParsedExpressionBindingProperty expression) => new ResultTypeBindingProperty(expression.Expression.Type);
176176

177-
public ExpectedTypeBindingProperty GetExpectedType(AssignedPropertyBindingProperty? property = null)
177+
public ExpectedTypeBindingProperty? GetExpectedType(AssignedPropertyBindingProperty? property = null)
178178
{
179179
var prop = property?.DotvvmProperty;
180-
if (prop == null) return new ExpectedTypeBindingProperty(typeof(object));
180+
if (prop == null) return null;
181181

182-
return new ExpectedTypeBindingProperty(prop.IsBindingProperty ? (prop.PropertyType.GenericTypeArguments.SingleOrDefault() ?? typeof(object)) : prop.PropertyType);
182+
if (prop.IsBindingProperty)
183+
{
184+
if (prop.PropertyType.GenericTypeArguments.SingleOrDefault() is {} type)
185+
return new ExpectedTypeBindingProperty(type);
186+
else
187+
return null;
188+
}
189+
190+
return new ExpectedTypeBindingProperty(prop.PropertyType);
183191
}
184192

185193
public BindingCompilationRequirementsAttribute GetAdditionalResolversFromProperty(AssignedPropertyBindingProperty property)
@@ -264,9 +272,9 @@ public NegatedBindingExpression NegateBinding(ParsedExpressionBindingProperty e,
264272
(Expression)Expression.Not(e.Expression)
265273
));
266274
}
267-
public ExpectedAsStringBindingExpression ExpectAsStringBinding(ParsedExpressionBindingProperty e, ExpectedTypeBindingProperty expectedType, IBinding binding)
275+
public ExpectedAsStringBindingExpression ExpectAsStringBinding(ParsedExpressionBindingProperty e, IBinding binding, ExpectedTypeBindingProperty? expectedType = null)
268276
{
269-
if (expectedType.Type == typeof(string))
277+
if (expectedType is {} && expectedType.Type == typeof(string))
270278
return new(binding);
271279

272280
return new(binding.DeriveBinding(new ExpectedTypeBindingProperty(typeof(string)), e));

src/Framework/Framework/Controls/GridViewCheckBoxColumn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class GridViewCheckBoxColumn : GridViewColumn
1515
/// Gets or sets a binding which retrieves the value to display from the current data item.
1616
/// </summary>
1717
[MarkupOptions(AllowHardCodedValue = false, Required = true)]
18-
public IStaticValueBinding<bool?> ValueBinding
18+
public IStaticValueBinding ValueBinding
1919
{
20-
get { return (IStaticValueBinding<bool?>)GetValueRaw(ValueBindingProperty)!; }
20+
get { return (IStaticValueBinding)GetValueRaw(ValueBindingProperty)!; }
2121
set { SetValue(ValueBindingProperty, value); }
2222
}
2323
public static readonly DotvvmProperty ValueBindingProperty =

src/Framework/Framework/Controls/GridViewDataSetBindingProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ ParameterExpression CreateParameter(DataContextStack dataContextStack, string na
119119
: null,
120120

121121
PageNumberText = isServerOnly switch {
122-
true => service.Cache.CreateResourceBinding<string>("_this + 1", pageIndexDataContext),
123-
false => service.Cache.CreateValueBinding<string>("_this + 1", pageIndexDataContext)
122+
true => service.Cache.CreateResourceBinding<string>("(_this + 1) + ''", pageIndexDataContext),
123+
false => service.Cache.CreateValueBinding<string>("(_this + 1) + ''", pageIndexDataContext)
124124
},
125125
HasMoreThanOnePage =
126126
GetValueBindingOrNull<IPageableGridViewDataSet<PagingOptions>, bool>(d => d.PagingOptions.PagesCount > 1) ??

src/Framework/Framework/Controls/Literal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool isFormattedType(Type? type) =>
9797
type != null && (type == typeof(float) || type == typeof(double) || type == typeof(decimal) ||
9898
type == typeof(DateTime) || type == typeof(DateOnly) || type == typeof(TimeOnly) || isFormattedType(Nullable.GetUnderlyingType(type)));
9999

100-
bool isFormattedTypeOrObj(Type? type) => type == typeof(object) || isFormattedType(type);
100+
bool isFormattedTypeOrObj(Type? type) => type is null || type == typeof(object) || isFormattedType(type);
101101

102102
return isFormattedType(binding?.ResultType) && isFormattedTypeOrObj(binding?.GetProperty<ExpectedTypeBindingProperty>(ErrorHandlingMode.ReturnNull)?.Type);
103103
}

src/Samples/Tests/Abstractions/SamplesRouteUrls.designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Samples/Tests/Tests/Control/GridViewTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,10 @@ public void Control_GridView_GridViewInlineEditing_PagingWhenEditing(string path
510510
[Theory]
511511
[InlineData(SamplesRouteUrls.ControlSamples_GridView_GridViewPagingSorting)]
512512
[InlineData(SamplesRouteUrls.ControlSamples_GridView_GridViewServerRender)]
513-
[InlineData(SamplesRouteUrls.ControlSamples_GridView_GridViewPagingSortingServerOnly)]
513+
[InlineData(SamplesRouteUrls.ControlSamples_GridView_GridViewPagingSortingServerSide)]
514514
[SampleReference(nameof(SamplesRouteUrls.ControlSamples_GridView_GridViewPagingSorting))]
515515
[SampleReference(nameof(SamplesRouteUrls.ControlSamples_GridView_GridViewServerRender))]
516-
[SampleReference(nameof(SamplesRouteUrls.ControlSamples_GridView_GridViewPagingSortingServerOnly))]
516+
[SampleReference(nameof(SamplesRouteUrls.ControlSamples_GridView_GridViewPagingSortingServerSide))]
517517
public void Control_GridView_GridViewPagingSortingBase(string path)
518518
{
519519
RunInAllBrowsers(browser => {

src/Tests/ControlTests/testoutputs/DataPagerTests.CommandDataPager.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<!-- ko foreach: { data: Customers()?.PagingOptions()?.NearPageIndexes } -->
1212
<li data-bind="css: { active: $data == $parent.Customers()?.PagingOptions()?.PageIndex() }">
1313
<!-- ko if: $data != $parent.Customers()?.PagingOptions()?.PageIndex() -->
14-
<a data-bind="text: dotvvm.globalize.bindingNumberToString($data + 1)" href="javascript:;" onclick="dotvvm.postBack(this,[&quot;Customers()?.PagingOptions()?.NearPageIndexes/[$index]&quot;],&quot;J4s1chtqLBUO+Bt2&quot;,&quot;&quot;,null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;"></a>
14+
<a data-bind="text: $data + 1" href="javascript:;" onclick="dotvvm.postBack(this,[&quot;Customers()?.PagingOptions()?.NearPageIndexes/[$index]&quot;],&quot;J4s1chtqLBUO+Bt2&quot;,&quot;&quot;,null,[],[],undefined).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;"></a>
1515
<!-- /ko -->
1616
<!-- ko if: $data == $parent.Customers()?.PagingOptions()?.PageIndex() -->
17-
<span data-bind="text: dotvvm.globalize.bindingNumberToString($data + 1)"></span>
17+
<span data-bind="text: $data + 1"></span>
1818
<!-- /ko -->
1919
</li>
2020
<!-- /ko -->

src/Tests/ControlTests/testoutputs/DataPagerTests.StaticCommandPager.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
<!-- ko foreach: { data: Customers()?.PagingOptions()?.NearPageIndexes } -->
1818
<li data-bind="css: { active: $data == $parent.Customers()?.PagingOptions()?.PageIndex() }">
1919
<!-- ko if: $data != $parent.Customers()?.PagingOptions()?.PageIndex() -->
20-
<a data-bind="text: dotvvm.globalize.bindingNumberToString($data + 1)" href="javascript:;" onclick="dotvvm.applyPostbackHandlers(async (options) => {
20+
<a data-bind="text: $data + 1" href="javascript:;" onclick="dotvvm.applyPostbackHandlers(async (options) => {
2121
let cx = options.knockoutContext;
2222
return await dotvvm.dataSet.loadDataSet(cx.$parent.Customers, (options) => dotvvm.dataSet.translations.PagingOptions.goToPage(ko.unwrap(options).PagingOptions, cx.$rawData.state), cx.$gridViewDataSetHelper.loadDataSet, cx.$gridViewDataSetHelper.postProcessor);
2323
},this).catch(dotvvm.log.logPostBackScriptError);event.stopPropagation();return false;"></a>
2424
<!-- /ko -->
2525
<!-- ko if: $data == $parent.Customers()?.PagingOptions()?.PageIndex() -->
26-
<span data-bind="text: dotvvm.globalize.bindingNumberToString($data + 1)"></span>
26+
<span data-bind="text: $data + 1"></span>
2727
<!-- /ko -->
2828
</li>
2929
<!-- /ko -->

0 commit comments

Comments
 (0)