File tree Expand file tree Collapse file tree 6 files changed +127
-32
lines changed Expand file tree Collapse file tree 6 files changed +127
-32
lines changed Original file line number Diff line number Diff line change 11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
62
73namespace CSVSerializer
84{
5+ /// <summary>
6+ /// Exception thrown whenever the file is not regognized to be a valid csv file
7+ /// </summary>
98 public class CSVFileExcepion : Exception
109 {
10+ /// <summary>
11+ /// Constructor for the message containing details of the exception
12+ /// </summary>
13+ /// <param name="message">Details of the exception</param>
1114 public CSVFileExcepion ( string message ) : base ( message )
1215 {
1316 message = "The input file is not a valid CSV file!\n " + message ;
Original file line number Diff line number Diff line change 44namespace CSVSerializer
55{
66 /// <summary>
7- /// This class allows you to deserialize a CSV file or an array
7+ /// This class allows you to deserialize a CSV file or an array of bytes
88 /// </summary>
99 public class Deserializer
1010 {
1111 private StreamReader File ;
12-
12+ /// <summary>
13+ /// Constructor that requires the path of the file. It may throw a FileNotFoundException, deal with it
14+ /// </summary>
15+ /// <param name="FilePath">The path of the csv file</param>
1316 public Deserializer ( String FilePath )
1417 {
1518 File = new StreamReader ( FilePath ) ; //may throw an exception if the file is not found, to be handled by the final user
1619 }
20+ /// <summary>
21+ /// Constructor that requires the content of the file
22+ /// </summary>
23+ /// <param name="buffer">An array of bytes that represent the csv file</param>
1724 public Deserializer ( byte [ ] buffer )
1825 {
1926 this . File = new StreamReader ( new MemoryStream ( buffer ) ) ;
2027 }
21-
28+ /// <summary>
29+ /// Deserialize the file defined in the constructor
30+ /// </summary>
31+ /// <returns>A Document containing the deserialized values</returns>
2232 public Document Deserialize ( )
2333 {
2434 Document doc = new Document ( ) ;
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
63
74namespace CSVSerializer
85{
6+ /// <summary>
7+ /// Structured document for a better organization of the data
8+ /// </summary>
99 public class Document
1010 {
11+ /// <summary>
12+ /// Headers of the document (usually the first row)
13+ /// </summary>
1114 public List < String > Headers { get ; }
15+ /// <summary>
16+ /// List of rows, which are the body of the document
17+ /// </summary>
1218 public List < Row > Rows { get ; }
19+ /// <summary>
20+ /// Constructor that requires headers and rows
21+ /// </summary>
22+ /// <param name="Headers">Name of the columns in the document</param>
23+ /// <param name="Rows">Body of the document</param>
1324 public Document ( List < String > Headers , List < Row > Rows )
1425 {
1526 this . Rows = Rows ;
1627 this . Headers = Headers ;
1728 }
29+ /// <summary>
30+ /// Empty constructor
31+ /// </summary>
1832 public Document ( )
1933 {
2034 Headers = new List < String > ( ) ;
2135 Rows = new List < Row > ( ) ;
2236 }
37+ /// <summary>
38+ /// Allows to set the header for the document
39+ /// </summary>
40+ /// <param name="header">Header of the document</param>
2341 public void SetHeader ( Row header )
2442 {
2543 foreach ( Value v in header . Values )
2644 Headers . Add ( v . ToString ( ) ) ;
2745 }
46+ /// <summary>
47+ /// Allows to add a row to the document
48+ /// </summary>
49+ /// <param name="row">The row to be added</param>
2850 public void AddRow ( Row row )
2951 {
3052 Rows . Add ( row ) ;
3153 }
54+ //TODO: Add indexed and allow more manipulation of the document, including removing rows and setting header from a List<String>
3255 }
3356}
Original file line number Diff line number Diff line change 1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
1+ using System . Collections . Generic ;
62
73namespace CSVSerializer
84{
5+ /// <summary>
6+ /// A row is a set of values
7+ /// </summary>
98 public class Row
109 {
10+ /// <summary>
11+ /// The content of the row
12+ /// </summary>
1113 public List < Value > Values { get ; }
14+ /// <summary>
15+ /// Constructor that requires a list of values
16+ /// </summary>
17+ /// <param name="Values">Values to be added</param>
1218 public Row ( List < Value > Values )
1319 {
1420 this . Values = Values ;
1521 }
22+ /// <summary>
23+ /// Empty constructor
24+ /// </summary>
1625 public Row ( )
1726 {
1827 Values = new List < Value > ( ) ;
1928 }
20- public void AddValue ( Value v )
29+ /// <summary>
30+ /// Adds a value to the row
31+ /// </summary>
32+ /// <param name="value">Value to be added</param>
33+ public void AddValue ( Value value )
2134 {
22- Values . Add ( v ) ;
35+ Values . Add ( value ) ;
2336 }
37+ /// <summary>
38+ /// Update the value at the specified index
39+ /// </summary>
40+ /// <param name="Index">Index of the value to be updated</param>
41+ /// <param name="NewValue">Updated values</param>
2442 public void UpdateValue ( int Index , Value NewValue )
2543 {
26- //delegates the Value class to update the value
2744 try
2845 {
29- Values [ Index ] . UpdateValue ( NewValue ) ;
46+ Values [ Index ] . UpdateValue ( NewValue ) ; //delegates the Value class to update the value
3047 }
3148 catch { }
3249 }
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
53using System . Threading . Tasks ;
64using System . IO ;
75
86namespace CSVSerializer
97{
8+ /// <summary>
9+ /// This class allows you to Serialize a document or a list of rows
10+ /// </summary>
1011 public class Serializer
1112 {
1213 private List < Row > Rows ;
1314 private Document Document ;
1415 private String FilePath ;
16+ /// <summary>
17+ /// Constructor that requires a list of rows and the path of the file
18+ /// </summary>
19+ /// <param name="Rows">The body of the document</param>
20+ /// <param name="FilePath">Path of the file to be serialized</param>
1521 public Serializer ( List < Row > Rows , String FilePath )
1622 {
1723 this . Rows = Rows ;
1824 this . FilePath = FilePath ;
1925 }
20-
26+ /// <summary>
27+ /// Constructor that requires a Document and the path of the file to be serialized
28+ /// </summary>
29+ /// <param name="Document">The document to be serialize</param>
30+ /// <param name="FilePath">Path of the file to be serialized</param>
2131 public Serializer ( Document Document , String FilePath )
2232 {
2333 this . Document = Document ;
2434 this . FilePath = FilePath ;
2535 }
26-
27- /*
28- * if it's a document we first add the headers, otherwise we assume that the headers are in the first row
29- */
36+ /// <summary>
37+ /// Serializes the specified document to the specified file path
38+ /// </summary>
39+ /// <returns>True if the task completes with no errors</returns>
3040 public async Task < bool > Serialize ( )
3141 {
42+ //if it's a document we first add the headers, otherwise we assume that the headers are in the first row
3243 try
3344 {
3445 if ( ! File . Exists ( FilePath ) )
Original file line number Diff line number Diff line change 11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
62
73namespace CSVSerializer
84{
5+ /// <summary>
6+ /// Represents a value of an implicit type
7+ /// </summary>
98 public class Value
109 {
1110 internal Type Type { get ; }
1211 private object value ;
13-
12+ /// <summary>
13+ /// Constructor for integer values
14+ /// </summary>
15+ /// <param name="v">Integer value</param>
1416 public Value ( int v )
1517 {
1618 value = v ;
1719 Type = typeof ( int ) ;
1820 }
21+ /// <summary>
22+ /// Constructor for double value
23+ /// </summary>
24+ /// <param name="v">Double value</param>
1925 public Value ( double v )
2026 {
2127 value = v ;
2228 Type = typeof ( double ) ;
2329 }
30+ /// <summary>
31+ /// Constructor for string values
32+ /// </summary>
33+ /// <param name="v">String value</param>
2434 public Value ( String v )
2535 {
2636 value = v ;
2737 Type = typeof ( String ) ;
2838 }
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 ;
48+ }
49+ /// <summary>
50+ /// Getter method for the value
51+ /// </summary>
52+ /// <returns>The actual value</returns>
2953 public Type GetValue ( )
3054 {
3155 return ( Type ) value ;
3256 }
57+ /// <summary>
58+ /// Method for updating the actual value of this Value
59+ /// </summary>
60+ /// <param name="NewValue">New value that will replace the old one</param>
3361 public void UpdateValue ( Value NewValue )
3462 {
3563 value = NewValue ;
3664 }
37-
65+ /// <summary>
66+ /// Override method for ToString
67+ /// </summary>
68+ /// <returns>The string representation of the object</returns>
3869 public override string ToString ( )
3970 {
4071 if ( Type == typeof ( String ) )
You can’t perform that action at this time.
0 commit comments