Skip to content

Commit

Permalink
implement IClone for ToxySpreadsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyqus committed Apr 22, 2015
1 parent 3343f12 commit 6b74165
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
12 changes: 10 additions & 2 deletions ToxyFramework/Entities/ToxySpreadsheet/ToxyCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Toxy
{
public class ToxyCell
public class ToxyCell : ICloneable
{
public ToxyCell(int cellIndex, string value)
{
Expand All @@ -22,10 +22,18 @@ public ToxyCell(int cellIndex, string value)
public string Value { get; set; }
public int CellIndex { get; set; }
public string Comment { get; set; }

public string Formula { get; set; }

public override string ToString()
{
return this.Value;
}
public object Clone()
{
ToxyCell clonedCell = new ToxyCell(this.CellIndex, this.Value);
clonedCell.Comment = this.Comment;
clonedCell.Formula = this.Formula;
return clonedCell;
}
}
}
12 changes: 11 additions & 1 deletion ToxyFramework/Entities/ToxySpreadsheet/ToxyRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Toxy
{
public class ToxyRow
public class ToxyRow:ICloneable
{
public int RowIndex { get; set; }
public int LastCellIndex { get; set; }
Expand All @@ -19,5 +19,15 @@ public List<ToxyCell> Cells
get;
set;
}

public object Clone()
{
ToxyRow clonedrow = new ToxyRow(this.RowIndex);
foreach (ToxyCell cell in this.Cells)
{
clonedrow.Cells.Add(cell.Clone() as ToxyCell);
}
return clonedrow;
}
}
}
16 changes: 15 additions & 1 deletion ToxyFramework/Entities/ToxySpreadsheet/ToxySpreadsheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Toxy
{
public class ToxySpreadsheet
public class ToxySpreadsheet:ICloneable
{
public ToxySpreadsheet()
{
Expand All @@ -30,6 +30,9 @@ public ToxyTable this[string name]
}
}




public DataSet ToDataSet()
{
DataSet ds = new DataSet();
Expand All @@ -40,5 +43,16 @@ public DataSet ToDataSet()
}
return ds;
}

public object Clone()
{
ToxySpreadsheet newss = new ToxySpreadsheet();
newss.Name = this.Name;
for (int i = 0; i < this.Tables.Count; i++)
{
newss.Tables.Add(this.Tables[i].Clone() as ToxyTable);
}
return newss;
}
}
}
18 changes: 17 additions & 1 deletion ToxyFramework/Entities/ToxySpreadsheet/ToxyTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Toxy
{

public class ToxyTable
public class ToxyTable:ICloneable
{
public ToxyTable()
{
Expand Down Expand Up @@ -111,5 +111,21 @@ public override string ToString()
{
return string.Format("[{0}]",this.Name);
}

public object Clone()
{
ToxyTable newtt = new ToxyTable();
newtt.PageFooter = this.PageFooter;
newtt.PageHeader = this.PageHeader;
newtt.Name = this.Name;
newtt.LastColumnIndex = this.LastColumnIndex;
newtt.LastRowIndex = this.LastRowIndex;
foreach(ToxyRow row in this.Rows)
{
newtt.Rows.Add(row.Clone() as ToxyRow);
}
newtt.ColumnHeaders = this.ColumnHeaders.Clone() as ToxyRow;
return newtt;
}
}
}

0 comments on commit 6b74165

Please sign in to comment.