取决于类属性的条件方法 [英] Conditional method depending on class attribute

查看:105
本文介绍了取决于类属性的条件方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道条件方法是否可以将他的条件放在类属性上。



例如:

  class Class1 
{
public bool _doStuff;

[Conditional(_doStuff)]
public static void Stuff(){
//做东西
}
}

类似于 [Conditonal( DEBUG)]



有人知道吗?

解决方案

这不是存在。更重要的是,这是不合逻辑的。



标记为 Conditional 的方法不参与构建过程如果不符合条件。不能在运行时做出此决定。



代码被省略,就好像它从未被编写过,并且可执行文件(或dll)不包含该方法。 / p>

I'm wondering if a conditional method can have his condition on a class attribute.

For instance :

class Class1 
{
   public bool _doStuff;

   [Conditional(_doStuff)]
   public static void Stuff() {
      // Do the stuff
   }
}

Like the [Conditonal("DEBUG")].

Does anyone know about this?

解决方案

This doesn't exist. More to the point, it's illogical.

A method marked as Conditional doesn't take part in the build process if the condition isn't met. This decision can't be made in runtime.

The code is omitted as if it was never written and the executable (or dll) doesn't contain that method.

这篇关于取决于类属性的条件方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆