Is it possible to ignore Attributes in C#? Or disable the processing of them?

南笙酒味 提交于 2019-12-11 11:18:36

问题


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

E.g:

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

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.

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.


回答1:


Perhaps a conditional compilation would do?

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


来源:https://stackoverflow.com/questions/26162056/is-it-possible-to-ignore-attributes-in-c-or-disable-the-processing-of-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!