Ejemplo n.º 1
0
        /// <summary>
        /// Converts the parameter value string to the given type.
        /// </summary>
        /// <param name="paramValue">The value string of the parameter.</param>
        /// <param name="paramType">The type of the parameter.</param>
        /// <returns>The value of the parameter in the given type.</returns>
        private object ParseParameterValue(string paramValue, CtorParamType paramType)
        {
            switch (paramType)
            {
            case CtorParamType.INT:
                return(int.Parse(paramValue, NumberStyles.Integer, CultureInfo.InvariantCulture));

            case CtorParamType.FLOAT:
                return(float.Parse(paramValue, NumberStyles.Float, CultureInfo.InvariantCulture));

            case CtorParamType.BOOL:
                return(bool.Parse(paramValue));

            case CtorParamType.STRING:
                return(paramValue);

            default:
                throw new ConfigurationException(string.Format("Unable to convert parameter value {0} to type {1}!", paramValue, paramType.ToString()));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the parameter value string to the given type.
        /// </summary>
        /// <param name="paramValue">The value string of the parameter.</param>
        /// <param name="paramType">The type of the parameter.</param>
        /// <returns>The value of the parameter in the given type.</returns>
        private static object ParseParameterValue(string paramValue, CtorParamType paramType)
        {
            // TODO: extend this switch if necessary!
            switch (paramType)
            {
            case CtorParamType.INT:
                return(XmlHelper.LoadInt(paramValue));

            case CtorParamType.FLOAT:
                return(float.Parse(paramValue, NumberStyles.Float, CultureInfo.InvariantCulture));

            case CtorParamType.BOOL:
                return(XmlHelper.LoadBool(paramValue));

            case CtorParamType.STRING:
                return(paramValue);

            default:
                throw new ConfigurationException(string.Format("Unable to convert parameter value '{0}' to type '{1}'!", paramValue, paramType.ToString()));
            }
        }