Skip to content

Commit 39975a8

Browse files
committed
Split out platform independent converter logic for BooleanToString value converter
1 parent 1f76416 commit 39975a8

File tree

3 files changed

+69
-48
lines changed

3 files changed

+69
-48
lines changed

src/MADE.Data.Converters/BooleanToStringValueConverter.Windows.cs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
namespace MADE.Data.Converters
66
{
77
using System;
8-
using MADE.Data.Converters.Exceptions;
98
using MADE.Data.Converters.Strings;
109
using Windows.UI.Xaml;
1110
using Windows.UI.Xaml.Data;
1211

1312
/// <summary>
1413
/// Defines a Windows components for a XAML value converter from <see cref="bool"/> to <see cref="string"/>.
1514
/// </summary>
16-
[Obsolete("Use the replicated BooleanToStringValueConverter type from the MADE.UI.Data.Converters library instead.")]
17-
public class BooleanToStringValueConverter : DependencyObject, IValueConverter, IValueConverter<bool, string>
15+
[Obsolete("BooleanToStringValueConverter for Windows will be removed in a future major release. Use the replicated BooleanToStringValueConverter type from the MADE.UI.Data.Converters library instead.")]
16+
public partial class BooleanToStringValueConverter : DependencyObject, IValueConverter, IValueConverter<bool, string>
1817
{
1918
/// <summary>
2019
/// Defines the dependency property for <see cref="TrueValue"/>.
@@ -88,50 +87,6 @@ public object ConvertBack(object value, Type targetType, object parameter, strin
8887

8988
return this.ConvertBack(b, parameter);
9089
}
91-
92-
/// <summary>
93-
/// Converts the <paramref name="value">value</paramref> to the <see cref="string"/> type.
94-
/// </summary>
95-
/// <param name="value">
96-
/// The value to convert.
97-
/// </param>
98-
/// <param name="parameter">
99-
/// The optional parameter used to help with conversion.
100-
/// </param>
101-
/// <returns>
102-
/// The converted <see cref="string"/> object.
103-
/// </returns>
104-
public string Convert(bool value, object parameter = default)
105-
{
106-
return value ? this.TrueValue : this.FalseValue;
107-
}
108-
109-
/// <summary>
110-
/// Converts the <paramref name="value">value</paramref> back to the <see cref="bool"/> type.
111-
/// </summary>
112-
/// <param name="value">
113-
/// The value to convert.
114-
/// </param>
115-
/// <param name="parameter">
116-
/// The optional parameter used to help with conversion.
117-
/// </param>
118-
/// <returns>
119-
/// The converted <see cref="bool"/> object.
120-
/// </returns>
121-
public bool ConvertBack(string value, object parameter = default)
122-
{
123-
if (value == this.TrueValue)
124-
{
125-
return true;
126-
}
127-
128-
if (value == this.FalseValue)
129-
{
130-
return false;
131-
}
132-
133-
throw new InvalidDataConversionException(nameof(BooleanToStringValueConverter), value, $"The value to convert back is not of the expected {nameof(this.TrueValue)} or {nameof(this.FalseValue)}");
134-
}
13590
}
13691
}
13792
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
namespace MADE.Data.Converters
2+
{
3+
using MADE.Data.Converters.Exceptions;
4+
5+
/// <summary>
6+
/// Defines a value converter from <see cref="bool"/> to <see cref="string"/> with a pre-determined <see cref="TrueValue"/> and <see cref="FalseValue"/>.
7+
/// </summary>
8+
public partial class BooleanToStringValueConverter : IValueConverter<bool, string>
9+
{
10+
#if !WINDOWS_UWP
11+
/// <summary>
12+
/// Gets or sets the positive/true value.
13+
/// </summary>
14+
public string TrueValue { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the negative/false value.
18+
/// </summary>
19+
public string FalseValue { get; set; }
20+
#endif
21+
22+
/// <summary>
23+
/// Converts the <paramref name="value">value</paramref> to the <see cref="string"/> type.
24+
/// </summary>
25+
/// <param name="value">
26+
/// The value to convert.
27+
/// </param>
28+
/// <param name="parameter">
29+
/// The optional parameter used to help with conversion.
30+
/// </param>
31+
/// <returns>
32+
/// The converted <see cref="string"/> object.
33+
/// </returns>
34+
public string Convert(bool value, object parameter = default)
35+
{
36+
return value ? this.TrueValue : this.FalseValue;
37+
}
38+
39+
/// <summary>
40+
/// Converts the <paramref name="value">value</paramref> back to the <see cref="bool"/> type.
41+
/// </summary>
42+
/// <param name="value">
43+
/// The value to convert.
44+
/// </param>
45+
/// <param name="parameter">
46+
/// The optional parameter used to help with conversion.
47+
/// </param>
48+
/// <returns>
49+
/// The converted <see cref="bool"/> object.
50+
/// </returns>
51+
public bool ConvertBack(string value, object parameter = default)
52+
{
53+
if (value == this.TrueValue)
54+
{
55+
return true;
56+
}
57+
58+
if (value == this.FalseValue)
59+
{
60+
return false;
61+
}
62+
63+
throw new InvalidDataConversionException(nameof(BooleanToStringValueConverter), value, $"The value to convert back is not of the expected {nameof(this.TrueValue)} or {nameof(this.FalseValue)}");
64+
}
65+
}
66+
}

src/MADE.Data.Converters/DateTimeToStringValueConverter.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace MADE.Data.Converters
1010
/// <summary>
1111
/// Defines a Windows components for a XAML value converter from <see cref="DateTime"/> to <see cref="string"/> with an optional format string.
1212
/// </summary>
13-
[Obsolete("Use the replicated DateTimeToStringValueConverter type from the MADE.UI.Data.Converters library instead.")]
13+
[Obsolete("DateTimeToStringValueConverter for Windows will be removed in a future major release. Use the replicated DateTimeToStringValueConverter type from the MADE.UI.Data.Converters library instead.")]
1414
public partial class DateTimeToStringValueConverter : IValueConverter
1515
{
1616
/// <summary>

0 commit comments

Comments
 (0)