XmlSchemaParticle.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml.Serialization;
  5. namespace System.Xml.Schema
  6. {
  7. /// <summary>
  8. /// Summary description for XmlSchemaParticle.
  9. /// </summary>
  10. public abstract class XmlSchemaParticle : XmlSchemaAnnotated
  11. {
  12. decimal minOccurs, maxOccurs;
  13. string minstr, maxstr;
  14. static XmlSchemaParticle empty;
  15. internal static XmlSchemaParticle Empty {
  16. get {
  17. if (empty == null) {
  18. empty = new XmlSchemaParticleEmpty ();
  19. }
  20. return empty;
  21. }
  22. }
  23. protected XmlSchemaParticle()
  24. {
  25. minOccurs = decimal.One;
  26. maxOccurs = decimal.One;
  27. }
  28. #region Attributes
  29. [System.Xml.Serialization.XmlAttribute("minOccurs")]
  30. public string MinOccursString
  31. {
  32. get{ return minstr; }
  33. set
  34. {
  35. decimal val = decimal.Parse(value);
  36. if(val >= 0 && (val == Decimal.Truncate(val)))
  37. {
  38. minOccurs = val;
  39. minstr = val.ToString();
  40. }
  41. else
  42. {
  43. throw new XmlSchemaException
  44. ("MinOccursString must be a non-negative number",null);
  45. }
  46. }
  47. }
  48. [System.Xml.Serialization.XmlAttribute("maxOccurs")]
  49. public string MaxOccursString
  50. {
  51. get{ return maxstr; }
  52. set
  53. {
  54. if(value == "unbounded")
  55. {
  56. maxstr = value;
  57. maxOccurs = decimal.MaxValue;
  58. }
  59. else
  60. {
  61. decimal val = decimal.Parse(value);
  62. if(val >= 0 && (val == Decimal.Truncate(val)))
  63. {
  64. maxOccurs = val;
  65. maxstr = val.ToString();
  66. }
  67. else
  68. {
  69. throw new XmlSchemaException
  70. ("MaxOccurs must be a non-negative integer",null);
  71. }
  72. }
  73. }
  74. }
  75. #endregion
  76. #region XmlIgnore
  77. [XmlIgnore]
  78. public decimal MinOccurs
  79. {
  80. get{ return minOccurs; }
  81. set
  82. {
  83. MinOccursString = value.ToString();
  84. }
  85. }
  86. [XmlIgnore]
  87. public decimal MaxOccurs
  88. {
  89. get{ return maxOccurs; }
  90. set
  91. {
  92. MaxOccursString = value.ToString();
  93. }
  94. }
  95. #endregion
  96. #region Internal Class
  97. public class XmlSchemaParticleEmpty : XmlSchemaParticle
  98. {
  99. internal XmlSchemaParticleEmpty ()
  100. {
  101. }
  102. }
  103. #endregion
  104. }
  105. }