Skip to content

Commit 890476c

Browse files
committed
updated to support Value as a generic
1 parent 719b890 commit 890476c

File tree

8 files changed

+49
-52
lines changed

8 files changed

+49
-52
lines changed

CSVSerializer.NET/CSVSerializer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
<Compile Include="CSVFileExcepion.cs" />
4545
<Compile Include="Deserializer.cs" />
4646
<Compile Include="Row.cs" />
47+
<Compile Include="Rowee.cs" />
4748
<Compile Include="Serializer.cs" />
4849
<Compile Include="Document.cs" />
4950
<Compile Include="Properties\AssemblyInfo.cs" />
5051
<Compile Include="Value.cs" />
52+
<Compile Include="Valuee.cs" />
5153
</ItemGroup>
5254
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5355
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

CSVSerializer.NET/Deserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Document Deserialize()
5858
DumpBuffer(row, buffer);
5959
buffer = new char[line.Length]; //clears the array after dumping values
6060
bufferIndex = 0;
61-
}
61+
} //TODO: deal with the space
6262
else
6363
{
6464
buffer[bufferIndex] = line[i];
@@ -82,7 +82,7 @@ private static void DumpBuffer(Row row, char[] buffer)
8282
if (c != '\0')
8383
tmp += c;
8484
else break; //otherwise keeps looping through the empty slot of the buffer
85-
Value value = new Value(tmp);
85+
Value<object> value = new Value<object>(tmp);
8686
row.AddValue(value);
8787
}
8888

CSVSerializer.NET/Document.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Document()
4040
/// <param name="header">Header of the document</param>
4141
public void SetHeader(Row header)
4242
{
43-
foreach (Value v in header.Values)
43+
foreach (Value<object> v in header.Values)
4444
Headers.Add(v.ToString());
4545
}
4646
/// <summary>

CSVSerializer.NET/Row.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public class Row
1010
/// <summary>
1111
/// The content of the row
1212
/// </summary>
13-
public List<Value> Values { get; }
13+
public List<Value<object>> Values { get; }
1414
/// <summary>
1515
/// Constructor that requires a list of values
1616
/// </summary>
1717
/// <param name="Values">Values to be added</param>
18-
public Row(List<Value> Values)
18+
public Row(List<Value<object>> Values)
1919
{
2020
this.Values = Values;
2121
}
@@ -24,13 +24,13 @@ public Row(List<Value> Values)
2424
/// </summary>
2525
public Row()
2626
{
27-
Values = new List<Value>();
27+
Values = new List<Value<object>>();
2828
}
2929
/// <summary>
3030
/// Adds a value to the row
3131
/// </summary>
3232
/// <param name="value">Value to be added</param>
33-
public void AddValue(Value value)
33+
public void AddValue(Value<object> value)
3434
{
3535
Values.Add(value);
3636
}
@@ -39,11 +39,11 @@ public void AddValue(Value value)
3939
/// </summary>
4040
/// <param name="Index">Index of the value to be updated</param>
4141
/// <param name="NewValue">Updated values</param>
42-
public void UpdateValue(int Index, Value NewValue)
42+
public void UpdateValue(int Index, Value<object> NewValue)
4343
{
4444
try
4545
{
46-
Values[Index].UpdateValue(NewValue); //delegates the Value class to update the value
46+
// Values[Index].UpdateValue(NewValue); //delegates the Value class to update the value
4747
}
4848
catch { }
4949
}

CSVSerializer.NET/Rowee.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSVSerializer
8+
{
9+
class Rowee
10+
{
11+
}
12+
}

CSVSerializer.NET/Serializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public async Task<bool> Serialize()
6262
foreach (Row row in (Document != null? Document.Rows : Rows))
6363
{
6464
short index = 0;
65-
foreach (Value value in row.Values)
65+
foreach (Value<object> value in row.Values)
6666
{
6767
if (index == 0)
6868
await sw.WriteAsync(String.Format("\"{0}\"", value));

CSVSerializer.NET/Value.cs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,33 @@
33
namespace 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
}

CSVSerializer.NET/Valuee.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSVSerializer
8+
{
9+
class Valuee
10+
{
11+
}
12+
}

0 commit comments

Comments
 (0)