Exemplo n.º 1
0
        /// <summary>
        /// Check for a special parameter value containing the Paramater expression
        /// </summary>
        /// <param name="paramValue">the Parameter value</param>
        /// <param name="element">the Element</param>
        /// <param name="paramName">the Parameter Name</param>
        /// <returns>the resolved Parameter Expression value or null if not resolved</returns>
        public static ParamExprResolver CheckForParameterExpr(string paramValue, Element element, string paramName, ExpectedValueEnum expectedDataType, out object propertyValue)
        {
            propertyValue = null;
            string paramValuetrim = paramValue.Trim();

            if (IsParameterExpr(paramValue))
            {
                ParamExprResolver pResv = new ParamExprResolver(element, paramName, paramValuetrim);
                switch (expectedDataType)
                {
                case ExpectedValueEnum.STRINGVALUE:
                    propertyValue = pResv.GetStringValue();
                    break;

                case ExpectedValueEnum.DOUBLEVALUE:
                    propertyValue = pResv.GetDoubleValue();
                    break;

                case ExpectedValueEnum.INTVALUE:
                    propertyValue = pResv.GetIntValue();
                    break;

                default:
                    break;
                }
                return(pResv);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets double value from parameter of an element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="group">Optional property group to limit search to.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="propertyValue">The output property value.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when propertyName is null or empty.</exception>
        /// <returns>The parameter, or null if not found.</returns>
        public static Parameter GetDoubleValueFromElement(Element element, BuiltInParameterGroup?group, string propertyName, out double propertyValue)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (String.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentException("It is null or empty.", "propertyName");
            }

            propertyValue = 0.0;

            Parameter parameter = GetParameterFromName(element.Id, group, propertyName);

            if (parameter != null && parameter.HasValue)
            {
                switch (parameter.StorageType)
                {
                case StorageType.Double:
                    propertyValue = parameter.AsDouble();
                    return(parameter);

                case StorageType.Integer:
                    propertyValue = parameter.AsInteger();
                    return(parameter);

                case StorageType.String:
                {
                    string propValue;
                    propValue = parameter.AsString();

                    string propValuetrim = propValue.Trim();
                    // This is kind of hack to quickly check whether we need to parse the parameter or not
                    if (((propValuetrim.Length > 1 && propValuetrim[0] == '{') || (propValuetrim.Length > 2 && propValuetrim[1] == '{')) && (propValuetrim[propValuetrim.Length - 1] == '}'))
                    {
                        ParamExprResolver pResv = new ParamExprResolver(element, propertyName, propValuetrim);
                        double?           propertyDoubleValue = pResv.GetDoubleValue();
                        if (propertyDoubleValue.HasValue)
                        {
                            propertyValue = propertyDoubleValue.Value;
                            return(parameter);
                        }
                    }

                    return(Double.TryParse(propValue, out propertyValue) ? parameter : null);
                }
                }
            }

            return(null);
        }