Reputation: 12051
Is there a built in attribute in the .net framework to mark up code with an arbitrary key and value? I've had a look through the list, but can't see anything useful there. What we ideally want is to be able to say
[NameValuePair("MyKey", "My long bit of text")]
...and then pull it out later on
Actually, what we really want to be able to do is embed extra info into the assemblyinfo at continuous integration build time, like
[Assembly: NameValuePair("MyKey", "My long bit of text")]
and then pull it out later on
I've seen Jeff's post about Custom AssemblyInfo Attributes, and it is good, but if there's an implicit attribute baked into the framework it'll be even better.
Upvotes: 3
Views: 1551
Reputation: 42526
There is not a built-in attribute that represents a name/value pair, although it would be fairly easy to implement. If your key and value are always strings, you simply need an attribute that takes both strings as constructor parameters.
[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;
}
}
Upvotes: 6