Пример #1
0
        /// <summary>Validate a string representing a value (for a preference or attribute).</summary>
        /// <param name="type"></param><param name="value"></param><param name="representation"></param>
        /// <returns></returns>
        public static bool Validate(MetaAttribute.MetaAttributeDataType type, string value, FormattedOrRaw representation)
        {
            if (value == null) return false;

            switch (type)
            {
                case MetaAttribute.MetaAttributeDataType.STRING: return ValidateString(value, representation);
                case MetaAttribute.MetaAttributeDataType.INTEGER: return ValidateInteger(value, representation);
                case MetaAttribute.MetaAttributeDataType.CURRENCY: return ValidateCurrency(value, representation);
                default: throw new Exception("Unknown MetaAttributeDataType: " + type.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a new ValueContainer of the appropriate specialisation. 
        /// </summary>
        /// <param name="value"></param><param name="type"></param><param name="format"></param>
        /// <returns></returns>
        public static ValueContainer Create(string value, MetaAttribute.MetaAttributeDataType type, FormattedOrRaw format)
        {
            Contract.Assert(ValueContainerValidator.Validate(type, value, format), "Value " + value + " is not valid.");

            switch (type)
            {
                case MetaAttribute.MetaAttributeDataType.CURRENCY: return (value.Length > 0) ? new CurrencyValue(value, format) : null;
                case MetaAttribute.MetaAttributeDataType.INTEGER: return (value.Length > 0) ? new IntegerValue(value, format) : null;
                case MetaAttribute.MetaAttributeDataType.STRING: return (value.Length > 0) ? new StringValue(value, format) : null;
                default: throw new Exception("Unknown data type " + type.ToString());
            }
        }