Adding attributes to POCO properties for mapping x,y cells

牧云@^-^@ 提交于 2019-12-11 14:37:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!