Engines/FlatRedBallXNA/3rd Party Libraries/StringEnum_src/CodeBureau/StringEnum.cs
/// <summary>
/// Parses the supplied enum and string value to find an associated enum value.
/// </summary>
/// <param name="type">Type.</param>
/// <param name="stringValue">String value.</param>
/// <param name="ignoreCase">Denotes whether to conduct a case-insensitive match on the supplied string value</param>
/// <returns>Enum value associated with the string value, or null if not found.</returns>
Parses the supplied enum and string value to find an associated enum value.
Parses the supplied enum and string value to find an associated enum value .
public static object Parse(Type type, string stringValue, bool ignoreCase)
		{
			object output = null;
			string enumStringValue = null;
			if (!type.IsEnum)
				throw new ArgumentException(String.Format("Supplied type must be an Enum.  Type was {0}", type.ToString()));
			foreach (FieldInfo fi in type.GetFields())
			{
				StringValueAttribute[] attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false) as StringValueAttribute[];
				if (attrs.Length > 0)
					enumStringValue = attrs[0].Value;
				if (string.Compare(enumStringValue, stringValue, ignoreCase) == 0)
				{
					output = Enum.Parse(type, fi.Name);
					break;
				}
			}
			return output;
		}
public static object Parse ( Type type , string stringValue , bool ignoreCase ) { object output = null ; string enumStringValue = null ; if ( ! type . IsEnum ) throw new ArgumentException ( String . Format ( " " , type . ToString ( ) ) ) ; foreach ( FieldInfo fi in type . GetFields ( ) ) { StringValueAttribute [ ] attrs = fi . GetCustomAttributes ( typeof ( StringValueAttribute ) , false ) as StringValueAttribute [ ] ; if ( attrs . Length > 0 ) enumStringValue = attrs [ 0 ] . Value ; if ( string . Compare ( enumStringValue , stringValue , ignoreCase ) == 0 ) { output = Enum . Parse ( type , fi . Name ) ; break ; } } return output ; }
Parses the supplied enum and string value to find an associated enum value.
Parses the supplied enum and string value to find an associated enum value .
//Look for our string value associated with fields in this enum //Check for our custom attribute //Check for equality then select actual enum value.
Enum value associated with the string value, or null if not found.
Enum value associated with the string value or null if not found .
type
Type
None
stringValue
string
None
ignoreCase
bool
Denotes whether to conduct a case-insensitive match on the supplied string value
Denotes whether to conduct a case - insensitive match on the supplied string value