Example #1
0
        public string GetValue(Type InType, string InArgument)
        {
            DebugHelper.Assert(InArgument != null);

            string[] Enums = Enum.GetNames(InType);

            for (int i = 0; i < Enums.Length; ++i)
            {
                if (Enums[i].Equals(InArgument, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(Enums[i]);
                }
            }

            string DummyString;

            if (ArgumentDescriptionDefault.CheckConvertUtil(InArgument, typeof(int), out DummyString))
            {
                int EnumValue = System.Convert.ToInt32(InArgument);

                string Result = Enum.GetName(InType, EnumValue);

                return(Result);
            }

            return("");
        }
Example #2
0
        public object Convert(string InArgument, Type InType)
        {
            string DummyString;

            if (ArgumentDescriptionDefault.CheckConvertUtil(InArgument, typeof(int), out DummyString))
            {
                int EnumValue = System.Convert.ToInt32(InArgument);

                return(Enum.ToObject(InType, EnumValue));
            }
            else
            {
                return(Enum.Parse(InType, InArgument, true));
            }
        }
Example #3
0
        public List <string> FilteredCandinates(Type InType, string InArgument)
        {
            string DummyString;

            if (ArgumentDescriptionDefault.CheckConvertUtil(InArgument, typeof(int), out DummyString))
            {
                int    EnumValue     = System.Convert.ToInt32(InArgument);
                string CurrentString = Enum.GetName(InType, EnumValue);

                return(FilteredCandinatesInner(InType, CurrentString));
            }
            else
            {
                return(FilteredCandinatesInner(InType, InArgument));
            }
        }
Example #4
0
        public static int StringToEnum(Type InType, string InText)
        {
            // assume this input text always can be convert to enum.
            string DummyString;

            if (ArgumentDescriptionDefault.CheckConvertUtil(InText, typeof(int), out DummyString))
            {
                int EnumValue = System.Convert.ToInt32(InText);

                return(EnumValue);
            }
            else
            {
                return(System.Convert.ToInt32(Enum.Parse(InType, InText, true)));
            }
        }
Example #5
0
        public bool CheckConvert(string InArgument, Type InType, out string OutErrorMessage)
        {
            DebugHelper.Assert(InArgument != null && InType.IsEnum);

            OutErrorMessage = "";

            string[] Enums = Enum.GetNames(InType);

            for (int i = 0; i < Enums.Length; ++i)
            {
                if (Enums[i].Equals(InArgument, StringComparison.CurrentCultureIgnoreCase))
                {
                    return(true);
                }
            }

            string DummyString;

            if (ArgumentDescriptionDefault.CheckConvertUtil(InArgument, typeof(int), out DummyString))
            {
                int EnumValue = System.Convert.ToInt32(InArgument);

                string Result = Enum.GetName(InType, EnumValue);

                if (string.IsNullOrEmpty(Result))
                {
                    OutErrorMessage = string.Format("Failed Convert\"{0}\" to {1}.", InArgument, InType.Name);
                }

                return(false);
            }

            OutErrorMessage = string.Format("Value \"{0}\" is not an valid property.", InArgument);

            return(false);
        }