Adding attributes to POCO properties for mapping x

2019-08-04 02:00发布

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?

标签: c# mapping poco
1条回答
狗以群分
2楼-- · 2019-08-04 02:39

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..."
                        };
查看更多
登录 后发表回答