本文整理汇总了C#中System.Xml.Schema.XmlSchemaFacet类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaFacet类的具体用法?C# XmlSchemaFacet怎么用?C# XmlSchemaFacet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchemaFacet类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaFacet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileLengthFacet
internal void CompileLengthFacet(XmlSchemaFacet facet) {
CheckProhibitedFlag(facet, RestrictionFlags.Length, Res.Sch_LengthFacetProhibited);
CheckDupFlag(facet, RestrictionFlags.Length, Res.Sch_DupLengthFacet);
derivedRestriction.Length = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(nonNegativeInt, facet, Res.Sch_LengthFacetInvalid, null, null));
if ((baseFixedFlags & RestrictionFlags.Length) != 0) {
if (!datatype.IsEqual(datatype.Restriction.Length, derivedRestriction.Length)) {
throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
}
}
if ((baseFlags & RestrictionFlags.Length) != 0) {
if (datatype.Restriction.Length < derivedRestriction.Length) {
throw new XmlSchemaException(Res.Sch_LengthGtBaseLength, facet);
}
}
// If the base has the MinLength facet, check that our derived length is not violating it
if ((baseFlags & RestrictionFlags.MinLength) != 0) {
if (datatype.Restriction.MinLength > derivedRestriction.Length) {
throw new XmlSchemaException(Res.Sch_MaxMinLengthBaseLength, facet);
}
}
// If the base has the MaxLength facet, check that our derived length is not violating it
if ((baseFlags & RestrictionFlags.MaxLength) != 0) {
if (datatype.Restriction.MaxLength < derivedRestriction.Length) {
throw new XmlSchemaException(Res.Sch_MaxMinLengthBaseLength, facet);
}
}
SetFlag(facet, RestrictionFlags.Length);
}
示例2: Write_XmlSchemaFacet
private void Write_XmlSchemaFacet(string name, XmlSchemaFacet o)
{
if (o != null)
{
this.WriteStartElement(name);
this.WriteAttribute("id", "", o.Id);
this.WriteAttribute("value", "", o.Value);
if (o.IsFixed)
{
this.WriteAttribute("fixed", "", XmlConvert.ToString(o.IsFixed));
}
this.WriteAttributes(o.UnhandledAttributes, o);
this.Write5_XmlSchemaAnnotation(o.Annotation);
this.WriteEndElement();
}
}
示例3: OnLoadFacet
/// <summary>
/// Loads a facet for this property.
/// </summary>
/// <param name="facet">The facet to load for this property.</param>
protected override void OnLoadFacet(XmlSchemaFacet facet)
{
base.OnLoadFacet(facet);
var maxLengthFacet = facet as XmlSchemaMaxLengthFacet;
if (maxLengthFacet != null)
{
int.TryParse(maxLengthFacet.Value, out _iMaxLength);
}
else
{
var lengthFacet = facet as XmlSchemaLengthFacet;
if (lengthFacet != null)
{
int.TryParse(lengthFacet.Value, out _iMaxLength);
}
}
}
示例4: AddNonXsdPrimitive
private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
{
XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
Name = dataTypeName
};
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
BaseTypeName = baseTypeName
};
foreach (XmlSchemaFacet facet in facets)
{
restriction.Facets.Add(facet);
}
dataType.Content = restriction;
TypeDesc desc = new TypeDesc(type, false, dataType, formatterName, flags);
if (primitiveTypes[type] == null)
{
primitiveTypes.Add(type, desc);
}
primitiveDataTypes.Add(dataType, desc);
primitiveNames.Add(dataTypeName, ns, desc);
}
示例5: CheckDupFlag
private void CheckDupFlag(XmlSchemaFacet facet, RestrictionFlags flag, string errorCode) {
if ((derivedRestriction.Flags & flag) != 0) {
throw new XmlSchemaException(errorCode, facet);
}
}
示例6: CheckValue
private void CheckValue(object value, XmlSchemaFacet facet) {
RestrictionFacets restriction = datatype.Restriction;
switch (facet.FacetType) {
case FacetType.MaxInclusive:
if ((baseFlags & RestrictionFlags.MaxInclusive) != 0) { //Base facet has maxInclusive
if (datatype.Compare(value, restriction.MaxInclusive) > 0) {
throw new XmlSchemaException(Res.Sch_MaxInclusiveMismatch, string.Empty);
}
}
if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
if (datatype.Compare(value, restriction.MaxExclusive) >= 0) {
throw new XmlSchemaException(Res.Sch_MaxIncExlMismatch, string.Empty);
}
}
break;
case FacetType.MaxExclusive:
if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
if (datatype.Compare(value, restriction.MaxExclusive) > 0) {
throw new XmlSchemaException(Res.Sch_MaxExclusiveMismatch, string.Empty);
}
}
if ((baseFlags & RestrictionFlags.MaxInclusive) != 0) { //Base facet has maxInclusive
if (datatype.Compare(value, restriction.MaxInclusive) > 0) {
throw new XmlSchemaException(Res.Sch_MaxExlIncMismatch, string.Empty);
}
}
break;
case FacetType.MinInclusive:
if ((baseFlags & RestrictionFlags.MinInclusive) != 0) { //Base facet has minInclusive
if (datatype.Compare(value, restriction.MinInclusive) < 0) {
throw new XmlSchemaException(Res.Sch_MinInclusiveMismatch, string.Empty);
}
}
if ((baseFlags & RestrictionFlags.MinExclusive) != 0) { //Base facet has minExclusive
if (datatype.Compare(value, restriction.MinExclusive) < 0) {
throw new XmlSchemaException(Res.Sch_MinIncExlMismatch, string.Empty);
}
}
if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
if (datatype.Compare(value, restriction.MaxExclusive) >= 0) {
throw new XmlSchemaException(Res.Sch_MinIncMaxExlMismatch, string.Empty);
}
}
break;
case FacetType.MinExclusive:
if ((baseFlags & RestrictionFlags.MinExclusive) != 0) { //Base facet has minExclusive
if (datatype.Compare(value, restriction.MinExclusive) < 0) {
throw new XmlSchemaException(Res.Sch_MinExclusiveMismatch, string.Empty);
}
}
if ((baseFlags & RestrictionFlags.MinInclusive) != 0) { //Base facet has minInclusive
if (datatype.Compare(value, restriction.MinInclusive) < 0) {
throw new XmlSchemaException(Res.Sch_MinExlIncMismatch, string.Empty);
}
}
if ((baseFlags & RestrictionFlags.MaxExclusive) != 0) { //Base facet has maxExclusive
if (datatype.Compare(value, restriction.MaxExclusive) >= 0) {
throw new XmlSchemaException(Res.Sch_MinExlMaxExlMismatch, string.Empty);
}
}
break;
default:
Debug.Assert(false);
break;
}
}
示例7: CompileTotalDigitsFacet
internal void CompileTotalDigitsFacet(XmlSchemaFacet facet) {
CheckProhibitedFlag(facet, RestrictionFlags.TotalDigits, Res.Sch_TotalDigitsFacetProhibited);
CheckDupFlag(facet, RestrictionFlags.TotalDigits, Res.Sch_DupTotalDigitsFacet);
XmlSchemaDatatype positiveInt = DatatypeImplementation.GetSimpleTypeFromTypeCode(XmlTypeCode.PositiveInteger).Datatype;
derivedRestriction.TotalDigits = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(positiveInt, facet, Res.Sch_TotalDigitsFacetInvalid, null, null));
if ((baseFixedFlags & RestrictionFlags.TotalDigits) != 0) {
if (!datatype.IsEqual(datatype.Restriction.TotalDigits, derivedRestriction.TotalDigits)) {
throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
}
}
if ((baseFlags & RestrictionFlags.TotalDigits) != 0) {
if(derivedRestriction.TotalDigits > datatype.Restriction.TotalDigits) {
throw new XmlSchemaException(Res.Sch_TotalDigitsMismatch, string.Empty);
}
}
SetFlag(facet, RestrictionFlags.TotalDigits);
}
示例8: CompileWhitespaceFacet
internal void CompileWhitespaceFacet(XmlSchemaFacet facet) {
CheckProhibitedFlag(facet, RestrictionFlags.WhiteSpace, Res.Sch_WhiteSpaceFacetProhibited);
CheckDupFlag(facet, RestrictionFlags.WhiteSpace, Res.Sch_DupWhiteSpaceFacet);
if (facet.Value == "preserve") {
derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Preserve;
}
else if (facet.Value == "replace") {
derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Replace;
}
else if (facet.Value == "collapse") {
derivedRestriction.WhiteSpace = XmlSchemaWhiteSpace.Collapse;
}
else {
throw new XmlSchemaException(Res.Sch_InvalidWhiteSpace, facet.Value, facet);
}
if ((baseFixedFlags & RestrictionFlags.WhiteSpace) != 0) {
if (!datatype.IsEqual(datatype.Restriction.WhiteSpace, derivedRestriction.WhiteSpace)) {
throw new XmlSchemaException(Res.Sch_FacetBaseFixed, facet);
}
}
//Check base and derived whitespace facets
XmlSchemaWhiteSpace baseWhitespace;
if ((baseFlags & RestrictionFlags.WhiteSpace) != 0) {
baseWhitespace = datatype.Restriction.WhiteSpace;
}
else {
baseWhitespace = datatype.BuiltInWhitespaceFacet;
}
if ( baseWhitespace == XmlSchemaWhiteSpace.Collapse &&
(derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Replace || derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve)
) {
throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction1, facet);
}
if (baseWhitespace == XmlSchemaWhiteSpace.Replace &&
derivedRestriction.WhiteSpace == XmlSchemaWhiteSpace.Preserve
) {
throw new XmlSchemaException(Res.Sch_WhiteSpaceRestriction2, facet);
}
SetFlag(facet, RestrictionFlags.WhiteSpace);
}
示例9: Write_XmlSchemaFacet
void Write_XmlSchemaFacet(string name, XmlSchemaFacet o) {
if ((object)o == null) return;
WriteStartElement(name);
WriteAttribute("id", "", o.Id);
WriteAttribute("value", "", o.Value);
if (o.IsFixed) {
WriteAttribute(@"fixed", @"", XmlConvert.ToString(o.IsFixed));
}
WriteAttributes((XmlAttribute[])[email protected], o);
Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)[email protected]);
WriteEndElement();
}
示例10: OnLoadFacet
/// <summary>
/// Loads a facet for this property.
/// </summary>
/// <param name="facet">The facet to load for this property.</param>
protected override void OnLoadFacet(XmlSchemaFacet facet)
{
base.OnLoadFacet(facet);
var minFacet = facet as XmlSchemaMinInclusiveFacet;
if (minFacet != null)
{
decimal.TryParse(minFacet.Value, out _dMin);
}
else
{
var maxFacet = facet as XmlSchemaMaxInclusiveFacet;
if (maxFacet != null)
{
decimal.TryParse(maxFacet.Value, out _dMax);
}
else
{
var totalDigitsFacet = facet as XmlSchemaTotalDigitsFacet;
if (totalDigitsFacet != null)
{
int.TryParse(totalDigitsFacet.Value, out _iLength);
}
else
{
var factionFacet = facet as XmlSchemaFractionDigitsFacet;
if (factionFacet != null)
{
int.TryParse(factionFacet.Value, out _iDecimalPlaces);
}
}
}
}
}
示例11: CompileMinLengthFacet
internal void CompileMinLengthFacet(XmlSchemaFacet facet)
{
CheckProhibitedFlag(facet, RestrictionFlags.MinLength, SR.Sch_MinLengthFacetProhibited);
CheckDupFlag(facet, RestrictionFlags.MinLength, SR.Sch_DupMinLengthFacet);
_derivedRestriction.MinLength = XmlBaseConverter.DecimalToInt32((decimal)ParseFacetValue(_nonNegativeInt, facet, SR.Sch_MinLengthFacetInvalid, null, null));
if ((_baseFixedFlags & RestrictionFlags.MinLength) != 0)
{
if (!_datatype.IsEqual(_datatype.Restriction.MinLength, _derivedRestriction.MinLength))
{
throw new XmlSchemaException(SR.Sch_FacetBaseFixed, facet);
}
}
if ((_baseFlags & RestrictionFlags.MinLength) != 0)
{
if (_datatype.Restriction.MinLength > _derivedRestriction.MinLength)
{
throw new XmlSchemaException(SR.Sch_MinLengthGtBaseMinLength, facet);
}
}
if ((_baseFlags & RestrictionFlags.Length) != 0)
{
if (_datatype.Restriction.Length < _derivedRestriction.MinLength)
{
throw new XmlSchemaException(SR.Sch_MaxMinLengthBaseLength, facet);
}
}
SetFlag(facet, RestrictionFlags.MinLength);
}
示例12: CompileMaxInclusiveFacet
internal void CompileMaxInclusiveFacet(XmlSchemaFacet facet)
{
CheckProhibitedFlag(facet, RestrictionFlags.MaxInclusive, SR.Sch_MaxInclusiveFacetProhibited);
CheckDupFlag(facet, RestrictionFlags.MaxInclusive, SR.Sch_DupMaxInclusiveFacet);
_derivedRestriction.MaxInclusive = ParseFacetValue(_builtInType, facet, SR.Sch_MaxInclusiveFacetInvalid, null, null);
if ((_baseFixedFlags & RestrictionFlags.MaxInclusive) != 0)
{
if (!_datatype.IsEqual(_datatype.Restriction.MaxInclusive, _derivedRestriction.MaxInclusive))
{
throw new XmlSchemaException(SR.Sch_FacetBaseFixed, facet);
}
}
CheckValue(_derivedRestriction.MaxInclusive, facet);
SetFlag(facet, RestrictionFlags.MaxInclusive);
}
示例13: checkMinLengthFacet
private void checkMinLengthFacet(XmlSchemaMinLengthFacet minlf,
XmlSchemaFacet.Facet facetsDefined,
ValidationEventHandler h) {
if (minlf != null) {
try {
if (lengthFacet >=0)
minlf.error(h, "It is an error for both length and minLength or maxLength to be present.");
else {
decimal newMinLengthFacet = decimal.Parse (minlf.Value.Trim (), lengthStyle, CultureInfo.InvariantCulture);
if (((fixedFacets & XmlSchemaFacet.Facet.minLength)!=0) && (newMinLengthFacet != minLengthFacet))
minlf.error(h, String.Format(CultureInfo.InvariantCulture, "The value '{0}' is not the same as the fixed value '{1}' on the base type", minlf.Value.Trim (), minLengthFacet));
if (newMinLengthFacet < minLengthFacet)
minlf.error(h, String.Format(CultureInfo.InvariantCulture, "The value '{0}' is not a valid restriction of the value '{1}' on the base minLength facet", minlf.Value.Trim (), minLengthFacet));
else
minLengthFacet = newMinLengthFacet;
if (minLengthFacet < 0)
minlf.error(h, "The value '" + minLengthFacet + "' is an invalid minLength");
if (maxLengthFacet >=0 && minLengthFacet > maxLengthFacet)
minlf.error(h, "minLength is greater than maxLength.");
}
} catch (FormatException) {
minlf.error (h, "The value '" + minlf.Value + "' is an invalid minLength facet specification");
}
}
}
示例14: checkLengthFacet
private void checkLengthFacet(XmlSchemaLengthFacet lf,
XmlSchemaFacet.Facet facetsDefined,
ValidationEventHandler h) {
if (lf != null) {
try {
if ((facetsDefined & (XmlSchemaFacet.Facet.minLength | XmlSchemaFacet.Facet.maxLength)) != 0)
lf.error(h, "It is an error for both length and minLength or maxLength to be present.");
else {
lengthFacet = decimal.Parse (lf.Value.Trim (), lengthStyle, CultureInfo.InvariantCulture);
/* TODO: Check that it is between inherited max/min lengths */
if (lengthFacet < 0)
lf.error(h, "The value '" + lengthFacet + "' is an invalid length");
}
} catch (FormatException) { // FIXME: better catch ;-(
lf.error (h, "The value '" + lf.Value + "' is an invalid length facet specification");
}
}
}
示例15: checkMinMaxFacet
private void checkMinMaxFacet(XmlSchemaFacet facet,
ref object baseFacet,
ValidationEventHandler h) {
// Is it a valid instance of the base type.
object newValue = ValidateValueWithDatatype(facet.Value);
if (newValue != null) {
// Is the base fixed - if so is it the same
if (((fixedFacets & facet.ThisFacet) != 0) && (baseFacet != null)){
XsdAnySimpleType dt = getDatatype();
if (dt.Compare (newValue, baseFacet) != XsdOrdering.Equal) {
facet.error (h,
String.Format(CultureInfo.InvariantCulture, "{0} is not the same as fixed parent {1} facet.",
facet.Value, facet.ThisFacet));
}
}
baseFacet = newValue;
}
else {
facet.error(h,
String.Format("The value '{0}' is not valid against the base type.", facet.Value));
}
}