Simple attribute class for storing string values that can be that can be accessed at run time, This class is designed to work with the StringEnum class

Namespace:  CA.Common.Attributes
Assembly:  CA.Common (in CA.Common.dll) Version: 1.0.0.0 (1.0.0.0)

Remarks

Full source code provided below

CopyFull Source Code for the StringValueAttribute class
//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);
}

ExampleStringValueAttribute2 For further examples on how to extract the data see the examples in StringEnum

Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    CA.Common.Attributes..::.StringValueAttribute

See Also