Updated comments.
This commit is contained in:
@@ -3,19 +3,38 @@ using System.Reflection;
|
||||
|
||||
namespace NSspi
|
||||
{
|
||||
/// <summary>
|
||||
/// Tags an enumeration member with a string that can be programmatically accessed.
|
||||
/// </summary>
|
||||
[AttributeUsage( AttributeTargets.Field )]
|
||||
public class EnumStringAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnumStringAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to associate with the enumeration member.</param>
|
||||
public EnumStringAttribute( string text )
|
||||
{
|
||||
this.Text = text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the string associated with the enumeration member.
|
||||
/// </summary>
|
||||
public string Text { get; private set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts betwen enumeration members and the strings associated to the members through the
|
||||
/// <see cref="EnumStringAttribute"/> type.
|
||||
/// </summary>
|
||||
public class EnumMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the text associated with the given enumeration member through a <see cref="EnumStringAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToText( Enum value )
|
||||
{
|
||||
FieldInfo field = value.GetType().GetField( value.ToString() );
|
||||
@@ -32,6 +51,12 @@ namespace NSspi
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the enumeration member that is tagged with the given text using the <see cref="EnumStringAttribute"/> type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The enumeration type to inspect.</typeparam>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
public static T FromText<T>( string text )
|
||||
{
|
||||
FieldInfo[] fields = typeof( T ).GetFields();
|
||||
|
||||
Reference in New Issue
Block a user