|
| 1 | +namespace Microsoft.Xml.XMLGen { |
| 2 | + using System; |
| 3 | + using System.Collections; |
| 4 | + using System.IO; |
| 5 | + using System.Text; |
| 6 | + using System.Xml.Schema; |
| 7 | + using System.Reflection; |
| 8 | + |
| 9 | + internal enum XmlSchemaWhiteSpace { |
| 10 | + Preserve, |
| 11 | + Replace, |
| 12 | + Collapse, |
| 13 | + } |
| 14 | + |
| 15 | + internal enum RestrictionFlags { |
| 16 | + Length = 0x0001, |
| 17 | + MinLength = 0x0002, |
| 18 | + MaxLength = 0x0004, |
| 19 | + Pattern = 0x0008, |
| 20 | + Enumeration = 0x0010, |
| 21 | + WhiteSpace = 0x0020, |
| 22 | + MaxInclusive = 0x0040, |
| 23 | + MaxExclusive = 0x0080, |
| 24 | + MinInclusive = 0x0100, |
| 25 | + MinExclusive = 0x0200, |
| 26 | + TotalDigits = 0x0400, |
| 27 | + FractionDigits = 0x0800, |
| 28 | + } |
| 29 | + |
| 30 | + internal class CompiledFacets { |
| 31 | + |
| 32 | + static FieldInfo lengthInfo; |
| 33 | + static FieldInfo minLengthInfo; |
| 34 | + static FieldInfo maxLengthInfo; |
| 35 | + static FieldInfo patternsInfo; |
| 36 | + static FieldInfo enumerationInfo; |
| 37 | + static FieldInfo whitespaceInfo; |
| 38 | + |
| 39 | + static FieldInfo maxInclusiveInfo; |
| 40 | + static FieldInfo maxExclusiveInfo; |
| 41 | + static FieldInfo minInclusiveInfo; |
| 42 | + static FieldInfo minExclusiveInfo; |
| 43 | + static FieldInfo totalDigitsInfo; |
| 44 | + static FieldInfo fractionDigitsInfo; |
| 45 | + |
| 46 | + static FieldInfo restrictionFlagsInfo; |
| 47 | + static FieldInfo restrictionFixedFlagsInfo; |
| 48 | + |
| 49 | + public static Type XsdSimpleValueType; |
| 50 | + public static Type XmlSchemaDatatypeType; |
| 51 | + |
| 52 | + object compiledRestriction; |
| 53 | + |
| 54 | + static CompiledFacets() { |
| 55 | + Assembly systemXmlAsm = typeof(XmlSchema).Assembly; |
| 56 | + |
| 57 | + Type RestrictionFacetsType = systemXmlAsm.GetType("System.Xml.Schema.RestrictionFacets", true); |
| 58 | + XsdSimpleValueType = systemXmlAsm.GetType("System.Xml.Schema.XsdSimpleValue", true); |
| 59 | + XmlSchemaDatatypeType = typeof(XmlSchemaDatatype); |
| 60 | + |
| 61 | + lengthInfo = RestrictionFacetsType.GetField("Length", BindingFlags.Instance | BindingFlags.NonPublic); |
| 62 | + minLengthInfo = RestrictionFacetsType.GetField("MinLength", BindingFlags.Instance | BindingFlags.NonPublic); |
| 63 | + maxLengthInfo = RestrictionFacetsType.GetField("MaxLength", BindingFlags.Instance | BindingFlags.NonPublic); |
| 64 | + patternsInfo = RestrictionFacetsType.GetField("Patterns", BindingFlags.Instance | BindingFlags.NonPublic); |
| 65 | + enumerationInfo = RestrictionFacetsType.GetField("Enumeration", BindingFlags.Instance | BindingFlags.NonPublic); |
| 66 | + whitespaceInfo = RestrictionFacetsType.GetField("WhiteSpace", BindingFlags.Instance | BindingFlags.NonPublic); |
| 67 | + |
| 68 | + maxInclusiveInfo = RestrictionFacetsType.GetField("MaxInclusive", BindingFlags.Instance | BindingFlags.NonPublic); |
| 69 | + maxExclusiveInfo = RestrictionFacetsType.GetField("MaxExclusive", BindingFlags.Instance | BindingFlags.NonPublic); |
| 70 | + minInclusiveInfo = RestrictionFacetsType.GetField("MinInclusive", BindingFlags.Instance | BindingFlags.NonPublic); |
| 71 | + minExclusiveInfo = RestrictionFacetsType.GetField("MinExclusive", BindingFlags.Instance | BindingFlags.NonPublic); |
| 72 | + |
| 73 | + totalDigitsInfo = RestrictionFacetsType.GetField("TotalDigits", BindingFlags.Instance | BindingFlags.NonPublic); |
| 74 | + fractionDigitsInfo = RestrictionFacetsType.GetField("FractionDigits", BindingFlags.Instance | BindingFlags.NonPublic); |
| 75 | + |
| 76 | + restrictionFlagsInfo = RestrictionFacetsType.GetField("Flags", BindingFlags.Instance | BindingFlags.NonPublic); |
| 77 | + restrictionFixedFlagsInfo = RestrictionFacetsType.GetField("FixedFlags", BindingFlags.Instance | BindingFlags.NonPublic); |
| 78 | + } |
| 79 | + |
| 80 | + public CompiledFacets(object restriction) { |
| 81 | + this.compiledRestriction = restriction; |
| 82 | + } |
| 83 | + |
| 84 | + public int Length { |
| 85 | + get { |
| 86 | + if (compiledRestriction == null) { |
| 87 | + return 0; |
| 88 | + } |
| 89 | + return (int)lengthInfo.GetValue(compiledRestriction); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + public int MinLength { |
| 94 | + get { |
| 95 | + if (compiledRestriction == null) { |
| 96 | + return 0; |
| 97 | + } |
| 98 | + return (int)minLengthInfo.GetValue(compiledRestriction); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + public int MaxLength { |
| 103 | + get { |
| 104 | + if (compiledRestriction == null) { |
| 105 | + return 0; |
| 106 | + } |
| 107 | + return (int)maxLengthInfo.GetValue(compiledRestriction); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + public ArrayList Patterns { |
| 112 | + get { |
| 113 | + if (compiledRestriction == null) { |
| 114 | + return null; |
| 115 | + } |
| 116 | + return (ArrayList)patternsInfo.GetValue(compiledRestriction); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + public ArrayList Enumeration { |
| 121 | + get { |
| 122 | + if (compiledRestriction == null) { |
| 123 | + return null; |
| 124 | + } |
| 125 | + return (ArrayList)enumerationInfo.GetValue(compiledRestriction); |
| 126 | + } |
| 127 | + } |
| 128 | + public XmlSchemaWhiteSpace WhiteSpace { |
| 129 | + get { |
| 130 | + if (compiledRestriction == null) { |
| 131 | + return XmlSchemaWhiteSpace.Preserve; |
| 132 | + } |
| 133 | + return (XmlSchemaWhiteSpace)whitespaceInfo.GetValue(compiledRestriction); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + public object MaxInclusive { |
| 138 | + get { |
| 139 | + if (compiledRestriction == null) { |
| 140 | + return null; |
| 141 | + } |
| 142 | + return maxInclusiveInfo.GetValue(compiledRestriction); |
| 143 | + } |
| 144 | + } |
| 145 | + public object MaxExclusive { |
| 146 | + get { |
| 147 | + if (compiledRestriction == null) { |
| 148 | + return null; |
| 149 | + } |
| 150 | + return maxExclusiveInfo.GetValue(compiledRestriction); |
| 151 | + } |
| 152 | + } |
| 153 | + public object MinInclusive { |
| 154 | + get { |
| 155 | + if (compiledRestriction == null) { |
| 156 | + return null; |
| 157 | + } |
| 158 | + return minInclusiveInfo.GetValue(compiledRestriction); |
| 159 | + } |
| 160 | + } |
| 161 | + public object MinExclusive { |
| 162 | + get { |
| 163 | + if (compiledRestriction == null) { |
| 164 | + return null; |
| 165 | + } |
| 166 | + return minExclusiveInfo.GetValue(compiledRestriction); |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + public int TotalDigits { |
| 171 | + get { |
| 172 | + if (compiledRestriction == null) { |
| 173 | + return 0; |
| 174 | + } |
| 175 | + return (int)totalDigitsInfo.GetValue(compiledRestriction); |
| 176 | + } |
| 177 | + } |
| 178 | + public int FractionDigits { |
| 179 | + get { |
| 180 | + if (compiledRestriction == null) { |
| 181 | + return 0; |
| 182 | + } |
| 183 | + return (int)fractionDigitsInfo.GetValue(compiledRestriction); |
| 184 | + } |
| 185 | + } |
| 186 | + public RestrictionFlags Flags { |
| 187 | + get { |
| 188 | + if (compiledRestriction == null) { |
| 189 | + return 0; |
| 190 | + } |
| 191 | + return (RestrictionFlags)restrictionFlagsInfo.GetValue(compiledRestriction); |
| 192 | + } |
| 193 | + } |
| 194 | + public RestrictionFlags FixedFlags { |
| 195 | + get { |
| 196 | + if (compiledRestriction == null) { |
| 197 | + return 0; |
| 198 | + } |
| 199 | + return (RestrictionFlags)restrictionFixedFlagsInfo.GetValue(compiledRestriction); |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | +} |
0 commit comments