Ignore:
Timestamp:
Jul 29, 2011, 6:05:05 PM (13 years ago)
Author:
bayral
Message:

MAj des truc existant et debut du upload de fichier

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/DTO/Helper/PwgEnumHelper.cs

    r7149 r11850  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    52using System.Reflection;
    6 using System.ComponentModel;
    73using System.Xml.Serialization;
    84
     
    117    internal static class PwgEnumHelper<T>
    128    {
    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)
    1417        {
    1518            FieldInfo fi = value.GetType().GetField(value.ToString());
     
    2528        }
    2629
    27         internal static T enumValueOf(string value)
     30        internal static T enumValueOf(String value)
    2831        {
    2932            Type enumType = typeof(T);
     
    3134            foreach (T enumValue in values)
    3235            {
    33                 if (stringValueOf(enumValue).Equals(value))
     36                if (StringValueOf(enumValue).Equals(value))
    3437                {
    3538                    return enumValue;
     
    3740            }
    3841
    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));
    4043        }
    4144    }
Note: See TracChangeset for help on using the changeset viewer.