我解析,看起來像這樣的文件:選擇正確的數據結構enum/struct/class?
test_data = {
{
id = '001-000505',
cnv = {
e9 = 0,
i6 = 0,
},
rel = {
rs10850985 = '-',
rs38932097 = '-',
rs5030655 = '-',
rs10655852 = '-',
rs28371725 = '-',
},
result = '*5/*5',
gt = {
rs31080985 = { '-', '-' },
rs16947 = { '-', '-' },
rs3892097 = { '-', '-' },
rs503350655 = { '-', '-' },
rs50530865 = { '-', '-' },
rs5030656 = { '-', '-' },
rs106371706 = { '-', '-' },
rs59421388 = { '-', '-' },
rs7693258 = { '-', '-' },
rs28371725 = { '-', '-' },
},
},
{
id = '004-AATTGG',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs3892097 = '>>',
rs505306d55 = '>>',
rs1065852 = '>>',
rs2837d1725 = '>>',
},
result = '*1/*5',
gt = {
rs10830985 = { 'C', 'C' },
rs164947 = { 'C', 'C' },
rs3892097 = { 'G', 'G' },
rs5030e655 = { 'T', 'T' },
rs5030865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs59421388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'G', 'G' },
},
},
{
id = '003-0300101',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs3892097 = '>>',
rs50530655 = '>>',
rs10365852 = '>>',
rs283271725 = '<<',
},
result = '*41/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs3892097 = { 'G', 'G' },
rs5030655 = { 'T', 'T' },
rs5030865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs593421388 = { 'G', 'G' },
rs7659258 = { 'G', 'G' },
rs28371725 = { 'A', 'A' },
},
},
{
id = '007-CCAA',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs38922097 = '>>',
rs50350655 = '>>',
rs1065852 = '>>',
rs283371725 = '<<',
},
result = '*41/*5',
gt = {
rs1080985 = { 'C', 'C' },
rs16947 = { 'T', 'T' },
rs3892097 = { 'G', 'G' },
rs50350655 = { 'T', 'T' },
rs50350865 = { 'G', 'G' },
rs5030656 = { 'AAG', 'AAG' },
rs106235852 = { 'C', 'C' },
rs28371706 = { 'C', 'C' },
rs59421388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'A', 'A' },
},
},
{
id = '001-000105',
cnv = {
e9 = 1,
i6 = 1,
},
rel = {
rs1080985 = '>>',
rs38392097 = '>>',
rs5030655 = '>>',
rs10565852 = '>>',
rs283371725 = '>>',
},
result = '*1/*5',
gt = {
rs10820985 = { 'C', 'C' },
rs16947 = { 'C', 'C' },
rs32892097 = { 'G', 'G' },
rs53030655 = { 'T', 'T' },
rs50303865 = { 'G', 'G' },
rs50530656 = { 'AAG', 'AAG' },
rs1065852 = { 'C', 'C' },
rs283751706 = { 'C', 'C' },
rs59421388 = { 'G', 'G' },
rs769258 = { 'G', 'G' },
rs28371725 = { 'G', 'G' },
},
},
我需要分析所有這些數據,並捕捉它在某些類型的數據結構。
這裏是我想出了:
struct LuaStructure
{
public string id { get; set; }
public struct cnv
{
public string e9 { get; set; }
public string x9 { get; set; }
public string i6 { get; set; }
}
public struct rel
{
public string rs1080985 { get; set; }
public string rs3892097 { get; set; }
public string rs5030655 { get; set; }
public string rs1065852 { get; set; }
public string rs28371725 { get; set; }
}
public string result { get; set; }
public struct gt
{
public string rs1080985 { get; set; }
public string rs16947 { get; set; }
public string rs3892097 { get; set; }
public string rs5030655 { get; set; }
public string rs5030865 { get; set; }
public string rs5030656 { get; set; }
public string rs1065852 { get; set; }
public string rs28371706 { get; set; }
public string rs59421388 { get; set; }
public string rs769258 { get; set; }
public string rs28371725 { get; set; }
}
}
我不認爲這是正確的解決方案,因爲我會想說
string somestring=LuaStructure.gt.rs1080985;
這是不可能的,因爲我需要先申報;
LuaStructure somestructure = new LuaStructure;
然後我需要做的
LuaStructure.gt somestructuregt = new LuaStructure.gt;
我不想不得不經歷這整個過程
我需要捕捉的數據是什麼類/結構/枚舉的組合我想要什麼?
那個結構是非常糟糕的。祝你好運... **你有沒有考慮過在創建對象時使用屬性初始值設定項嗎?** – Yuck 2012-02-16 03:51:20
@Yuck你是對的,這太可怕了,你可以請建議一些更有用的:) – 2012-02-16 03:51:53
@yuck你能告訴我你的意思嗎?我不明白如何做嵌套數據的初始化器 – 2012-02-16 03:52:35