0
我希望我的類中的屬性在設計時返回與運行時不同的值。我可以使用LicenseManager.UsageMode
檢測到我處於設計模式,但將其從我的發佈版本中排除是很好的。在設計和運行時從屬性獲取不同的值
有沒有更好的方法來實現下面的代碼,或許使用Conditional
屬性?
public int MyValue
{
get
{
int my_value = 10;
#if DEBUG
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
my_value = 20;
}
#endif
return my_value;
}
}
爲什麼不使用設計時屬性?它應該在屬性獲得者中具有正確的價值。 – 2011-01-12 16:36:28