internal void PopulateFromXml( XPathNavigator containerNav, string elementName, ConvertToType convert) { XPathNodeIterator elementsIterator = containerNav.Select(elementName); foreach (XPathNavigator elementNav in elementsIterator) { var language = elementNav.GetAttribute("lang", "http://www.w3.org/XML/1998/namespace"); if (string.IsNullOrEmpty(language)) { language = DefaultLanguage; } var elementValue = elementNav.Value; if (!string.IsNullOrEmpty(elementValue)) { this[language] = convert(elementValue); } else { // Remove any existing value. if (ContainsKey(language)) { Remove(language); } } } }
internal override void PopulateFromXml( XPathNavigator containerNav, string elementName) { ConvertToType stringConvert = ConvertToString; PopulateFromXml( containerNav, elementName, stringConvert); }
internal override void PopulateFromXml( XPathNavigator containerNav, string elementName) { ConvertToType byteArrayConvert = ConvertToByteArray; PopulateFromXml( containerNav, elementName, byteArrayConvert); }
/// <summary> /// HACK - New Feature - fixed constructor to support date and decimal types since these are not allowed in a attributes constructor /// There is some restriction on the data types that can be used as attribute parameters. /// Parameters can be any integral data type (Byte, Short, Integer, Long) or floating point data type (Single and Double), as well as Char, String, Boolean, an enumerated type, or System.Type. /// Thus, Date, Decimal, Object, and structured types cannot be used as parameters. /// </summary> /// <param name="lowerRangeBoundaryType">Type of the lower range boundary.</param> /// <param name="lowerValue">The lower value.</param> /// <param name="upperRangeBoundaryType">Type of the upper range boundary.</param> /// <param name="upperValue">The upper value.</param> /// <param name="requiredEntry">The required entry.</param> /// <param name="convertToType">Type of the convert to.</param> public RangeValidatorAttribute(RangeBoundaryType lowerRangeBoundaryType, String lowerValue, RangeBoundaryType upperRangeBoundaryType, String upperValue, RequiredEntry requiredEntry, ConvertToType convertToType) { switch (convertToType) { case ConvertToType.Date: this.LowerValue = Convert.ToDateTime(lowerValue); this.UpperValue = Convert.ToDateTime(upperValue); break; case ConvertToType.Decimal: this.LowerValue = Convert.ToDecimal(lowerValue); this.UpperValue = Convert.ToDecimal(upperValue); break; default: throw new OverflowException(String.Format(Resources.RangeValidatorAttribute_RangeValidatorAttribute_This_ConvertToType_has_not_yet_been_programmed__value_passed_was___0_FormatString, convertToType)); } this.LowerRangeBoundaryType = lowerRangeBoundaryType; this.UpperRangeBoundaryType = upperRangeBoundaryType; this.RequiredEntry = requiredEntry; }
/// <summary> /// There is some restriction on the data types that can be used as attribute parameters. /// Parameters can be any integral data type (Byte, Short, Integer, Long) or floating point data type (Single and Double), as well as Char, String, Boolean, an enumerated type, or System.Type. /// Thus, Date, Decimal, Object, and structured types cannot be used as parameters. /// </summary> /// <param name="comparisonType">Type of the comparison.</param> /// <param name="compareToValue">The compare to value.</param> /// <param name="requiredEntry">The required entry.</param> /// <param name="convertToType">Type of the convert to.</param> /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception> /// <exception cref="InvalidEnumArgumentException">comparisonType is not a member of ComparisonType enum.</exception> /// <exception cref="InvalidEnumArgumentException">convertToType is not a member of ConvertToType enum.</exception> public CompareValueValidatorAttribute(ComparisonType comparisonType, String compareToValue, RequiredEntry requiredEntry, ConvertToType convertToType) { if (!Enum.IsDefined(typeof(ComparisonType), comparisonType)) { throw new InvalidEnumArgumentException(nameof(comparisonType), (Int32)comparisonType, typeof(ComparisonType)); } if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry)) { throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry)); } if (!Enum.IsDefined(typeof(ConvertToType), convertToType)) { throw new InvalidEnumArgumentException(nameof(convertToType), (Int32)convertToType, typeof(ConvertToType)); } this.ComparisonType = comparisonType; switch (convertToType) { case ConvertToType.Date: this.CompareToValue = Convert.ToDateTime(compareToValue); break; case ConvertToType.Decimal: this.CompareToValue = Convert.ToDecimal(compareToValue); break; } this.RequiredEntry = requiredEntry; }
/// <summary> /// Added constructor to support date and decimal types since these are not allowed in a attributes constructor /// There is some restriction on the data types that can be used as attribute parameters. /// Parameters can be any integral data type (Byte, Short, Integer, Long) or floating point data type (Single and Double), as well as Char, String, Boolean, an enumerated type, or System.Type. /// Thus, Date, Decimal, Object, and structured types cannot be used as parameters. /// </summary> /// <param name="lowerRangeBoundaryType">Type of the lower range boundary.</param> /// <param name="lowerValue">The lower value.</param> /// <param name="upperRangeBoundaryType">Type of the upper range boundary.</param> /// <param name="upperValue">The upper value.</param> /// <param name="requiredEntry">The required entry.</param> /// <param name="convertToType">Type of the convert to.</param> /// <exception cref="InvalidEnumArgumentException">requiredEntry is not member of RequiredEntry enum.</exception> /// <exception cref="InvalidEnumArgumentException">lowerRangeBoundaryType is not member of RangeBoundaryType enum.</exception> /// <exception cref="InvalidEnumArgumentException">upperRangeBoundaryType is not member of RangeBoundaryType enum.</exception> public RangeValidatorAttribute(RangeBoundaryType lowerRangeBoundaryType, String lowerValue, RangeBoundaryType upperRangeBoundaryType, String upperValue, RequiredEntry requiredEntry, ConvertToType convertToType) { if (!Enum.IsDefined(typeof(RangeBoundaryType), lowerRangeBoundaryType)) { throw new InvalidEnumArgumentException(nameof(lowerRangeBoundaryType), (Int32)lowerRangeBoundaryType, typeof(RangeBoundaryType)); } if (!Enum.IsDefined(typeof(RequiredEntry), requiredEntry)) { throw new InvalidEnumArgumentException(nameof(requiredEntry), (Int32)requiredEntry, typeof(RequiredEntry)); } if (!Enum.IsDefined(typeof(RangeBoundaryType), upperRangeBoundaryType)) { throw new InvalidEnumArgumentException(nameof(upperRangeBoundaryType), (Int32)upperRangeBoundaryType, typeof(RangeBoundaryType)); } switch (convertToType) { case ConvertToType.Date: this.LowerValue = Convert.ToDateTime(lowerValue); this.UpperValue = Convert.ToDateTime(upperValue); break; case ConvertToType.Decimal: this.LowerValue = Convert.ToDecimal(lowerValue); this.UpperValue = Convert.ToDecimal(upperValue); break; } this.LowerRangeBoundaryType = lowerRangeBoundaryType; this.UpperRangeBoundaryType = upperRangeBoundaryType; this.RequiredEntry = requiredEntry; }
/// <summary> /// HACK - New Feature - fixed constructor to support date and decimal types since these are not allowed in a attributes constructor /// There is some restriction on the data types that can be used as attribute parameters. /// Parameters can be any integral data type (Byte, Short, Integer, Long) or floating point data type (Single and Double), as well as Char, String, Boolean, an enumerated type, or System.Type. /// Thus, Date, Decimal, Object, and structured types cannot be used as parameters. /// </summary> /// <param name="comparisonType">Type of the comparison.</param> /// <param name="compareToValue">The compare to value.</param> /// <param name="requiredEntry">The required entry.</param> /// <param name="convertToType">Type of the convert to.</param> public CompareValueValidatorAttribute(ComparisonType comparisonType, String compareToValue, RequiredEntry requiredEntry, ConvertToType convertToType) { this.ComparisonType = comparisonType; switch (convertToType) { case ConvertToType.Date: this.CompareToValue = Convert.ToDateTime(compareToValue); break; case ConvertToType.Decimal: this.CompareToValue = Convert.ToDecimal(compareToValue); break; default: throw new OverflowException(String.Format(Resources.CompareValueValidatorAttribute_CompareValueValidatorAttribute_This_ConvertToType_has_not_yet_been_programmed__value_passed_was___0_FomatString, convertToType)); } this.RequiredEntry = requiredEntry; }