- Timestamp:
- Jul 29, 2011, 6:05:05 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/PiwigoLib/PiwigoLib/DTO/Helper/PwgEnumHelper.cs
r7149 r11850 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 2 using System.Reflection; 6 using System.ComponentModel;7 3 using System.Xml.Serialization; 8 4 … … 11 7 internal static class PwgEnumHelper<T> 12 8 { 13 internal static string stringValueOf(T value) 9 static PwgEnumHelper() 10 { 11 if (!typeof(T).IsEnum) { 12 throw new ArgumentException(String.Format("PwgEnumHelper<T>(): The type {0} is not a enum.", typeof(T).Name)); 13 } 14 } 15 16 internal static String StringValueOf(T value) 14 17 { 15 18 FieldInfo fi = value.GetType().GetField(value.ToString()); … … 25 28 } 26 29 27 internal static T enumValueOf( string value)30 internal static T enumValueOf(String value) 28 31 { 29 32 Type enumType = typeof(T); … … 31 34 foreach (T enumValue in values) 32 35 { 33 if ( stringValueOf(enumValue).Equals(value))36 if (StringValueOf(enumValue).Equals(value)) 34 37 { 35 38 return enumValue; … … 37 40 } 38 41 39 throw new ArgumentException( "The string is not a description or value of the specified enum.");42 throw new ArgumentException(String.Format("PwgEnumHelper<{0}>.enumValueOf({1}): The String is not a description or value of the specified enum.", typeof(T).Name, value)); 40 43 } 41 44 }
Note: See TracChangeset
for help on using the changeset viewer.