自定义程序集属性 [英] Custom Assembly Attributes
本文介绍了自定义程序集属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以定义自定义程序集属性.现有属性的定义方式如下:
I would like to know if I can define custom assembly attributes. Existing attributes are defined in the following way:
[assembly: AssemblyTitle("MyApplication")]
[assembly: AssemblyDescription("This application is a sample application.")]
[assembly: AssemblyCopyright("Copyright © MyCompany 2009")]
有没有办法做到以下几点:
Is there a way I can do the following:
[assembly: MyCustomAssemblyAttribute("Hello World! This is a custom attribute.")]
推荐答案
是的,你可以.我们做这种事情.
Yes you can. We do this kind of thing.
[AttributeUsage(AttributeTargets.Assembly)]
public class MyCustomAttribute : Attribute {
string someText;
public MyCustomAttribute() : this(string.Empty) {}
public MyCustomAttribute(string txt) { someText = txt; }
...
}
阅读使用这种linq stmt.
To read use this kind of linq stmt.
var attributes = assembly
.GetCustomAttributes(typeof(MyCustomAttribute), false)
.Cast<MyCustomAttribute>();
这篇关于自定义程序集属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文