在设计和运行时从属性获取不同的值
我希望类中的属性在设计时返回与运行时不同的值。我可以使用 LicenseManager.UsageMode
,但最好将其从我的发布版本中排除。
有没有更好的方法来实现以下代码,也许使用 < code>Conditional 属性不知何故?
public int MyValue
{
get
{
int my_value = 10;
#if DEBUG
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
my_value = 20;
}
#endif
return my_value;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这将是你必须做的检查。或者,如果这两个程序是您单独构建的完全不同的程序,您可以对自定义变量执行相同的
#if
操作。因此,如果有两个单独的构建,您可以设置用于构建的自定义参数并执行以下操作:
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: