Assembly: CA.Common (in CA.Common.dll) Version: 1.0.0.0 (1.0.0.0)
Remarks
Full source code provided below
//Source code from the Code Associate C# code library, Full documentation and latest updates can be found //@ http://www.codeassociate.com/caapi/ using System; namespace CA.Common.Attributes { public class StringValueAttribute : Attribute { public StringValueAttribute(string value) { Value = value; } public string Value { get; private set; } } }
Examples
Example Usage defining:
CopyC#public enum MenuItemType
{
[StringValue("Header for a Menu")]
Header,
[StringValue("All odd Menu Items")]
Item,
[StringValue("All even Menu Items")]
AlternatingItem,
[StringValue("Footer for a Menu")]
Footer
}
Example Usage Extracting:
CopyC#[Test]
public void CheckStringToEnumWorksWithMenuItemType()
{
// will extract the value string value from MenuItemType.Item into the string variable stringEnumValue
string stringEnumValue = StringEnum.GetStringValue(MenuItemType.Item);
// the expected result is the value defined in the MenuItemType.Item attribute which is hardcoded for testing
Assert.AreEqual("All odd Menu Items", stringEnumValue);
}