예제 #1
0
        public static object Parse(Type tType, string sValue, bool bIgnoreCase)
        {
            object oReturnObj       = null;
            string sEnumStringValue = string.Empty;

            if (!(ConventionSupport.IsTypeEnum(tType)))
            {
                string sArgExceptionMsg = String.Format("Parameter 'Type' must be an Enum. 'Type' used : {0}", tType.ToString());

                throw new ArgumentException(ConventionSupport.ProduceErrorMsg(sArgExceptionMsg));
            }

            foreach (FieldInfo fInfo in tType.GetFields())
            {
                StringValueAttribute[] svaAttribs = fInfo.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];

                if (svaAttribs.Length > 0)
                {
                    sEnumStringValue = svaAttribs [0].ValueOf;
                }

                if (string.Compare(sEnumStringValue, sValue, bIgnoreCase) == 0)
                {
                    oReturnObj = Enum.Parse(tType, fInfo.Name);
                    break;
                }
            }

            return(oReturnObj);
        }
예제 #2
0
        public StringEnum(Type tEnumType)
        {
            if (!ConventionSupport.IsTypeEnum(tEnumType))
            {
                string sArgExceptionMsg = String.Format("Parameter 'Type' must be an Enum. 'Type' used : {0}", tEnumType.ToString());

                throw new ArgumentException(ConventionSupport.ProduceErrorMsg(sArgExceptionMsg));
            }

            mT_enumType = tEnumType;
        }