是否可以忽略C#中的属性?还是禁用它们的处理? [英] Is it possible to ignore Attributes in C#? Or disable the processing of them?

查看:54
本文介绍了是否可以忽略C#中的属性?还是禁用它们的处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,出于多种目的,我们可以使用Attributes装饰方法.

In C# we can decorate methods with Attributes for numerous purposes.

例如:

   [Activity (Label = "My Activity", MainLauncher = true)]
   public class MainActivity : Activity

这个特定示例来自Xamarin,它关闭并根据这些属性自动构建Android Manifest文件.

This particular example is from Xamarin, it goes off and auto builds the Android Manifest file based on these attributes.

我想知道是否有任何方法可以使编译器全局忽略这些属性?即完全禁用属性处理.

I want to know if there is any way to get the compiler to globally ignore these attributes? i.e Disable Attribute processing altogether.

我的最终目标是自己手动生成Android Manifest文件,但仍将这些属性保留在类中.我正在使用Visual Studio 2012.

My actual end goal is to manually generate my Android Manifest file myself but still keep these Attributes in the classes. I'm using Visual Studio 2012.

推荐答案

也许条件编译可以做到?

Perhaps a conditional compilation would do?

#if DEBUG
[Activity (Label = "My Activity", MainLauncher = true)]
#endif
public class MainActivity : Activity

这篇关于是否可以忽略C#中的属性?还是禁用它们的处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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