.net框架中是否有内置属性来标记具有任意键和值的代码?我看了一下清单,但看不到有用的东西.我们理想的是能够说出来
[NameValuePair("MyKey", "My long bit of text")]
Run Code Online (Sandbox Code Playgroud)
......然后再拉出来
实际上,我们真正希望能够做的是在持续集成构建时将额外信息嵌入到assemblyinfo中,例如
[Assembly: NameValuePair("MyKey", "My long bit of text")]
Run Code Online (Sandbox Code Playgroud)
然后把它拉出来
我已经看过Jeff关于Custom AssemblyInfo Attributes的帖子,这很好,但是如果在框架中有一个隐含的属性,它会更好.
没有表示名称/值对的内置属性,尽管它实现起来相当容易.如果您的键和值始终是字符串,则只需要一个将两个字符串作为构造函数参数的属性.
[AttributeUsage(AttributeTargets.Assembly)]
public KeyValuePairAttribute : Attribute
{
private string key;
private string value;
private KeyValuePairAttribute() { }
public KeyValuePairAttribute(string key, string value)
{
this.key = key;
this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |