9
9
namespace System . Windows
10
10
{
11
11
/// <summary>
12
- /// TypeConverter for TextDecorationCollection
13
- /// </summary>
12
+ /// Provides a type converter to convert from <see langword="string"/> to <see cref=" TextDecorationCollection"/> only.
13
+ /// </summary>
14
14
public sealed class TextDecorationCollectionConverter : TypeConverter
15
15
{
16
16
/// <summary>
17
- /// CanConvertTo method
17
+ /// Returns whether this converter can convert the object to the specified
18
+ /// <paramref name="destinationType"/>, using the specified <paramref name="context"/>.
18
19
/// </summary>
19
- /// <param name="context"> ITypeDescriptorContext </param>
20
- /// <param name="destinationType"> Type to convert to </param>
21
- /// <returns> false will always be returned because TextDecorations cannot be converted to any other type. </returns>
20
+ /// <param name="context">Context information used for conversion.</param>
21
+ /// <param name="destinationType">Type being evaluated for conversion.</param>
22
+ /// <returns>
23
+ /// <see langword="false"/> will always be returned because <see cref="TextDecorations"/> cannot be converted to any other type.
24
+ /// </returns>
22
25
public override bool CanConvertTo ( ITypeDescriptorContext context , Type destinationType )
23
26
{
24
27
// Return false for any other target type. Don't call base.CanConvertTo() because it would be confusing
@@ -28,44 +31,46 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
28
31
}
29
32
30
33
/// <summary>
31
- /// CanConvertFrom
34
+ /// Returns whether this class can convert specific <see cref="Type"/> into <see cref="TextDecorationCollection"/>.
32
35
/// </summary>
33
36
/// <param name="context"> ITypeDescriptorContext </param>
34
- /// <param name="sourceType">Type to convert to </param>
35
- /// <returns> true if it can convert from sourceType to TextDecorations, false otherwise </returns>
37
+ /// <param name="sourceType">Type being evaluated for conversion.</param>
38
+ /// <returns>
39
+ /// <see langword="true"/> if <paramref name="sourceType"/> is <see langword="string"/>, otherwise <see langword="false"/>.
40
+ /// </returns>
36
41
public override bool CanConvertFrom ( ITypeDescriptorContext context , Type sourceType )
37
42
{
38
43
return sourceType == typeof ( string ) ;
39
44
}
40
45
41
46
/// <summary>
42
- /// ConvertFrom
47
+ /// Converts <paramref name="input"/> of <see langword="string"/> type to its <see cref="TextDecorationCollection"/> represensation.
43
48
/// </summary>
44
- /// <param name="context"> ITypeDescriptorContext </param>
45
- /// <param name="culture"> CultureInfo </param>
46
- /// <param name="input"> The input object to be converted to TextDecorations </param>
47
- /// <returns> the converted value of the input object </returns>
49
+ /// <param name="context">Context information used for conversion, ignored currently. </param>
50
+ /// <param name="culture">The culture specifier to use, ignored currently. </param>
51
+ /// <param name="input">The string to convert from. </param>
52
+ /// <returns>A <see cref="TextDecorationCollection"/> representing the <see langword="string"/> specified by <paramref name="input"/>. </returns>
48
53
public override object ConvertFrom ( ITypeDescriptorContext context , CultureInfo culture , object input )
49
54
{
50
55
if ( input is null )
51
56
throw GetConvertFromException ( input ) ;
52
57
53
58
if ( input is not string value )
54
- throw new ArgumentException ( SR . Format ( SR . General_BadType , "ConvertFrom" ) , nameof ( input ) ) ;
55
-
56
- return ConvertFromString ( value ) ;
59
+ throw new ArgumentException ( SR . Format ( SR . General_BadType , "ConvertFrom" ) , nameof ( input ) ) ;
60
+
61
+ return ConvertFromString ( value ) ;
57
62
}
58
63
59
64
/// <summary>
60
- /// ConvertFromString
65
+ /// Converts <paramref name="text"/> to its <see cref="TextDecorationCollection"/> represensation.
61
66
/// </summary>
62
- /// <param name="text"> The string to be converted into TextDecorationCollection object </param>
63
- /// <returns> the converted value of the string flag </returns>
67
+ /// <param name="text">The string to be converted into TextDecorationCollection object. </param>
68
+ /// <returns>A <see cref="TextDecorationCollection"/> representing the <see langword=" string"/> specified by <paramref name="text"/>. </returns>
64
69
/// <remarks>
65
- /// The text parameter can be either string "None" or a combination of the predefined
66
- /// TextDecoration names delimited by commas (,). One or more blanks spaces can precede
67
- /// or follow each text decoration name or comma. There can't be duplicate TextDecoration names in the
68
- /// string. The operation is case-insensitive.
70
+ /// The text parameter can be either be <see langword="null"/>; <see cref="string.Empty"/>; the string "None"
71
+ /// or a combination of the predefined <see cref="TextDecorations"/> names delimited by commas (,).
72
+ /// One or more blanks spaces can precede or follow each text decoration name or comma.
73
+ /// There can't be duplicate TextDecoration names in the string. The operation is case-insensitive.
69
74
/// </remarks>
70
75
public static new TextDecorationCollection ConvertFromString ( string text )
71
76
{
@@ -88,7 +93,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
88
93
if ( decorationsSpan . IsEmpty || decorationsSpan . Equals ( "None" , StringComparison . OrdinalIgnoreCase ) )
89
94
return new TextDecorationCollection ( ) ;
90
95
91
- // Create new collection, save allocations
96
+ // Create new collection, save re- allocations
92
97
TextDecorationCollection textDecorations = new ( 1 + decorationsSpan . Count ( ',' ) ) ;
93
98
94
99
// Go through each item in the input and match accordingly
@@ -123,16 +128,16 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
123
128
}
124
129
125
130
return textDecorations ;
126
- }
131
+ }
127
132
128
133
/// <summary>
129
- /// ConvertTo
134
+ /// Converts a <paramref name="value"/> of <see cref="TextDecorationCollection"/> to the specified <paramref name="destinationType"/>.
130
135
/// </summary>
131
- /// <param name="context"> ITypeDescriptorContext </param>
132
- /// <param name="culture"> CultureInfo </param>
133
- /// <param name="value"> the object to be converted to another type </param>
134
- /// <param name="destinationType"> The destination type of the conversion </param>
135
- /// <returns> null will always be returned because TextDecorations cannot be converted to any other type. </returns>
136
+ /// <param name="context">Context information used for conversion. </param>
137
+ /// <param name="culture">The culture specifier to use. </param>
138
+ /// <param name="value">Duration value to convert from. </param>
139
+ /// <param name="destinationType">Type being evaluated for conversion. </param>
140
+ /// <returns><see langword=" null"/> will always be returned because <see cref=" TextDecorations"/> cannot be converted to any other type.</returns>
136
141
public override object ConvertTo ( ITypeDescriptorContext context , CultureInfo culture , object value , Type destinationType )
137
142
{
138
143
if ( destinationType == typeof ( InstanceDescriptor ) && value is IEnumerable < TextDecoration > )
@@ -144,6 +149,6 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
144
149
145
150
// Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)
146
151
return base . ConvertTo ( context , culture , value , destinationType ) ;
147
- }
148
- }
152
+ }
153
+ }
149
154
}
0 commit comments