mscorlib(4.0.0.0) API with additions
XmlSchemaParticle.cs
2 
3 namespace System.Xml.Schema
4 {
6  public abstract class XmlSchemaParticle : XmlSchemaAnnotated
7  {
8  [Flags]
9  private enum Occurs
10  {
11  None = 0x0,
12  Min = 0x1,
13  Max = 0x2
14  }
15 
16  private class EmptyParticle : XmlSchemaParticle
17  {
18  internal override bool IsEmpty => true;
19  }
20 
21  private decimal minOccurs = decimal.One;
22 
23  private decimal maxOccurs = decimal.One;
24 
25  private Occurs flags;
26 
27  internal static readonly XmlSchemaParticle Empty = new EmptyParticle();
28 
31  [XmlAttribute("minOccurs")]
32  public string MinOccursString
33  {
34  get
35  {
36  if ((flags & Occurs.Min) != 0)
37  {
38  return XmlConvert.ToString(minOccurs);
39  }
40  return null;
41  }
42  set
43  {
44  if (value == null)
45  {
46  minOccurs = decimal.One;
47  flags &= ~Occurs.Min;
48  return;
49  }
50  minOccurs = XmlConvert.ToInteger(value);
51  if (minOccurs < decimal.Zero)
52  {
53  throw new XmlSchemaException("Sch_MinOccursInvalidXsd", string.Empty);
54  }
55  flags |= Occurs.Min;
56  }
57  }
58 
61  [XmlAttribute("maxOccurs")]
62  public string MaxOccursString
63  {
64  get
65  {
66  if ((flags & Occurs.Max) != 0)
67  {
68  if (!(maxOccurs == decimal.MaxValue))
69  {
70  return XmlConvert.ToString(maxOccurs);
71  }
72  return "unbounded";
73  }
74  return null;
75  }
76  set
77  {
78  if (value == null)
79  {
80  maxOccurs = decimal.One;
81  flags &= ~Occurs.Max;
82  return;
83  }
84  if (value == "unbounded")
85  {
86  maxOccurs = decimal.MaxValue;
87  }
88  else
89  {
90  maxOccurs = XmlConvert.ToInteger(value);
91  if (maxOccurs < decimal.Zero)
92  {
93  throw new XmlSchemaException("Sch_MaxOccursInvalidXsd", string.Empty);
94  }
95  if (maxOccurs == decimal.Zero && (flags & Occurs.Min) == Occurs.None)
96  {
97  minOccurs = default(decimal);
98  }
99  }
100  flags |= Occurs.Max;
101  }
102  }
103 
106  [XmlIgnore]
107  public decimal MinOccurs
108  {
109  get
110  {
111  return minOccurs;
112  }
113  set
114  {
115  if (value < decimal.Zero || value != decimal.Truncate(value))
116  {
117  throw new XmlSchemaException("Sch_MinOccursInvalidXsd", string.Empty);
118  }
119  minOccurs = value;
120  flags |= Occurs.Min;
121  }
122  }
123 
126  [XmlIgnore]
127  public decimal MaxOccurs
128  {
129  get
130  {
131  return maxOccurs;
132  }
133  set
134  {
135  if (value < decimal.Zero || value != decimal.Truncate(value))
136  {
137  throw new XmlSchemaException("Sch_MaxOccursInvalidXsd", string.Empty);
138  }
139  maxOccurs = value;
140  if (maxOccurs == decimal.Zero && (flags & Occurs.Min) == Occurs.None)
141  {
142  minOccurs = default(decimal);
143  }
144  flags |= Occurs.Max;
145  }
146  }
147 
148  internal virtual bool IsEmpty => maxOccurs == decimal.Zero;
149 
150  internal bool IsMultipleOccurrence => maxOccurs > decimal.One;
151 
152  internal virtual string NameString => string.Empty;
153 
154  internal XmlQualifiedName GetQualifiedName()
155  {
156  XmlSchemaElement xmlSchemaElement = this as XmlSchemaElement;
157  if (xmlSchemaElement != null)
158  {
159  return xmlSchemaElement.QualifiedName;
160  }
161  XmlSchemaAny xmlSchemaAny = this as XmlSchemaAny;
162  if (xmlSchemaAny != null)
163  {
164  string @namespace = xmlSchemaAny.Namespace;
165  @namespace = ((@namespace == null) ? string.Empty : @namespace.Trim());
166  return new XmlQualifiedName("*", (@namespace.Length == 0) ? "##any" : @namespace);
167  }
168  return XmlQualifiedName.Empty;
169  }
170  }
171 }
decimal MaxOccurs
Gets or sets the maximum number of times the particle can occur.
Definition: __Canon.cs:3
Represents an attribute. Valid and default values for the attribute are defined in a document type de...
Definition: XmlAttribute.cs:7
static string ToString(bool value)
Converts the T:System.Boolean to a T:System.String.
Definition: XmlConvert.cs:601
The base class for any element that can contain annotation elements.
decimal MinOccurs
Gets or sets the minimum number of times the particle can occur.
string MinOccursString
Gets or sets the number as a string value. The minimum number of times the particle can occur.
Represents an XML qualified name.
XmlQualifiedName QualifiedName
Gets the actual qualified name for the given element.
Represents the element element from XML Schema as specified by the World Wide Web Consortium (W3C)....
string MaxOccursString
Gets or sets the number as a string value. Maximum number of times the particle can occur.
Abstract class for that is the base class for all particle types (e.g. T:System.Xml....
Returns detailed information about the schema exception.
Encodes and decodes XML names, and provides methods for converting between common language runtime ty...
Definition: XmlConvert.cs:11