@@ -35,19 +35,26 @@ namespace Litipk.ColorSharp
3535{
3636 namespace ColorSpaces
3737 {
38+ /**
39+ *
40+ */
3841 public abstract class AConvertibleColor
3942 {
4043 #region properties
4144
42- // If this "color" comes from another data source, then we keep the original data.
43- protected AConvertibleColor DataSource = null ;
45+ /**
46+ * <value>Original color sample</value>
47+ */
48+ public readonly AConvertibleColor DataSource = null ;
4449
4550 #endregion
4651
4752
4853 #region constructors
4954
50- // TODO: Check if this should be public in order to work as expected with reflection.
55+ /**
56+ * Boilerplate constructor
57+ */
5158 protected AConvertibleColor ( AConvertibleColor dataSource = null )
5259 {
5360 DataSource = dataSource ;
@@ -58,37 +65,49 @@ protected AConvertibleColor(AConvertibleColor dataSource = null)
5865
5966 #region conversion skeleton
6067
68+ /**
69+ * <see cref="ConvertTo"/>
70+ */
6171 public T ConvertTo < T > ( ConversionStrategy strategy = ConversionStrategy . Default ) where T : AConvertibleColor
6272 {
63- Type t = typeof ( T ) ;
73+ return ( T ) ConvertTo ( typeof ( T ) , strategy ) ;
74+ }
75+
76+ /**
77+ * <summary>Method that allows conversions passing the type as a parameter.</summary>
78+ * <remarks>DON'T USE it to implement conversion methods, use the non type-parametric variants.</remarks>
79+ */
80+ public AConvertibleColor ConvertTo ( Type t , ConversionStrategy strategy = ConversionStrategy . Default )
81+ {
6482 Type tt = GetType ( ) ;
6583
6684 if ( t == tt ) {
6785 // Dumb conversion
68- return ( T ) ( AConvertibleColor ) this ;
86+ return this ;
6987 }
7088
7189 if ( DataSource != null ) {
7290 if ( DataSource . GetType ( ) == t ) {
73- return ( T ) DataSource ;
91+ return DataSource ;
7492 }
7593
76- return DataSource . ConvertTo < T > ( strategy ) ;
94+ return DataSource . ConvertTo ( t , strategy ) ;
7795 }
7896
79- return InnerConvertTo < T > ( strategy ) ;
97+ return InnerConvertTo ( t , strategy ) ;
8098 }
8199
82- protected T InnerConvertTo < T > ( ConversionStrategy strategy = ConversionStrategy . Default ) where T : AConvertibleColor
100+ /**
101+ * Helper method used by ConvertTo.
102+ */
103+ private AConvertibleColor InnerConvertTo ( Type t , ConversionStrategy strategy = ConversionStrategy . Default )
83104 {
84- Type t = typeof ( T ) ;
85-
86105 if ( t == typeof ( CIEXYZ ) )
87- return ( T ) ( AConvertibleColor ) ToCIEXYZ ( strategy ) ;
106+ return ToCIEXYZ ( strategy ) ;
88107 if ( t == typeof ( CIExyY ) )
89- return ( T ) ( AConvertibleColor ) ToCIExyY ( strategy ) ;
108+ return ToCIExyY ( strategy ) ;
90109 if ( t == typeof ( SRGB ) )
91- return ( T ) ( AConvertibleColor ) ToSRGB ( strategy ) ;
110+ return ToSRGB ( strategy ) ;
92111
93112 throw new NotImplementedException ( "This conversion isn't implemented." ) ;
94113 }
@@ -114,7 +133,7 @@ protected T InnerConvertTo<T> (ConversionStrategy strategy = ConversionStrategy.
114133 public abstract CIExyY ToCIExyY ( ConversionStrategy strategy = ConversionStrategy . Default ) ;
115134
116135 /**
117- * <summary>Converts the color sample to an HP's & Microsoft's 1996 sRGB sample.</summary>
136+ * <summary>Converts the color sample to an HP's and Microsoft's 1996 sRGB sample.</summary>
118137 */
119138 public abstract SRGB ToSRGB ( ConversionStrategy strategy = ConversionStrategy . Default ) ;
120139
0 commit comments