1
public class MyClass  {  public string MyProperty{ get; set; }

Now, I would like to Map each property to have an [X, Y] integer.

MyProperty = "Its string value.";  
MyProperty.X = 4;
MyProperty.Y = 10;

There are a couple of ways I am thinking about doing this, but not sure what would be the best. Basically mapping a POCO to an Excel spreadsheet.

Should I or can I decorate the properties? Should I use a Dictionary?

mstaffeld
  • 1,335
  • 2
  • 10
  • 11
  • Why not have `MyProperty` be a more complex type instead of a `string`? I guess I don't understand what you're trying to do. – David Hoerster Jun 14 '12 at 12:55
  • Not exactly clear what you want to achieve. You can use static typeing only if you know the structure of the Excel spreadsheet. If you know it, just add the properties you need. If you don't, why not use a `DataSet`s and `DataTable`s? There is `Microsoft.Jet.OLEDB` that can be used to query Excel files like db. Just don't expect it to work flawlessly if the structure of the file and data types aren't consistent. Or just make it dynamic :) – Akos Lukacs Jun 14 '12 at 13:01
  • I don't necessarily know what the type will be and there will be a lot of them. I would basically like to reflect through all of the properties and map them to a cell (x,y). I think something like an IDictionary() is where I'm heading. – mstaffeld Jun 14 '12 at 13:01

1 Answers1

0

As @DavidHoerster mentioned, you need a more descriptive class model:

public class SpreadSheetCell
{
    public int X {get; set;}
    public int Y {get; set;}
    public string Contents {get; set;}
}

...
SpreadSheetCell[,] spreadSheet = new SpreadSheetCell[100,100];
spreadSheet[1, 2] = new SpreadSheetCell
                        {
                          X = 1,
                          Y = 2,
                          Contents = "Something goes here..."
                        };
bluevector
  • 3,485
  • 1
  • 15
  • 18