-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b32de3e
commit 8c96b75
Showing
11 changed files
with
133 additions
and
193 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
23 changes: 0 additions & 23 deletions
23
...eactiveUI.Tests/Platforms/windows-xaml/Api/XamlApiApprovalTests.Blend.Net4_8.received.txt
This file was deleted.
Oops, something went wrong.
119 changes: 0 additions & 119 deletions
119
...eUI.Tests/Platforms/winforms/API/WinformsApiApprovalTests.Winforms.DotNet5_0.received.txt
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
87 changes: 87 additions & 0 deletions
87
src/ReactiveUI/Platforms/uap/ComponentModelTypeConverter.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
// <auto-generated /> | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using Splat; | ||
|
||
#nullable enable | ||
namespace ReactiveUI; | ||
|
||
/// <summary> | ||
/// Binding Type Converter for component model. | ||
/// </summary> | ||
public class ComponentModelTypeConverter : IBindingTypeConverter | ||
{ | ||
private readonly MemoizingMRUCache<(Type fromType, Type toType), TypeConverter?> _typeConverterCache = new ( | ||
(types, _) => | ||
{ | ||
// NB: String is a Magical Type(tm) to TypeConverters. If we are | ||
// converting from string => int, we need the Int converter, not | ||
// the string converter :-/ | ||
if (types.fromType == typeof(string)) | ||
{ | ||
types = (types.toType, types.fromType); | ||
} | ||
|
||
var converter = TypeDescriptor.GetConverter(types.fromType); | ||
return converter.CanConvertTo(types.toType) ? converter : null; | ||
}, RxApp.SmallCacheLimit); | ||
|
||
/// <inheritdoc/> | ||
public int GetAffinityForObjects(Type fromType, Type toType) | ||
{ | ||
var converter = _typeConverterCache.Get((fromType, toType)); | ||
return converter is not null ? 10 : 0; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public bool TryConvert(object? from, Type toType, object? conversionHint, out object? result) | ||
{ | ||
if (from is null) | ||
{ | ||
result = null; | ||
return true; | ||
} | ||
|
||
var fromType = from.GetType(); | ||
var converter = _typeConverterCache.Get((fromType, toType)); | ||
|
||
if (converter is null) | ||
{ | ||
throw new ArgumentException($"Can't convert {fromType} to {toType}. To fix this, register a IBindingTypeConverter"); | ||
} | ||
|
||
try | ||
{ | ||
// TODO: This should use conversionHint to determine whether this is locale-aware or not | ||
result = (fromType == typeof(string)) ? | ||
converter.ConvertFrom(from) : converter.ConvertTo(from, toType); | ||
|
||
return true; | ||
} | ||
catch (FormatException) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
catch (Exception e) | ||
{ | ||
// Errors from ConvertFrom end up here but wrapped in | ||
// outer exception. Add more types here as required. | ||
// IndexOutOfRangeException is given when trying to | ||
// convert empty strings with some/all? converters | ||
if (e.InnerException is IndexOutOfRangeException || | ||
e.InnerException is FormatException) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
throw new Exception($"Can't convert from {@from.GetType()} to {toType}.", e); | ||
} | ||
} | ||
} |
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,28 @@ | ||
// Copyright (c) 2021 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
// <auto-generated /> | ||
|
||
using System; | ||
using System.Reactive.Concurrency; | ||
using Splat; | ||
|
||
namespace ReactiveUI; | ||
|
||
/// <summary> | ||
/// .NET Framework platform registrations. | ||
/// </summary> | ||
/// <seealso cref="ReactiveUI.IWantsToRegisterStuff" /> | ||
public class PlatformRegistrations : IWantsToRegisterStuff | ||
{ | ||
/// <inheritdoc/> | ||
public void Register(Action<Func<object>, Type> registerFunction) | ||
{ | ||
if (registerFunction is null) | ||
{ | ||
throw new ArgumentNullException(nameof(registerFunction)); | ||
} | ||
// Registration is done in Registrations of ReactiveUI.Uap | ||
} | ||
} |
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