33namespace CSVSerializer
44{
55 /// <summary>
6- /// Represents a value of an implicit type
6+ /// Represents a generic value of an implicit type
77 /// </summary>
8- public class Value
8+ public class Value < T >
99 {
10- internal Type Type { get ; }
10+ private T type ;
1111 private object value ;
1212 /// <summary>
13- /// Constructor for integer values
13+ /// Constructor that accepts any object
1414 /// </summary>
15- /// <param name="v">Integer value</param>
16- public Value ( int v )
15+ /// <param name="value">The value to assign to the object </param>
16+ public Value ( object value )
1717 {
18- value = v ;
19- Type = typeof ( int ) ;
20- }
21- /// <summary>
22- /// Constructor for double value
23- /// </summary>
24- /// <param name="v">Double value</param>
25- public Value ( double v )
26- {
27- value = v ;
28- Type = typeof ( double ) ;
29- }
30- /// <summary>
31- /// Constructor for string values
32- /// </summary>
33- /// <param name="v">String value</param>
34- public Value ( String v )
35- {
36- value = v ;
37- Type = typeof ( String ) ;
38- }
39- /// <summary>
40- /// Constructor for specified types
41- /// </summary>
42- /// <param name="v">Value casted to any type</param>
43- /// <param name="t">Explicit type of the value</param>
44- public Value ( object v , Type t )
45- {
46- Type = t ;
47- value = v ;
18+ this . value = value ;
4819 }
4920 /// <summary>
5021 /// Getter method for the value
5122 /// </summary>
5223 /// <returns>The actual value</returns>
53- public Type GetValue ( )
24+ public T GetValue ( )
5425 {
55- return ( Type ) value ;
26+ return ( T ) value ;
5627 }
5728 /// <summary>
5829 /// Method for updating the actual value of this Value
5930 /// </summary>
6031 /// <param name="NewValue">New value that will replace the old one</param>
61- public void UpdateValue ( Value NewValue )
32+ public void UpdateValue ( Value < object > NewValue )
6233 {
6334 value = NewValue ;
6435 }
@@ -68,10 +39,10 @@ public void UpdateValue(Value NewValue)
6839 /// <returns>The string representation of the object</returns>
6940 public override string ToString ( )
7041 {
71- if ( Type == typeof ( String ) )
72- return ( String ) value ;
42+ if ( typeof ( T ) == typeof ( String ) )
43+ return ( string ) value ;
7344 else
74- return base . ToString ( ) ;
45+ return Convert . ToString ( value ) ;
7546 }
7647 }
7748}
0 commit comments