public XmlValidationContext(PropertyInfo field, IAttributeDataProvider attributeProvider, IXmlValidatorDataProvider <string> dataProvider, IValidationReport report) { Field = field; AttributeProvider = attributeProvider; DataProvider = dataProvider; Report = report; }
/// <summary> /// Gets a value indicating whether the specified attribute should be written in the output. /// </summary> /// <param name="value">The attribute to check.</param> /// <returns>True if the attribute should be written based on the current settings, false indicates the /// attribute does not need to be written.</returns> private bool ShouldWriteAttributeString(IAttributeDataProvider value) { bool result; result = false; if (!value.IsOptional) { // Value is required so it must be written. result = true; } else if ((this.settings.Detail == OutputDetail.Full) && !object.Equals(value.GetStringValue(), null)) { // Full detail so write everything that isn't null (has no value). result = true; } else if ((this.settings.Detail == OutputDetail.Explicit) && value.HasValue) { // Explicit detail so only write things that have values explicitly set. result = true; } else if ((this.settings.Detail == OutputDetail.Minimal) && value.HasValue) { if (!value.IsDefaultValue) { // The value is different than the default. result = true; } else { string inheritedValue; if (value.TryGetInheritedStringValue(out inheritedValue) && (value.GetStringValue() != inheritedValue)) { // The value is the same as the default value but is different than an ancestor's value so it // needs to be written otherwise the inherited value will override the default. return(true); } // else there is no inherited value so the default can be used, or the value is the same as the // default value and an ancestor's value so the value can just be taken as the default or whatever // is written by the ancestor. } } return(result); }
/// <summary> /// Writes out an attribute to the current XmlElement. /// </summary> /// <param name="value">The value of the attribute.</param> /// <remarks>The value is written depending on the OutputDetail of the Settings and whether the /// attribute value is set.</remarks> private void WriteAttributeString(IAttributeDataProvider value) { this.writer.WriteAttributeString(value.Prefix, value.LocalName, value.Namespace, value.GetStringValue()); }
/// <summary> /// Gets a value indicating whether the specified attribute should be written in the output. /// </summary> /// <param name="value">The attribute to check.</param> /// <returns>True if the attribute should be written based on the current settings, false indicates the /// attribute does not need to be written.</returns> private bool ShouldWriteAttributeString(IAttributeDataProvider value) { bool result; result = false; if (!value.IsOptional) { // Value is required so it must be written. result = true; } else if ((this.settings.Detail == OutputDetail.Full) && !object.Equals(value.GetStringValue(), null)) { // Full detail so write everything that isn't null (has no value). result = true; } else if ((this.settings.Detail == OutputDetail.Explicit) && value.HasValue) { // Explicit detail so only write things that have values explicitly set. result = true; } else if ((this.settings.Detail == OutputDetail.Minimal) && value.HasValue) { if (!value.IsDefaultValue) { // The value is different than the default. result = true; } else { string inheritedValue; if (value.TryGetInheritedStringValue(out inheritedValue) && (value.GetStringValue() != inheritedValue)) { // The value is the same as the default value but is different than an ancestor's value so it // needs to be written otherwise the inherited value will override the default. return true; } // else there is no inherited value so the default can be used, or the value is the same as the // default value and an ancestor's value so the value can just be taken as the default or whatever // is written by the ancestor. } } return result; }