2009-02-16 19 views
0

晚報所有,C# - Store,然後更新屬性

我已經寫了需要進行更新,然後更新對應於更新日期轉學申請。即

string content = string.Empty; 
IIvdManager manager; 
DateTime configDate; 

if (table == Tables.Asset) 
{ 
    content = WebService.GetTblAsset(companyId); 
    manager = ivdData.Instance.Asset; 
    configDate = ivdConfig.LAST_UPDATE_ASSET; 
} 
else if (table == Tables.Site) 
{ 
    content = WebService.GetTblSite(companyId); 
    manager = ivdData.Instance.Site; 
    configDate = ivdConfig.LAST_UPDATE_SITE; 
} 
else if (table...) 
{ 
    ... 
} 

if (content.Length > 0) 
{ 
    if (UpdateManager(manager, content)) 
    { 
     configDate = DateTime.Now; 
    } 

} 

我想要的是爲configDate屬性更新我的ivdConfig靜態類中相應的日期獲取/設置。

我該怎麼做?

+0

我很困惑這裏... configDate不是一個屬性。它似乎是一個局部變量。 – 2009-02-16 21:56:02

+0

是的,它是 - 我知道它不工作,但我需要一種方法,使其能夠更新其他靜態ivdConfig類中的日期 – GenericTypeTea 2009-02-16 22:18:36

回答

1

你是否考慮過狀態模式?

子類化你的表(表變量)並添加一個虛擬方法(更新()也許?),然後在每個特定的表類型中覆蓋。這將徹底除去其他IFS,因爲它只會變成:

table.Update(); 

傳下去,你需要這個調用任何對象,然後從表中獲取值回(因爲它可以在更新自己的具體日期物業公司實現更新())。

我很抱歉,如果我有棒棒的結尾,但我不是100%確定你要求說實話。

0

,你需要做到這一點聽起來簡單:

manager.Date = configDate; 

這意味着我幾乎可以肯定是錯誤的....

1

不,我覺得這是很好的代碼,但是這是你在找什麼?

private DateTime configDate; 

private DateTime ConfigDate 
{ 
    get { return configDate; } 
    set 
    { 
    configDate = value; 
    ivdConfig.TheDate = value; 
    } 
} 
0

DateTime類型爲值類型,所以上面的代碼將ivdConfig.LAST_UPDATE_SITE的值只是複製到dateToUpdate而不是參考。

爲了解決你的問題,你可以做到以下幾點:

if (table == Tables.Asset) 
{ 
    content = WebService.GetTblAsset(companyId); 
    manager = ivdData.Instance.Asset; 
} 
else if (table == Tables.Site) 
{ 
    content = WebService.GetTblSite(companyId); 
    manager = ivdData.Instance.Site; 
} 
else if (table...) 
{ 
    ... 
} 

if ((content.Length > 0) && UpdateManager(manager, content)) 
{ 
    DateTime updateDate = DateTime.Now; 

    if (table == Tables.Asset) 
    { 
     ivdConfig.LAST_UPDATE_ASSET = updateDate; 
    } 
    else if (table == Tables.Site) 
    { 
     ivdConfig.LAST_UPDATE_SITE = updateDate; 
    } 
    else if (table...) 
    { 
     ... 
    } 
} 
0

那麼有沒有碰巧是PropertyInfo.SetValue方法。