-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Trimming] Use new feature switch definition attribute and enable ana…
…lyzers in Controls.Core.csproj (#21621) Contributes to #18658 We can use `[FeatureSwitchDefinition("...")]` attributes instead of `ILLink.Substitutions.xml` since dotnet/runtime#99338 has been merged and has flown into MAUI. * Use new FeatureSwitchDefinition attributes instead of ILLink substitutions * Update comment * Update Controls * Update Compatibility * Disable analyzers in Controls.Core on Tizen * Skip warning on Windows * Add RUC attributes to NativeBindingExtensions * Add RUC attributes to NativeBindingService * Add comment explaining why DoNothing moved from Binding to MultiBinding
- Loading branch information
1 parent
f118f45
commit ac6cc71
Showing
37 changed files
with
293 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Compatibility/Core/src/Android/Extensions/NativeBindingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/Compatibility/Core/src/Tizen/Extensions/NativeBindingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.Maui.Controls | ||
{ | ||
internal static class BindingExpressionHelper | ||
{ | ||
static readonly Type[] DecimalTypes = { typeof(float), typeof(decimal), typeof(double) }; | ||
|
||
internal static bool TryConvert(ref object value, BindableProperty targetProperty, Type convertTo, bool toTarget) | ||
{ | ||
if (value == null) | ||
return !convertTo.GetTypeInfo().IsValueType || Nullable.GetUnderlyingType(convertTo) != null; | ||
try | ||
{ | ||
if ((toTarget && targetProperty.TryConvert(ref value)) || (!toTarget && convertTo.IsInstanceOfType(value))) | ||
return true; | ||
} | ||
catch (InvalidOperationException) | ||
{ //that's what TypeConverters ususally throw | ||
return false; | ||
} | ||
|
||
object original = value; | ||
try | ||
{ | ||
convertTo = Nullable.GetUnderlyingType(convertTo) ?? convertTo; | ||
|
||
var stringValue = value as string ?? string.Empty; | ||
// see: https://bugzilla.xamarin.com/show_bug.cgi?id=32871 | ||
// do not canonicalize "*.[.]"; "1." should not update bound BindableProperty | ||
if (stringValue.EndsWith(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, StringComparison.Ordinal) && DecimalTypes.Contains(convertTo)) | ||
{ | ||
value = original; | ||
return false; | ||
} | ||
|
||
// do not canonicalize "-0"; user will likely enter a period after "-0" | ||
if (stringValue == "-0" && DecimalTypes.Contains(convertTo)) | ||
{ | ||
value = original; | ||
return false; | ||
} | ||
|
||
value = Convert.ChangeType(value, convertTo, CultureInfo.CurrentCulture); | ||
|
||
return true; | ||
} | ||
catch (Exception ex) when (ex is InvalidCastException || ex is FormatException || ex is InvalidOperationException || ex is OverflowException) | ||
{ | ||
value = original; | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.