Exemple #1
0
        public static IValueModel GetValueModel(this BaseParameter parameter, bool allowNullInput)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException("parameter");
            }

            var lb = parameter.GetLabel();

            if (parameter is BoolParameter && !parameter.IsList)
            {
                return(new BoolValueModel(lb, parameter.Description, allowNullInput, false));
            }
            else if (parameter is DateTimeParameter && !parameter.IsList)
            {
                var dtp = (DateTimeParameter)parameter;
                return(new DateTimeValueModel(lb, parameter.Description, allowNullInput, false, dtp.DateTimeStyle ?? DateTimeStyles.DateTime));
            }
            else if (parameter is DoubleParameter && !parameter.IsList)
            {
                return(new NullableStructValueModel <double>(lb, parameter.Description, allowNullInput, false));
            }
            else if (parameter is IntParameter && !parameter.IsList)
            {
                return(new NullableStructValueModel <int>(lb, parameter.Description, allowNullInput, false));
            }
            else if (parameter is DecimalParameter && !parameter.IsList)
            {
                return(new DecimalValueModel(lb, parameter.Description, allowNullInput, false));
            }
            else if (parameter is StringParameter && !parameter.IsList)
            {
                return(new ClassValueModel <string>(lb, parameter.Description, allowNullInput, false));
            }
            else if (parameter is ObjectReferenceParameter && !parameter.IsList)
            {
                return(new ObjectReferenceValueModel(lb, parameter.Description, allowNullInput, false, ((ObjectReferenceParameter)parameter).ObjectClass));
            }
            else if (parameter is EnumParameter && !parameter.IsList)
            {
                return(new EnumerationValueModel(lb, parameter.Description, allowNullInput, false, ((EnumParameter)parameter).Enumeration));
            }
            else if (parameter is CompoundObjectParameter && !parameter.IsList)
            {
                return(new CompoundObjectValueModel(lb, parameter.Description, allowNullInput, false, ((CompoundObjectParameter)parameter).CompoundObject));
            }
            else
            {
                Logging.Log.WarnFormat("No model for parameter '{0}' of type '{1}'", parameter, parameter.GetParameterTypeString());
                return(null);
            }
        }