Getting different values from a property at design and run time
I'd like a property in my class to return a different value at design time than in run time. I can detect that I'm in design mode using LicenseManager.UsageMode
, but it would be nice to exclude that from my Release builds.
Is there a better way to implement the following code, perhaps using the Conditional
attribute somehow?
public int MyValue
{
get
{
int my_value = 10;
#if DEBUG
开发者_运维百科 if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
my_value = 20;
}
#endif
return my_value;
}
}
I think that this will be a check you have to make. Or, if the two are totally different programs that you build seperately, you can do the same #if
for your custom variables.
So if there are two seperate builds, you can set a custom parameter for building and do this:
public int MyValue
{
get
{
#if DESIGN
return 20;
#else
return 10;
#endif
}
}
精彩评论