Reputation: 28259
DescriptionAttribute not allow to be set multiple times.
Is there any way to have such opportunity to set kind of DescriptionAttribute many times to property or enum for example.
Upvotes: 4
Views: 2320
Reputation: 918
You should be calling the base class constructor and remove the Description
property. This also shows how to set the ExtraInfo
property.
public class ExtraDescriptionAttribute : DescriptionAttribute
{
public String ExtraInfo { get; private set; }
public ExtraDescriptionAttribute (String description, String extraInfo) : base(description)
{
ExtraInfo = extraInfo;
}
}
The description attribute will now look like:
[ExtraDescriptionAttribute("Description", "ExtraInfo")]
Upvotes: 2
Reputation: 28259
Solution:
public class ExtraDescriptionAttribute : DescriptionAttribute
{
private string extraInfo; public string ExtraInfo { get { return extraInfo; } set { extraInfo = value; } }
public ExtraDescriptionAttribute(string description)
{
this.DescriptionValue = description;
this.extraInfo = String.Empty;
}
}
Upvotes: 3