XmlSchemaImporter.cs 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. //
  2. // System.Xml.Serialization.XmlSchemaImporter
  3. //
  4. // Author:
  5. // Tim Coleman ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Tim Coleman, 2002
  9. //
  10. using System.Xml;
  11. using System.Xml.Schema;
  12. using System.Collections;
  13. namespace System.Xml.Serialization {
  14. public class XmlSchemaImporter {
  15. #region Fields
  16. XmlSchemas schemas;
  17. CodeIdentifiers typeIdentifiers;
  18. CodeIdentifiers elemIdentifiers = new CodeIdentifiers ();
  19. Hashtable mappedTypes = new Hashtable ();
  20. Hashtable dataMappedTypes = new Hashtable ();
  21. Queue pendingMaps = new Queue ();
  22. Hashtable sharedAnonymousTypes = new Hashtable ();
  23. static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
  24. XmlSchemaElement anyElement = null;
  25. class MapFixup
  26. {
  27. public XmlTypeMapping Map;
  28. public XmlSchemaComplexType SchemaType;
  29. public XmlQualifiedName TypeName;
  30. }
  31. #endregion
  32. #region Constructors
  33. public XmlSchemaImporter (XmlSchemas schemas)
  34. {
  35. this.schemas = schemas;
  36. typeIdentifiers = new CodeIdentifiers ();
  37. }
  38. public XmlSchemaImporter (XmlSchemas schemas, CodeIdentifiers typeIdentifiers)
  39. : this (schemas)
  40. {
  41. this.typeIdentifiers = typeIdentifiers;
  42. }
  43. #endregion // Constructors
  44. #region Methods
  45. [MonoTODO]
  46. public XmlMembersMapping ImportAnyType (XmlQualifiedName typeName, string elementName)
  47. {
  48. throw new NotImplementedException ();
  49. }
  50. [MonoTODO]
  51. public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name, Type baseType)
  52. {
  53. throw new NotImplementedException ();
  54. }
  55. [MonoTODO]
  56. public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name, bool baseTypeCanBeIndirect)
  57. {
  58. throw new NotImplementedException ();
  59. }
  60. [MonoTODO]
  61. public XmlTypeMapping ImportDerivedTypeMapping (XmlQualifiedName name,
  62. Type baseType,
  63. bool baseTypeCanBeIndirect)
  64. {
  65. throw new NotImplementedException ();
  66. }
  67. [MonoTODO]
  68. public XmlMembersMapping ImportMembersMapping (XmlQualifiedName name)
  69. {
  70. throw new NotImplementedException ();
  71. }
  72. [MonoTODO]
  73. public XmlMembersMapping ImportMembersMapping (XmlQualifiedName[] names)
  74. {
  75. throw new NotImplementedException ();
  76. }
  77. [MonoTODO]
  78. public XmlMembersMapping ImportMembersMapping (XmlQualifiedName[] names, Type baseType, bool baseTypeCanBeIndirect)
  79. {
  80. throw new NotImplementedException ();
  81. }
  82. public XmlTypeMapping ImportTypeMapping (XmlQualifiedName name)
  83. {
  84. XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (name, typeof (XmlSchemaElement));
  85. if (elem == null) return null;
  86. // The root element must be an element with complex type
  87. XmlQualifiedName qname;
  88. XmlSchemaType stype;
  89. if (elem.SchemaType != null)
  90. {
  91. stype = elem.SchemaType;
  92. qname = name;
  93. }
  94. else
  95. {
  96. if (elem.SchemaTypeName.IsEmpty) return null;
  97. if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace) return null;
  98. object type = schemas.Find (elem.SchemaTypeName, typeof (XmlSchemaComplexType));
  99. if (type == null) type = schemas.Find (elem.SchemaTypeName, typeof (XmlSchemaSimpleType));
  100. if (type == null) throw new InvalidOperationException ("Schema type '" + elem.SchemaTypeName + "' not found");
  101. stype = (XmlSchemaType) type;
  102. qname = stype.QualifiedName;
  103. }
  104. if (stype is XmlSchemaSimpleType) return null;
  105. XmlTypeMapping map = CreateTypeMapping (qname, SchemaTypes.Class, name);
  106. map.Documentation = GetDocumentation (stype);
  107. RegisterMapFixup (map, qname, (XmlSchemaComplexType)stype);
  108. BuildPendingMaps ();
  109. return map;
  110. }
  111. public XmlTypeMapping ImportType (XmlQualifiedName name, XmlQualifiedName root)
  112. {
  113. XmlTypeMapping map = GetRegisteredTypeMapping (name);
  114. if (map != null) return map;
  115. XmlSchemaType type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaComplexType));
  116. if (type == null) type = (XmlSchemaType) schemas.Find (name, typeof (XmlSchemaSimpleType));
  117. return ImportType (name, type, root);
  118. }
  119. XmlTypeMapping ImportType (XmlQualifiedName name, XmlSchemaType stype, XmlQualifiedName root)
  120. {
  121. XmlTypeMapping map = GetRegisteredTypeMapping (name);
  122. if (map != null) return map;
  123. if (stype is XmlSchemaComplexType)
  124. return ImportClassComplexType (name, (XmlSchemaComplexType) stype, root);
  125. else if (stype is XmlSchemaSimpleType)
  126. return ImportClassSimpleType (name, (XmlSchemaSimpleType) stype, root);
  127. throw new NotSupportedException ("Schema type not supported: " + stype.GetType ());
  128. }
  129. XmlTypeMapping ImportClassComplexType (XmlQualifiedName typeQName, XmlSchemaComplexType stype, XmlQualifiedName root)
  130. {
  131. XmlTypeMapping map;
  132. // The need for fixups: If the complex type is an array, then to get the type of the
  133. // array we need first to get the type of the items of the array.
  134. // But if one of the item types or its children has a referece to this type array,
  135. // then we enter in an infinite loop. This does not happen with class types because
  136. // the class map is registered before parsing the children. We can't do the same
  137. // with the array type because to register the array map we need the type of the array.
  138. if (CanBeArray (typeQName, stype))
  139. {
  140. TypeData typeData;
  141. ListMap listMap = BuildArrayMap (typeQName, stype, out typeData);
  142. if (listMap != null)
  143. {
  144. map = CreateArrayTypeMapping (typeQName, typeData);
  145. map.ObjectMap = listMap;
  146. return map;
  147. }
  148. // After all, it is not an array. Create a class map then.
  149. }
  150. else if (CanBeAnyElement (stype))
  151. {
  152. return GetTypeMapping (TypeTranslator.GetTypeData(typeof(XmlElement)));
  153. }
  154. else if (CanBeIXmlSerializable (stype))
  155. {
  156. return GetTypeMapping (TypeTranslator.GetTypeData(typeof(object)));
  157. }
  158. // Register the map right now but do not build it,
  159. // This will avoid loops.
  160. map = CreateTypeMapping (typeQName, SchemaTypes.Class, root);
  161. map.Documentation = GetDocumentation (stype);
  162. RegisterMapFixup (map, typeQName, stype);
  163. return map;
  164. }
  165. void RegisterMapFixup (XmlTypeMapping map, XmlQualifiedName typeQName, XmlSchemaComplexType stype)
  166. {
  167. MapFixup fixup = new MapFixup ();
  168. fixup.Map = map;
  169. fixup.SchemaType = stype;
  170. fixup.TypeName = typeQName;
  171. pendingMaps.Enqueue (fixup);
  172. }
  173. void BuildPendingMaps ()
  174. {
  175. while (pendingMaps.Count > 0) {
  176. MapFixup fixup = (MapFixup) pendingMaps.Dequeue ();
  177. if (fixup.Map.ObjectMap == null) {
  178. BuildClassMap (fixup.Map, fixup.TypeName, fixup.SchemaType);
  179. if (fixup.Map.ObjectMap == null) pendingMaps.Enqueue (fixup);
  180. }
  181. }
  182. }
  183. void BuildPendingMap (XmlTypeMapping map)
  184. {
  185. if (map.ObjectMap != null) return;
  186. foreach (MapFixup fixup in pendingMaps)
  187. {
  188. if (fixup.Map == map) {
  189. BuildClassMap (fixup.Map, fixup.TypeName, fixup.SchemaType);
  190. return;
  191. }
  192. }
  193. throw new InvalidOperationException ("Can't complete map of type " + map.XmlType + " : " + map.Namespace);
  194. }
  195. void BuildClassMap (XmlTypeMapping map, XmlQualifiedName typeQName, XmlSchemaComplexType stype)
  196. {
  197. CodeIdentifiers classIds = new CodeIdentifiers();
  198. classIds.AddReserved (map.TypeData.TypeName);
  199. ClassMap cmap = new ClassMap ();
  200. map.ObjectMap = cmap;
  201. bool isMixed = stype.IsMixed;
  202. if (stype.Particle != null)
  203. {
  204. ImportParticleComplexContent (typeQName, cmap, stype.Particle, classIds, isMixed);
  205. }
  206. else
  207. {
  208. if (stype.ContentModel is XmlSchemaSimpleContent) {
  209. ImportSimpleContent (typeQName, map, (XmlSchemaSimpleContent)stype.ContentModel, classIds, isMixed);
  210. }
  211. else if (stype.ContentModel is XmlSchemaComplexContent) {
  212. ImportComplexContent (typeQName, map, (XmlSchemaComplexContent)stype.ContentModel, classIds, isMixed);
  213. }
  214. }
  215. ImportAttributes (typeQName, cmap, stype.Attributes, stype.AnyAttribute, classIds);
  216. }
  217. void ImportAttributes (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat, CodeIdentifiers classIds)
  218. {
  219. if (anyat != null)
  220. {
  221. XmlTypeMapMemberAnyAttribute member = new XmlTypeMapMemberAnyAttribute ();
  222. member.Name = classIds.AddUnique ("AnyAttribute", member);
  223. member.TypeData = TypeTranslator.GetTypeData (typeof(XmlAttribute[]));
  224. cmap.AddMember (member);
  225. }
  226. foreach (XmlSchemaObject at in atts)
  227. {
  228. if (at is XmlSchemaAttribute)
  229. {
  230. string ns;
  231. XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
  232. XmlSchemaAttribute refAttr = GetRefAttribute (typeQName, attr, out ns);
  233. XmlTypeMapMemberAttribute member = new XmlTypeMapMemberAttribute ();
  234. member.Name = classIds.AddUnique (CodeIdentifier.MakeValid (refAttr.Name), member);
  235. member.Documentation = GetDocumentation (attr);
  236. member.AttributeName = refAttr.Name;
  237. member.Namespace = ns;
  238. member.Form = refAttr.Form;
  239. member.TypeData = GetAttributeTypeData (typeQName, attr);
  240. if (refAttr.DefaultValue != null) member.DefaultValue = XmlCustomFormatter.FromXmlString (member.TypeData, refAttr.DefaultValue);
  241. if (member.TypeData.IsComplexType)
  242. member.MappedType = GetTypeMapping (member.TypeData);
  243. cmap.AddMember (member);
  244. }
  245. else if (at is XmlSchemaAttributeGroupRef)
  246. {
  247. XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
  248. XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  249. ImportAttributes (typeQName, cmap, grp.Attributes, grp.AnyAttribute, classIds);
  250. }
  251. }
  252. }
  253. ListMap BuildArrayMap (XmlQualifiedName typeQName, XmlSchemaComplexType stype, out TypeData arrayTypeData)
  254. {
  255. ClassMap cmap = new ClassMap ();
  256. CodeIdentifiers classIds = new CodeIdentifiers();
  257. ImportParticleComplexContent (typeQName, cmap, stype.Particle, classIds, false);
  258. XmlTypeMapMemberFlatList list = (cmap.AllMembers.Count == 1) ? cmap.AllMembers[0] as XmlTypeMapMemberFlatList : null;
  259. if (list != null && list.ChoiceMember == null)
  260. {
  261. arrayTypeData = list.TypeData;
  262. return list.ListMap;
  263. }
  264. else
  265. {
  266. arrayTypeData = null;
  267. return null;
  268. }
  269. }
  270. void ImportParticleComplexContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaParticle particle, CodeIdentifiers classIds, bool isMixed)
  271. {
  272. ImportParticleContent (typeQName, cmap, particle, classIds, false, ref isMixed);
  273. if (isMixed)
  274. {
  275. XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
  276. member.Name = classIds.AddUnique ("Text", member);
  277. member.TypeData = TypeTranslator.GetTypeData (typeof(string[]));
  278. member.ElementInfo.Add (CreateTextElementInfo (typeQName.Namespace, member, member.TypeData.ListItemTypeData));
  279. member.IsXmlTextCollector = true;
  280. member.ListMap = new ListMap ();
  281. member.ListMap.ItemInfo = member.ElementInfo;
  282. cmap.AddMember (member);
  283. }
  284. }
  285. void ImportParticleContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaParticle particle, CodeIdentifiers classIds, bool multiValue, ref bool isMixed)
  286. {
  287. if (particle is XmlSchemaGroupRef)
  288. particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
  289. if (particle.MaxOccurs > 1) multiValue = true;
  290. if (particle is XmlSchemaSequence) {
  291. ImportSequenceContent (typeQName, cmap, ((XmlSchemaSequence)particle).Items, classIds, multiValue, ref isMixed);
  292. }
  293. else if (particle is XmlSchemaChoice) {
  294. if (((XmlSchemaChoice)particle).Items.Count == 1)
  295. ImportSequenceContent (typeQName, cmap, ((XmlSchemaChoice)particle).Items, classIds, multiValue, ref isMixed);
  296. else
  297. ImportChoiceContent (typeQName, cmap, (XmlSchemaChoice)particle, classIds, multiValue);
  298. }
  299. else if (particle is XmlSchemaAll) {
  300. ImportSequenceContent (typeQName, cmap, ((XmlSchemaAll)particle).Items, classIds, multiValue, ref isMixed);
  301. }
  302. }
  303. void ImportSequenceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection items, CodeIdentifiers classIds, bool multiValue, ref bool isMixed)
  304. {
  305. foreach (XmlSchemaObject item in items)
  306. {
  307. XmlTypeMapMember mapMember;
  308. if (item is XmlSchemaElement)
  309. {
  310. string ns;
  311. XmlSchemaElement elem = (XmlSchemaElement) item;
  312. TypeData typeData = GetElementTypeData (typeQName, elem);
  313. XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
  314. if (elem.MaxOccurs == 1 && !multiValue)
  315. {
  316. XmlTypeMapMemberElement member = null;
  317. if (typeData.SchemaType != SchemaTypes.Array)
  318. {
  319. member = new XmlTypeMapMemberElement ();
  320. if (refElem.DefaultValue != null) member.DefaultValue = XmlCustomFormatter.FromXmlString (typeData, refElem.DefaultValue);
  321. }
  322. else if (GetTypeMapping (typeData).IsSimpleType)
  323. {
  324. // It is a simple list (space separated list).
  325. // Since this is not supported, map as a single item value
  326. // TODO: improve this
  327. member = new XmlTypeMapMemberElement ();
  328. typeData = typeData.ListItemTypeData;
  329. }
  330. else
  331. member = new XmlTypeMapMemberList ();
  332. member.Name = classIds.AddUnique(CodeIdentifier.MakeValid(refElem.Name), member);
  333. member.Documentation = GetDocumentation (elem);
  334. member.TypeData = typeData;
  335. member.ElementInfo.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable));
  336. cmap.AddMember (member);
  337. }
  338. else
  339. {
  340. XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
  341. member.ListMap = new ListMap ();
  342. member.Name = classIds.AddUnique(CodeIdentifier.MakeValid(refElem.Name), member);
  343. member.Documentation = GetDocumentation (elem);
  344. member.TypeData = typeData.ListTypeData;
  345. member.ElementInfo.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable));
  346. member.ListMap.ItemInfo = member.ElementInfo;
  347. cmap.AddMember (member);
  348. }
  349. }
  350. else if (item is XmlSchemaAny)
  351. {
  352. XmlSchemaAny elem = (XmlSchemaAny) item;
  353. XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement ();
  354. member.Name = classIds.AddUnique ("Any", member);
  355. member.Documentation = GetDocumentation (elem);
  356. Type ctype;
  357. if (elem.MaxOccurs > 1 || multiValue)
  358. ctype = isMixed ? typeof(XmlNode[]) : typeof(XmlElement[]);
  359. else
  360. ctype = isMixed ? typeof(XmlNode) : typeof(XmlElement);
  361. member.TypeData = TypeTranslator.GetTypeData (ctype);
  362. XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, member.TypeData);
  363. einfo.IsUnnamedAnyElement = true;
  364. member.ElementInfo.Add (einfo);
  365. if (isMixed)
  366. {
  367. einfo = CreateTextElementInfo (typeQName.Namespace, member, member.TypeData);
  368. member.ElementInfo.Add (einfo);
  369. member.IsXmlTextCollector = true;
  370. isMixed = false; //Allow only one XmlTextAttribute
  371. }
  372. cmap.AddMember (member);
  373. }
  374. else if (item is XmlSchemaParticle) {
  375. ImportParticleContent (typeQName, cmap, (XmlSchemaParticle)item, classIds, multiValue, ref isMixed);
  376. }
  377. }
  378. }
  379. void ImportChoiceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaChoice choice, CodeIdentifiers classIds, bool multiValue)
  380. {
  381. XmlTypeMapElementInfoList choices = new XmlTypeMapElementInfoList ();
  382. multiValue = ImportChoices (typeQName, null, choices, choice.Items) || multiValue;
  383. if (choices.Count == 0) return;
  384. if (choice.MaxOccurs > 1) multiValue = true;
  385. XmlTypeMapMemberElement member;
  386. if (multiValue)
  387. {
  388. member = new XmlTypeMapMemberFlatList ();
  389. member.Name = classIds.AddUnique ("Items", member);
  390. ListMap listMap = new ListMap ();
  391. listMap.ItemInfo = choices;
  392. ((XmlTypeMapMemberFlatList)member).ListMap = listMap;
  393. }
  394. else
  395. {
  396. member = new XmlTypeMapMemberElement ();
  397. member.Name = classIds.AddUnique ("Item", member);
  398. }
  399. // If all choices have the same type, use that type for the member.
  400. // If not use System.Object.
  401. // If there are at least two choices with the same type, use a choice
  402. // identifier attribute
  403. TypeData typeData = null;
  404. bool twoEqual = false;
  405. bool allEqual = true;
  406. Hashtable types = new Hashtable ();
  407. foreach (XmlTypeMapElementInfo einfo in choices)
  408. {
  409. if (types.ContainsKey (einfo.TypeData)) twoEqual = true;
  410. else types.Add (einfo.TypeData, einfo);
  411. TypeData choiceType = einfo.TypeData;
  412. if (choiceType.SchemaType == SchemaTypes.Class)
  413. {
  414. // When comparing class types, use the most generic class in the
  415. // inheritance hierarchy
  416. XmlTypeMapping choiceMap = GetTypeMapping (choiceType);
  417. BuildPendingMap (choiceMap);
  418. while (choiceMap.BaseMap != null) {
  419. choiceMap = choiceMap.BaseMap;
  420. BuildPendingMap (choiceMap);
  421. choiceType = choiceMap.TypeData;
  422. }
  423. }
  424. if (typeData == null) typeData = choiceType;
  425. else if (typeData != choiceType) allEqual = false;
  426. }
  427. if (!allEqual)
  428. typeData = TypeTranslator.GetTypeData (typeof(object));
  429. if (twoEqual)
  430. {
  431. // Create the choice member
  432. XmlTypeMapMemberElement choiceMember = new XmlTypeMapMemberElement ();
  433. choiceMember.Name = classIds.AddUnique (member.Name + "ElementName", choiceMember);
  434. member.ChoiceMember = choiceMember.Name;
  435. // Create the choice enum
  436. XmlTypeMapping enumMap = CreateTypeMapping (new XmlQualifiedName (member.Name + "ChoiceType", typeQName.Namespace), SchemaTypes.Enum, null);
  437. CodeIdentifiers codeIdents = new CodeIdentifiers ();
  438. EnumMap.EnumMapMember[] members = new EnumMap.EnumMapMember [choices.Count];
  439. for (int n=0; n<choices.Count; n++)
  440. {
  441. XmlTypeMapElementInfo it =(XmlTypeMapElementInfo) choices[n];
  442. string xmlName = (it.Namespace != null && it.Namespace != "") ? it.Namespace + ":" + it.ElementName : it.ElementName;
  443. string enumName = codeIdents.AddUnique (CodeIdentifier.MakeValid (it.ElementName), it);
  444. members [n] = new EnumMap.EnumMapMember (xmlName, enumName);
  445. }
  446. enumMap.ObjectMap = new EnumMap (members, false);
  447. choiceMember.TypeData = multiValue ? enumMap.TypeData.ListTypeData : enumMap.TypeData;
  448. choiceMember.ElementInfo.Add (CreateElementInfo (typeQName.Namespace, choiceMember, choiceMember.Name, choiceMember.TypeData, false));
  449. cmap.AddMember (choiceMember);
  450. }
  451. if (multiValue)
  452. typeData = typeData.ListTypeData;
  453. member.ElementInfo = choices;
  454. member.Documentation = GetDocumentation (choice);
  455. member.TypeData = typeData;
  456. cmap.AddMember (member);
  457. }
  458. bool ImportChoices (XmlQualifiedName typeQName, XmlTypeMapMember member, XmlTypeMapElementInfoList choices, XmlSchemaObjectCollection items)
  459. {
  460. bool multiValue = false;
  461. foreach (XmlSchemaObject titem in items)
  462. {
  463. XmlSchemaObject item = titem;
  464. if (item is XmlSchemaGroupRef)
  465. item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
  466. if (item is XmlSchemaElement)
  467. {
  468. string ns;
  469. XmlSchemaElement elem = (XmlSchemaElement) item;
  470. TypeData typeData = GetElementTypeData (typeQName, elem);
  471. XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
  472. choices.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable));
  473. if (elem.MaxOccurs > 1) multiValue = true;
  474. }
  475. else if (item is XmlSchemaAny)
  476. {
  477. XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(typeof(XmlElement)));
  478. einfo.IsUnnamedAnyElement = true;
  479. choices.Add (einfo);
  480. }
  481. else if (item is XmlSchemaChoice) {
  482. multiValue = ImportChoices (typeQName, member, choices, ((XmlSchemaChoice)item).Items) || multiValue;
  483. }
  484. else if (item is XmlSchemaSequence) {
  485. multiValue = ImportChoices (typeQName, member, choices, ((XmlSchemaSequence)item).Items) || multiValue;
  486. }
  487. }
  488. return multiValue;
  489. }
  490. void ImportSimpleContent (XmlQualifiedName typeQName, XmlTypeMapping map, XmlSchemaSimpleContent content, CodeIdentifiers classIds, bool isMixed)
  491. {
  492. ClassMap cmap = (ClassMap)map.ObjectMap;
  493. XmlQualifiedName qname = GetContentBaseType (content.Content);
  494. XmlTypeMapMemberElement member = new XmlTypeMapMemberElement ();
  495. member.Name = classIds.AddUnique("Value", member);
  496. member.TypeData = FindBuiltInType (qname);
  497. member.ElementInfo.Add (CreateTextElementInfo (typeQName.Namespace, member, member.TypeData));
  498. member.IsXmlTextCollector = true;
  499. cmap.AddMember (member);
  500. XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
  501. if (ext != null)
  502. ImportAttributes (typeQName, cmap, ext.Attributes, ext.AnyAttribute, classIds);
  503. }
  504. TypeData FindBuiltInType (XmlQualifiedName qname)
  505. {
  506. if (qname.Namespace == XmlSchema.Namespace)
  507. return TypeTranslator.GetPrimitiveTypeData (qname.Name);
  508. XmlSchemaComplexType ct = (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
  509. if (ct != null)
  510. {
  511. XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
  512. if (sc == null) throw new InvalidOperationException ("Invalid schema");
  513. return FindBuiltInType (GetContentBaseType (sc.Content));
  514. }
  515. XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  516. if (st != null)
  517. return FindBuiltInType (qname, st);
  518. throw new InvalidOperationException ("Definition of type " + qname + " not found");
  519. }
  520. TypeData FindBuiltInType (XmlQualifiedName qname, XmlSchemaSimpleType st)
  521. {
  522. if (CanBeEnum (st))
  523. return ImportType (qname, null).TypeData;
  524. if (st.Content is XmlSchemaSimpleTypeRestriction) {
  525. return FindBuiltInType (GetContentBaseType (st.Content));
  526. }
  527. else if (st.Content is XmlSchemaSimpleTypeList) {
  528. return FindBuiltInType (GetContentBaseType (st.Content)).ListTypeData;
  529. }
  530. else if (st.Content is XmlSchemaSimpleTypeUnion)
  531. {
  532. // Check if all types of the union are equal. If not, then will use anyType.
  533. XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
  534. TypeData utype = null;
  535. // Anonymous types are unique
  536. if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
  537. return FindBuiltInType (anyType);
  538. foreach (XmlQualifiedName mt in uni.MemberTypes)
  539. {
  540. TypeData qn = FindBuiltInType (mt);
  541. if (utype != null && qn != utype) return FindBuiltInType (anyType);
  542. else utype = qn;
  543. }
  544. return utype;
  545. }
  546. else
  547. return null;
  548. }
  549. XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
  550. {
  551. if (ob is XmlSchemaSimpleContentExtension)
  552. return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
  553. else if (ob is XmlSchemaSimpleContentRestriction)
  554. return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
  555. else if (ob is XmlSchemaSimpleTypeRestriction)
  556. return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
  557. else if (ob is XmlSchemaSimpleTypeList)
  558. return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
  559. else
  560. return null;
  561. }
  562. void ImportComplexContent (XmlQualifiedName typeQName, XmlTypeMapping map, XmlSchemaComplexContent content, CodeIdentifiers classIds, bool isMixed)
  563. {
  564. XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
  565. ClassMap cmap = (ClassMap)map.ObjectMap;
  566. XmlQualifiedName qname;
  567. if (ext != null) qname = ext.BaseTypeName;
  568. else qname = ((XmlSchemaComplexContentRestriction)content.Content).BaseTypeName;
  569. // Add base map members to this map
  570. XmlTypeMapping baseMap = ImportType (qname, null);
  571. BuildPendingMap (baseMap);
  572. ClassMap baseClassMap = (ClassMap)baseMap.ObjectMap;
  573. foreach (XmlTypeMapMember member in baseClassMap.AllMembers)
  574. cmap.AddMember (member);
  575. if (baseClassMap.XmlTextCollector != null) isMixed = false;
  576. else if (content.IsMixed) isMixed = true;
  577. map.BaseMap = baseMap;
  578. baseMap.DerivedTypes.Add (map);
  579. if (ext != null) {
  580. // Add the members of this map
  581. ImportParticleComplexContent (typeQName, cmap, ext.Particle, classIds, isMixed);
  582. ImportAttributes (typeQName, cmap, ext.Attributes, ext.AnyAttribute, classIds);
  583. }
  584. else {
  585. if (isMixed) ImportParticleComplexContent (typeQName, cmap, null, classIds, true);
  586. }
  587. }
  588. XmlTypeMapping ImportClassSimpleType (XmlQualifiedName typeQName, XmlSchemaSimpleType stype, XmlQualifiedName root)
  589. {
  590. if (CanBeEnum (stype))
  591. {
  592. // Create an enum map
  593. CodeIdentifiers codeIdents = new CodeIdentifiers ();
  594. XmlSchemaSimpleTypeRestriction rest = (XmlSchemaSimpleTypeRestriction)stype.Content;
  595. XmlTypeMapping enumMap = CreateTypeMapping (typeQName, SchemaTypes.Enum, null);
  596. enumMap.Documentation = GetDocumentation (stype);
  597. codeIdents.AddReserved (enumMap.TypeData.TypeName);
  598. EnumMap.EnumMapMember[] members = new EnumMap.EnumMapMember [rest.Facets.Count];
  599. for (int n=0; n<rest.Facets.Count; n++)
  600. {
  601. XmlSchemaEnumerationFacet enu = (XmlSchemaEnumerationFacet) rest.Facets[n];
  602. string enumName = codeIdents.AddUnique(CodeIdentifier.MakeValid (enu.Value), enu);
  603. members [n] = new EnumMap.EnumMapMember (enu.Value, enumName);
  604. members [n].Documentation = GetDocumentation (enu);
  605. }
  606. enumMap.ObjectMap = new EnumMap (members, false);
  607. enumMap.IsSimpleType = true;
  608. return enumMap;
  609. }
  610. if (stype.Content is XmlSchemaSimpleTypeList)
  611. {
  612. XmlSchemaSimpleTypeList slist = (XmlSchemaSimpleTypeList)stype.Content;
  613. TypeData arrayTypeData = FindBuiltInType (slist.ItemTypeName, stype);
  614. ListMap listMap = new ListMap ();
  615. listMap.ItemInfo = new XmlTypeMapElementInfoList ();
  616. listMap.ItemInfo.Add (CreateElementInfo (typeQName.Namespace, null, "Item", arrayTypeData.ListItemTypeData, false));
  617. XmlTypeMapping map = CreateArrayTypeMapping (typeQName, arrayTypeData);
  618. map.ObjectMap = listMap;
  619. map.IsSimpleType = true;
  620. return map;
  621. }
  622. // It is an extension of a primitive or known type
  623. TypeData typeData = FindBuiltInType (typeQName, stype);
  624. return GetTypeMapping (typeData);
  625. }
  626. bool CanBeEnum (XmlSchemaSimpleType stype)
  627. {
  628. if (stype.Content is XmlSchemaSimpleTypeRestriction)
  629. {
  630. XmlSchemaSimpleTypeRestriction rest = (XmlSchemaSimpleTypeRestriction)stype.Content;
  631. foreach (object ob in rest.Facets)
  632. if (!(ob is XmlSchemaEnumerationFacet)) return false;
  633. return true;
  634. }
  635. return false;
  636. }
  637. bool CanBeArray (XmlQualifiedName typeQName, XmlSchemaComplexType stype)
  638. {
  639. if (stype.Attributes.Count > 0 || stype.AnyAttribute != null) return false;
  640. else return !stype.IsMixed && CanBeArray (typeQName, stype.Particle, false);
  641. }
  642. bool CanBeArray (XmlQualifiedName typeQName, XmlSchemaParticle particle, bool multiValue)
  643. {
  644. // To be an array, there can't be a direct child of type typeQName
  645. if (particle == null) return false;
  646. multiValue = multiValue || particle.MaxOccurs > 1;
  647. if (particle is XmlSchemaGroupRef)
  648. return CanBeArray (typeQName, GetRefGroupParticle ((XmlSchemaGroupRef)particle), multiValue);
  649. if (particle is XmlSchemaElement)
  650. {
  651. XmlSchemaElement elem = (XmlSchemaElement)particle;
  652. if (!elem.RefName.IsEmpty)
  653. return CanBeArray (typeQName, FindRefElement (elem), multiValue);
  654. else
  655. return multiValue && !typeQName.Equals (((XmlSchemaElement)particle).SchemaTypeName);
  656. }
  657. if (particle is XmlSchemaAny)
  658. return multiValue;
  659. if (particle is XmlSchemaSequence)
  660. {
  661. XmlSchemaSequence seq = particle as XmlSchemaSequence;
  662. if (seq.Items.Count != 1) return false;
  663. return CanBeArray (typeQName, (XmlSchemaParticle)seq.Items[0], multiValue);
  664. }
  665. if (particle is XmlSchemaChoice)
  666. {
  667. // Can be array if all choices have different types
  668. ArrayList types = new ArrayList ();
  669. if(!CheckChoiceType (typeQName, particle, types, ref multiValue)) return false;
  670. return multiValue;
  671. }
  672. return false;
  673. }
  674. bool CheckChoiceType (XmlQualifiedName typeQName, XmlSchemaParticle particle, ArrayList types, ref bool multiValue)
  675. {
  676. XmlQualifiedName type = null;
  677. multiValue = multiValue || particle.MaxOccurs > 1;
  678. if (particle is XmlSchemaGroupRef)
  679. return CheckChoiceType (typeQName, GetRefGroupParticle ((XmlSchemaGroupRef)particle), types, ref multiValue);
  680. if (particle is XmlSchemaElement) {
  681. string ns;
  682. XmlSchemaElement elem = (XmlSchemaElement)particle;
  683. XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
  684. if (refElem.SchemaType != null) return true;
  685. type = refElem.SchemaTypeName;
  686. }
  687. else if (particle is XmlSchemaAny) {
  688. type = anyType;
  689. }
  690. else if (particle is XmlSchemaSequence)
  691. {
  692. XmlSchemaSequence seq = particle as XmlSchemaSequence;
  693. foreach (XmlSchemaParticle par in seq.Items)
  694. if (!CheckChoiceType (typeQName, par, types, ref multiValue)) return false;
  695. return true;
  696. }
  697. else if (particle is XmlSchemaChoice)
  698. {
  699. foreach (XmlSchemaParticle choice in ((XmlSchemaChoice)particle).Items)
  700. if (!CheckChoiceType (typeQName, choice, types, ref multiValue)) return false;
  701. return true;
  702. }
  703. if (typeQName.Equals (type)) return false;
  704. // For primitive types, compare using CLR types, since several
  705. // xml types can be mapped to a single CLR type
  706. string t;
  707. if (type.Namespace == XmlSchema.Namespace)
  708. t = TypeTranslator.GetPrimitiveTypeData (type.Name).FullTypeName + ":" + type.Namespace;
  709. else
  710. t = type.Name + ":" + type.Namespace;
  711. if (types.Contains (t)) return false;
  712. types.Add (t);
  713. return true;
  714. }
  715. bool CanBeAnyElement (XmlSchemaComplexType stype)
  716. {
  717. XmlSchemaSequence seq = stype.Particle as XmlSchemaSequence;
  718. return (seq != null) && (seq.Items.Count == 1) && (seq.Items[0] is XmlSchemaAny);
  719. }
  720. bool CanBeIXmlSerializable (XmlSchemaComplexType stype)
  721. {
  722. XmlSchemaSequence seq = stype.Particle as XmlSchemaSequence;
  723. if (seq == null) return false;
  724. if (seq.Items.Count != 2) return false;
  725. XmlSchemaElement elem = seq.Items[0] as XmlSchemaElement;
  726. if (elem == null) return false;
  727. if (elem.RefName != new XmlQualifiedName ("schema",XmlSchema.Namespace)) return false;
  728. return (seq.Items[1] is XmlSchemaAny);
  729. }
  730. XmlTypeMapElementInfo CreateElementInfo (string ns, XmlTypeMapMember member, string name, TypeData typeData, bool isNillable)
  731. {
  732. XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, typeData);
  733. einfo.ElementName = name;
  734. einfo.Namespace = ns;
  735. einfo.IsNullable = isNillable;
  736. if (einfo.TypeData.IsComplexType)
  737. einfo.MappedType = GetTypeMapping (typeData);
  738. return einfo;
  739. }
  740. XmlTypeMapElementInfo CreateTextElementInfo (string ns, XmlTypeMapMember member, TypeData typeData)
  741. {
  742. XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, typeData);
  743. einfo.IsTextElement = true;
  744. einfo.WrappedElement = false;
  745. if (typeData.IsComplexType)
  746. einfo.MappedType = GetTypeMapping (typeData);
  747. return einfo;
  748. }
  749. XmlTypeMapping CreateTypeMapping (XmlQualifiedName typeQName, SchemaTypes schemaType, XmlQualifiedName root)
  750. {
  751. string typeName = CodeIdentifier.MakeValid (typeQName.Name);
  752. typeName = typeIdentifiers.AddUnique (typeName, null);
  753. TypeData typeData = new TypeData (typeName, typeName, typeName, schemaType, null);
  754. XmlQualifiedName elemName = (root != null) ? root : typeQName;
  755. XmlTypeMapping map = new XmlTypeMapping (elemName.Name, elemName.Namespace, typeData, typeQName.Name, typeQName.Namespace);
  756. mappedTypes [typeQName] = map;
  757. dataMappedTypes [typeData] = map;
  758. return map;
  759. }
  760. XmlTypeMapping CreateArrayTypeMapping (XmlQualifiedName typeQName, TypeData arrayTypeData)
  761. {
  762. XmlTypeMapping map = new XmlTypeMapping (arrayTypeData.XmlType, typeQName.Namespace, arrayTypeData, arrayTypeData.XmlType, typeQName.Namespace);
  763. mappedTypes [typeQName] = map;
  764. dataMappedTypes [arrayTypeData] = map;
  765. return map;
  766. }
  767. XmlSchemaElement GetRefElement (XmlQualifiedName typeQName, XmlSchemaElement elem, out string ns)
  768. {
  769. if (!elem.RefName.IsEmpty)
  770. {
  771. ns = elem.RefName.Namespace;
  772. return FindRefElement (elem);
  773. }
  774. else
  775. {
  776. ns = typeQName.Namespace;
  777. return elem;
  778. }
  779. }
  780. XmlSchemaAttribute GetRefAttribute (XmlQualifiedName typeQName, XmlSchemaAttribute attr, out string ns)
  781. {
  782. if (!attr.RefName.IsEmpty)
  783. {
  784. ns = attr.RefName.Namespace;
  785. return (XmlSchemaAttribute) schemas.Find (attr.RefName, typeof(XmlSchemaAttribute));
  786. }
  787. else
  788. {
  789. ns = typeQName.Namespace;
  790. return attr;
  791. }
  792. }
  793. TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem)
  794. {
  795. bool sharedAnnType = false;
  796. XmlQualifiedName root = null;
  797. if (!elem.RefName.IsEmpty) {
  798. XmlSchemaElement refElem = FindRefElement (elem);
  799. if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
  800. root = elem.RefName;
  801. elem = refElem;
  802. sharedAnnType = true;
  803. }
  804. if (!elem.SchemaTypeName.IsEmpty) return GetTypeData (elem.SchemaTypeName, root);
  805. else if (elem.SchemaType == null) return TypeTranslator.GetTypeData (typeof(object));
  806. else return GetTypeData (elem.SchemaType, typeQName, elem.Name, sharedAnnType, root);
  807. }
  808. TypeData GetAttributeTypeData (XmlQualifiedName typeQName, XmlSchemaAttribute attr)
  809. {
  810. bool sharedAnnType = false;
  811. if (!attr.RefName.IsEmpty) {
  812. XmlSchemaAttribute refAtt = (XmlSchemaAttribute)schemas.Find (attr.RefName, typeof (XmlSchemaAttribute));
  813. if (refAtt == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
  814. attr = refAtt;
  815. sharedAnnType = true;
  816. }
  817. if (!attr.SchemaTypeName.IsEmpty) return GetTypeData (attr.SchemaTypeName, null);
  818. else return GetTypeData (attr.SchemaType, typeQName, attr.Name, sharedAnnType, null);
  819. }
  820. TypeData GetTypeData (XmlQualifiedName typeQName, XmlQualifiedName root)
  821. {
  822. if (typeQName.Namespace == XmlSchema.Namespace)
  823. return TypeTranslator.GetPrimitiveTypeData (typeQName.Name);
  824. return ImportType (typeQName, root).TypeData;
  825. }
  826. TypeData GetTypeData (XmlSchemaType stype, XmlQualifiedName typeQNname, string propertyName, bool sharedAnnType, XmlQualifiedName root)
  827. {
  828. string baseName;
  829. if (sharedAnnType)
  830. {
  831. // Anonymous types defined in root elements or attributes can be shared among all elements that
  832. // reference this root element or attribute
  833. TypeData std = sharedAnonymousTypes [stype] as TypeData;
  834. if (std != null) return std;
  835. baseName = propertyName;
  836. }
  837. else
  838. baseName = typeQNname.Name + typeIdentifiers.MakeRightCase (propertyName);
  839. baseName = elemIdentifiers.AddUnique (baseName, stype);
  840. XmlQualifiedName newName;
  841. newName = new XmlQualifiedName (baseName, typeQNname.Namespace);
  842. XmlTypeMapping map = ImportType (newName, stype, root);
  843. if (sharedAnnType) sharedAnonymousTypes [stype] = map.TypeData;
  844. return map.TypeData;
  845. }
  846. XmlTypeMapping GetTypeMapping (TypeData typeData)
  847. {
  848. XmlTypeMapping map = (XmlTypeMapping) dataMappedTypes [typeData];
  849. if (map != null) return map;
  850. if (map == null && typeData.IsListType)
  851. {
  852. // Create an array map for the type
  853. XmlTypeMapping itemMap = GetTypeMapping (typeData.ListItemTypeData);
  854. map = new XmlTypeMapping (typeData.XmlType, itemMap.Namespace, typeData, typeData.XmlType, itemMap.Namespace);
  855. ListMap listMap = new ListMap ();
  856. listMap.ItemInfo = new XmlTypeMapElementInfoList();
  857. listMap.ItemInfo.Add (CreateElementInfo (itemMap.Namespace, null, typeData.ListItemTypeData.XmlType, typeData.ListItemTypeData, false));
  858. map.ObjectMap = listMap;
  859. mappedTypes [new XmlQualifiedName(map.ElementName, map.Namespace)] = map;
  860. dataMappedTypes [typeData] = map;
  861. return map;
  862. }
  863. else if (typeData.SchemaType == SchemaTypes.Primitive || typeData.Type == typeof(object) || typeof(XmlNode).IsAssignableFrom(typeData.Type))
  864. {
  865. map = new XmlTypeMapping (typeData.XmlType, XmlSchema.Namespace, typeData, typeData.XmlType, XmlSchema.Namespace);
  866. dataMappedTypes [typeData] = map;
  867. return map;
  868. }
  869. throw new InvalidOperationException ("Map for type " + typeData.TypeName + " not found");
  870. }
  871. XmlTypeMapping GetRegisteredTypeMapping (XmlQualifiedName typeQName)
  872. {
  873. return (XmlTypeMapping) mappedTypes [typeQName];
  874. }
  875. XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
  876. {
  877. XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
  878. return grp.Particle;
  879. }
  880. XmlSchemaElement FindRefElement (XmlSchemaElement elem)
  881. {
  882. if (elem.RefName.Namespace == XmlSchema.Namespace)
  883. {
  884. if (anyElement != null) return anyElement;
  885. anyElement = new XmlSchemaElement ();
  886. anyElement.Name = "any";
  887. anyElement.SchemaTypeName = anyType;
  888. return anyElement;
  889. }
  890. return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  891. }
  892. string GetDocumentation (XmlSchemaAnnotated elem)
  893. {
  894. string res = "";
  895. XmlSchemaAnnotation anot = elem.Annotation;
  896. if (anot == null || anot.Items == null) return null;
  897. foreach (object ob in anot.Items)
  898. {
  899. XmlSchemaDocumentation doc = ob as XmlSchemaDocumentation;
  900. if (doc != null && doc.Markup != null && doc.Markup.Length > 0) {
  901. if (res != string.Empty) res += "\n";
  902. foreach (XmlNode node in doc.Markup)
  903. res += node.Value;
  904. }
  905. }
  906. return res;
  907. }
  908. #endregion // Methods
  909. }
  910. }