Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ public static IEnumerable<Instruction> ProvideValue(VariableDefinitionReference

if (bindingExtensionType.Value.Item3 == "BindingExtension")
{
// extension.TypedBinding.ConverterCulture = extension.ConverterCulture;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For full parity, consider whether ConverterCulture should also be supported on TemplateBindingExtension, which shares much of this binding-construction path. Right now ConverterCulture is wired for Binding/MultiBinding but a TemplateBinding with a converter won't honor a culture. Non-blocking — flagging for completeness/consistency.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this out intentionally for this PR. TemplateBindingExtension currently has no ConverterCulture API surface, so adding parity there would require a separate public API addition beyond the Binding/MultiBinding support in scope here.

yield return Create(Ldloc, vardefref.VariableDefinition);
yield return Create(Callvirt, module.ImportPropertyGetterReference(context.Cache, bindingExtensionType.Value, propertyName: "TypedBinding"));
yield return Create(Ldloc, vardefref.VariableDefinition);
yield return Create(Callvirt, module.ImportPropertyGetterReference(context.Cache, bindingExtensionType.Value, propertyName: "ConverterCulture"));
yield return Create(Callvirt, module.ImportPropertySetterReference(context.Cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.Internals", "TypedBindingBase"), propertyName: "ConverterCulture"));
// // extension.TypedBinding.Source = extension.Source;
yield return Create(Ldloc, vardefref.VariableDefinition);
yield return Create(Callvirt, module.ImportPropertyGetterReference(context.Cache, bindingExtensionType.Value, propertyName: "TypedBinding"));
Expand Down
21 changes: 19 additions & 2 deletions src/Controls/src/Core/Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class Binding : BindingBase
public const string SelfPath = ".";
IValueConverter _converter;
object _converterParameter;
CultureInfo _converterCulture;

BindingExpression _expression;
string _path;
Expand Down Expand Up @@ -81,6 +82,21 @@ public object ConverterParameter
}
}

/// <summary>
/// Gets or sets the culture information used by the converter.
/// </summary>
[TypeConverter(typeof(CultureInfoConverter))]
public CultureInfo ConverterCulture
{
get { return _converterCulture ?? CultureInfo.CurrentUICulture; }
set
{
ThrowIfApplied();

_converterCulture = value;
}
}

/// <summary>
/// Gets or sets the property path to bind to on the source object.
/// </summary>
Expand Down Expand Up @@ -195,6 +211,7 @@ internal override BindingBase Clone()
{
Converter = Converter,
ConverterParameter = ConverterParameter,
ConverterCulture = _converterCulture,
StringFormat = StringFormat,
Source = Source,
UpdateSourceEventName = UpdateSourceEventName,
Expand All @@ -211,15 +228,15 @@ internal override BindingBase Clone()
internal override object GetSourceValue(object value, Type targetPropertyType)
{
if (Converter != null)
value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
value = Converter.Convert(value, targetPropertyType, ConverterParameter, ConverterCulture);

return base.GetSourceValue(value, targetPropertyType);
}

internal override object GetTargetValue(object value, Type sourcePropertyType)
{
if (Converter != null)
value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, ConverterCulture);

return base.GetTargetValue(value, sourcePropertyType);
}
Expand Down
21 changes: 19 additions & 2 deletions src/Controls/src/Core/MultiBinding.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Xaml.Diagnostics;
Expand All @@ -14,6 +15,7 @@ namespace Microsoft.Maui.Controls
public sealed class MultiBinding : BindingBase
{
IMultiValueConverter _converter;
CultureInfo _converterCulture;
object _converterParameter;
IList<BindingBase> _bindings;
BindableProperty _targetProperty;
Expand All @@ -35,6 +37,20 @@ public IMultiValueConverter Converter
}
}

/// <summary>
/// Gets or sets the culture in which to evaluate the <see cref="Converter"/>.
/// </summary>
[TypeConverter(typeof(CultureInfoConverter))]
public CultureInfo ConverterCulture
{
get { return _converterCulture ?? CultureInfo.CurrentUICulture; }
set
{
ThrowIfApplied();
_converterCulture = value;
}
}

/// <summary>
/// Gets or sets an optional parameter to pass to the <see cref="Converter"/>.
/// </summary>
Expand Down Expand Up @@ -70,6 +86,7 @@ internal override BindingBase Clone()
var clone = new MultiBinding()
{
Converter = Converter,
ConverterCulture = _converterCulture,
ConverterParameter = ConverterParameter,
Bindings = bindingsclone,
FallbackValue = FallbackValue,
Expand Down Expand Up @@ -208,7 +225,7 @@ internal override object GetSourceValue(object value, Type targetPropertyType)
{
var valuearray = value as object[];
if (valuearray != null && Converter != null)
value = Converter.Convert(valuearray, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
value = Converter.Convert(valuearray, targetPropertyType, ConverterParameter, ConverterCulture);

if (valuearray != null && Converter == null && StringFormat != null && BindingBase.TryFormat(StringFormat, valuearray, out var formatted))
return formatted;
Expand All @@ -227,7 +244,7 @@ internal override object GetTargetValue(object value, Type sourcePropertyType)
var types = new Type[_bpProxies.Length];
for (var i = 0; i < _bpProxies.Length; i++)
types[i] = values[i]?.GetType() ?? typeof(object);
return Converter.ConvertBack(value, types, ConverterParameter, CultureInfo.CurrentUICulture);
return Converter.ConvertBack(value, types, ConverterParameter, ConverterCulture);
}

return base.GetTargetValue(value, sourcePropertyType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#nullable enable
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
*REMOVED*~static readonly Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.DefaultForegroundColor -> Microsoft.Maui.Graphics.Color
*REMOVED*~static readonly Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.DefaultTitleColor -> Microsoft.Maui.Graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#nullable enable
*REMOVED*~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Microsoft.Maui.Controls.BoxView.~BoxView() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#nullable enable
*REMOVED*~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Microsoft.Maui.Controls.BoxView.~BoxView() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#nullable enable
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#nullable enable
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#nullable enable
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Microsoft.Maui.Controls.BoxView.~BoxView() -> void
Expand Down
26 changes: 16 additions & 10 deletions src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#nullable enable
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
~Microsoft.Maui.Controls.Binding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Binding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.MultiBinding.ConverterCulture.set -> void
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.get -> System.Globalization.CultureInfo
~Microsoft.Maui.Controls.Internals.TypedBindingBase.ConverterCulture.set -> void
~Microsoft.Maui.Controls.BackButtonBehavior.AccessibilityLabel.get -> string
~Microsoft.Maui.Controls.BackButtonBehavior.AccessibilityLabel.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.BaseShellItem.BadgeColor.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeText.get -> string
~Microsoft.Maui.Controls.BaseShellItem.BadgeText.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeTextColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.BaseShellItem.BadgeTextColor.set -> void
~Microsoft.Maui.Controls.BoxView.Fill.get -> Microsoft.Maui.Controls.Brush
~Microsoft.Maui.Controls.BoxView.Fill.set -> void
Microsoft.Maui.Controls.BoxView.~BoxView() -> void
Microsoft.Maui.Controls.ImageSource.InvalidateStyle() -> void
Microsoft.Maui.Controls.LongPressGestureRecognizer
Expand Down Expand Up @@ -47,16 +63,6 @@ static readonly Microsoft.Maui.Controls.LongPressGestureRecognizer.NumberOfTouch
static readonly Microsoft.Maui.Controls.LongPressGestureRecognizer.StateProperty -> Microsoft.Maui.Controls.BindableProperty!
virtual Microsoft.Maui.Controls.LongPressedEventArgs.GetPosition(Microsoft.Maui.Controls.Element? relativeTo) -> Microsoft.Maui.Graphics.Point?
virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui.Controls.Element? relativeTo) -> Microsoft.Maui.Graphics.Point?
~Microsoft.Maui.Controls.BackButtonBehavior.AccessibilityLabel.get -> string
~Microsoft.Maui.Controls.BackButtonBehavior.AccessibilityLabel.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.BaseShellItem.BadgeColor.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeText.get -> string
~Microsoft.Maui.Controls.BaseShellItem.BadgeText.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeTextColor.get -> Microsoft.Maui.Graphics.Color
~Microsoft.Maui.Controls.BaseShellItem.BadgeTextColor.set -> void
~Microsoft.Maui.Controls.BoxView.Fill.get -> Microsoft.Maui.Controls.Brush
~Microsoft.Maui.Controls.BoxView.Fill.set -> void
~Microsoft.Maui.Controls.Editor.ReturnCommand.get -> System.Windows.Input.ICommand
~Microsoft.Maui.Controls.Editor.ReturnCommand.set -> void
~Microsoft.Maui.Controls.Editor.ReturnCommandParameter.get -> object
Expand Down
20 changes: 18 additions & 2 deletions src/Controls/src/Core/TypedBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class TypedBindingBase : BindingBase
{
IValueConverter _converter;
object _converterParameter;
CultureInfo _converterCulture;
object _source;
string _updateSourceEventName;

Expand All @@ -42,6 +43,20 @@ public object ConverterParameter
}
}

/// <summary>Gets or sets the culture information used by the converter.</summary>
[TypeConverter(typeof(CultureInfoConverter))]
public CultureInfo ConverterCulture
{
get { return _converterCulture ?? CultureInfo.CurrentUICulture; }
set
{
ThrowIfApplied();
_converterCulture = value;
}
}

internal CultureInfo ConverterCultureValue => _converterCulture;

/// <summary>Gets or sets the source object for the binding.</summary>
public object Source
{
Expand Down Expand Up @@ -237,6 +252,7 @@ internal override BindingBase Clone()
Mode = Mode,
Converter = Converter,
ConverterParameter = ConverterParameter,
ConverterCulture = ConverterCultureValue,
StringFormat = StringFormat,
Source = Source,
UpdateSourceEventName = UpdateSourceEventName,
Expand All @@ -263,15 +279,15 @@ internal override void ApplyToResolvedSource(object source, BindableObject targe
internal override object GetSourceValue(object value, Type targetPropertyType)
{
if (Converter != null)
value = Converter.Convert(value, targetPropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
value = Converter.Convert(value, targetPropertyType, ConverterParameter, ConverterCulture);

return base.GetSourceValue(value, targetPropertyType);
}

internal override object GetTargetValue(object value, Type sourcePropertyType)
{
if (Converter != null)
value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, CultureInfo.CurrentUICulture);
value = Converter.ConvertBack(value, sourcePropertyType, ConverterParameter, ConverterCulture);

//return base.GetTargetValue(value, sourcePropertyType);
return value;
Expand Down
5 changes: 4 additions & 1 deletion src/Controls/src/SourceGen/CompiledBindingMarkup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public bool TryCompileBinding(ITypeSymbol sourceType, bool isTemplateBinding, ou
propertyFlags |= BindingPropertyFlags.FallbackValue;
if (_node.HasProperty("TargetNullValue"))
propertyFlags |= BindingPropertyFlags.TargetNullValue;
var hasConverterCulture = !isTemplateBinding && _node.HasProperty("ConverterCulture");

//Generate the complete inline binding creation method
using var stringWriter = new StringWriter();
Expand Down Expand Up @@ -191,7 +192,7 @@ public bool TryCompileBinding(ITypeSymbol sourceType, bool isTemplateBinding, ou
code.Indent--;

// Object initializer if any properties are set
if (propertyFlags != BindingPropertyFlags.None)
if (propertyFlags != BindingPropertyFlags.None || hasConverterCulture)
{
code.WriteLine();
code.WriteLine("{");
Expand All @@ -203,6 +204,8 @@ public bool TryCompileBinding(ITypeSymbol sourceType, bool isTemplateBinding, ou
code.WriteLine("Converter = extension.Converter,");
if (propertyFlags.HasFlag(BindingPropertyFlags.ConverterParameter))
code.WriteLine("ConverterParameter = extension.ConverterParameter,");
if (hasConverterCulture)
code.WriteLine("ConverterCulture = extension.ConverterCulture,");
if (propertyFlags.HasFlag(BindingPropertyFlags.StringFormat))
code.WriteLine("StringFormat = extension.StringFormat,");
if (propertyFlags.HasFlag(BindingPropertyFlags.Source))
Expand Down
25 changes: 21 additions & 4 deletions src/Controls/src/SourceGen/KnownMarkups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Xml;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.Maui.Controls.Xaml;

using static System.String;
Expand Down Expand Up @@ -404,10 +405,15 @@ private static bool ProvideValueForBindingExtension(ElementNode markupNode, Inde
}
else
{
value = expression +
$"{{ UpdateSourceEventName = {extVariable.ValueAccessor}.UpdateSourceEventName, " +
$"FallbackValue = {extVariable.ValueAccessor}.FallbackValue, " +
$"TargetNullValue = {extVariable.ValueAccessor}.TargetNullValue }}";
var objectInitializer = new StringBuilder()
.Append($"{{ UpdateSourceEventName = {extVariable.ValueAccessor}.UpdateSourceEventName, ");
if (markupNode.HasProperty("ConverterCulture"))
objectInitializer.Append($"ConverterCulture = {extVariable.ValueAccessor}.ConverterCulture, ");
objectInitializer
.Append($"FallbackValue = {extVariable.ValueAccessor}.FallbackValue, ")
.Append($"TargetNullValue = {extVariable.ValueAccessor}.TargetNullValue }}");

value = expression + objectInitializer;
return true;
}
}
Expand Down Expand Up @@ -441,6 +447,17 @@ private static bool ProvideValueForBindingExtension(ElementNode markupNode, Inde
expression += ") {";
if (markupNode.Properties.TryGetValue(new XmlName(null, "UpdateSourceEventName"), out var updateSourceEventNameNode))
expression += $"UpdateSourceEventName = {getNodeValue(updateSourceEventNameNode, context.Compilation.GetTypeByMetadataName("System.String")!).ValueAccessor}, ";
if (markupNode.Properties.TryGetValue(new XmlName(null, "ConverterCulture"), out var converterCultureNode))
{
if (converterCultureNode is ValueNode { Value: string converterCulture })
{
expression += $"ConverterCulture = global::System.Globalization.CultureInfo.GetCultureInfo({SymbolDisplay.FormatLiteral(converterCulture, true)}), ";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source-generated binding code instantiates a fresh CultureInfoConverter for each binding when a ConverterCulture string is present. Since CultureInfoConverter is stateless, consider emitting a single cached/static converter (or converting the culture string once at generation time into a CultureInfo.GetCultureInfo("...") call) to avoid a per-binding allocation on a hot path. Minor — not blocking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion — addressed in e21a5d0. Literal converter culture values now emit CultureInfo.GetCultureInfo("..."), so generated code no longer allocates a CultureInfoConverter per binding.

else
{
expression += $"ConverterCulture = {getNodeValue(converterCultureNode, context.Compilation.GetTypeByMetadataName("System.Globalization.CultureInfo")!).ValueAccessor}, ";
}
}
if (markupNode.Properties.TryGetValue(new XmlName(null, "FallbackValue"), out var fallbackValueNode))
expression += $"FallbackValue = {getNodeValue(fallbackValueNode, context.Compilation.GetTypeByMetadataName("System.Object")!).ValueAccessor}, ";
if (markupNode.Properties.TryGetValue(new XmlName(null, "TargetNullValue"), out var targetNullValueNode))
Expand Down
Loading
Loading