@@ -20,7 +20,7 @@ public static class Colors
2020 /// Caches the named colors and their names, for performance reasons when using <see cref="GetNamedColor(string)"/> and/or
2121 /// <see cref="TryGetNamedColor(string, out Color)"/>.
2222 /// </summary>
23- static readonly ReadOnlyDictionary < string , Color > namedColors ;
23+ static readonly ReadOnlyDictionary < string , Color > namedColors = GetNamedColorCache ( ) ;
2424
2525#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
2626 public static Color TRANSPARENT => new Color ( 0 , 0 , 0 , 0 ) ;
@@ -219,14 +219,21 @@ public static bool TryGetNamedColor(string colorName, out Color color)
219219 }
220220
221221 /// <summary>
222- /// Static constructor initializes a cache of the named colors.
222+ /// Gets a dictionary of the names/instances of the well-known colors.
223223 /// </summary>
224- static Colors ( )
224+ /// <remarks>
225+ /// <para>
226+ /// The keys of this dictionary are case insensitive and correspond to the names of the static properties of this type.
227+ /// The values are instances of the <see cref="Color"/> that the corresponding property returns.
228+ /// </para>
229+ /// </remarks>
230+ /// <returns>A cache of the named color values.</returns>
231+ static ReadOnlyDictionary < string , Color > GetNamedColorCache ( )
225232 {
226233 var namedColorValues = typeof ( Colors )
227234 . GetProperties ( BindingFlags . Static )
228235 . ToDictionary ( k => k . Name , v => ( Color ) v . GetValue ( null ) , StringComparer . InvariantCultureIgnoreCase ) ;
229- namedColors = new ReadOnlyDictionary < string , Color > ( namedColorValues ) ;
236+ return new ReadOnlyDictionary < string , Color > ( namedColorValues ) ;
230237 }
231238 }
232239}
0 commit comments