问题
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?
回答1:
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..."
};
来源:https://stackoverflow.com/questions/11033218/adding-attributes-to-poco-properties-for-mapping-x-y-cells