示例#1
0
 private void UpdateAttributeValueType(XmlToClrImporter.ClrTypeDescription type, string name, string value)
 {
     XmlToClrImporter.ClrPropertyDescription propertyDescription = type[name];
     XmlToClrImporter.ClrTypeDescription     existingType        = (XmlToClrImporter.ClrTypeDescription)null;
     if (propertyDescription != null)
     {
         propertyDescription.CountOccurence();
         existingType = propertyDescription.PropertyType;
     }
     if (existingType == this.stringTypeDescription)
     {
         return;
     }
     XmlToClrImporter.ClrTypeDescription newType = XmlToClrImporter.ClrTypeDescription.EmptyAttribute;
     if (!string.IsNullOrEmpty(value))
     {
         newType = this.GetOrCreateLeafDescription(this.xmlToClrAdapter.InferValueType(value));
     }
     XmlToClrImporter.ClrTypeDescription description = this.ReconcilePropertyType(existingType, newType);
     if (propertyDescription == null)
     {
         type.AddProperty(name, description);
     }
     else
     {
         propertyDescription.PropertyType = description;
     }
 }
示例#2
0
 private void ParseType(XmlToClrImporter.ClrTypeDescription description, XmlToClrImporter.FilteredElement element)
 {
     description.ResetPropertyOccurenceCounts();
     if (element.HasAttributes)
     {
         foreach (XmlAttribute xmlAttribute in element.Attributes)
         {
             string clrName = this.xmlToClrAdapter.GetClrName(xmlAttribute.LocalName, xmlAttribute.Prefix, xmlAttribute.NamespaceURI);
             this.UpdateAttributeValueType(description, clrName, xmlAttribute.Value);
         }
     }
     if (!element.HasChildElements)
     {
         return;
     }
     foreach (XmlElement element1 in element.ChildElements)
     {
         XmlToClrImporter.FilteredElement        element2            = new XmlToClrImporter.FilteredElement(element1, this.xmlToClrAdapter);
         XmlToClrImporter.ClrPropertyDescription propertyDescription = description[element2.Name];
         XmlToClrImporter.ClrTypeDescription     existingType        = (XmlToClrImporter.ClrTypeDescription)null;
         if (propertyDescription != null)
         {
             propertyDescription.CountOccurence();
             existingType = propertyDescription.PropertyType;
         }
         XmlToClrImporter.ClrTypeDescription clrTypeDescription;
         if (element2.IsLeaf)
         {
             if (existingType != this.stringTypeDescription)
             {
                 string leafValue = element2.LeafValue;
                 if (!string.IsNullOrEmpty(leafValue))
                 {
                     clrTypeDescription = this.GetOrCreateLeafDescription(this.xmlToClrAdapter.InferValueType(leafValue));
                 }
                 else if (existingType == null)
                 {
                     clrTypeDescription = this.GetOrCreateEmptyDescription(element2.Name);
                 }
                 else
                 {
                     continue;
                 }
             }
             else
             {
                 continue;
             }
         }
         else
         {
             clrTypeDescription = this.GetOrCreateCompositeDescription(element2.Name);
             this.ParseType(clrTypeDescription, element2);
         }
         if (propertyDescription == null)
         {
             propertyDescription = description[element2.Name];
             if (propertyDescription != null)
             {
                 existingType = propertyDescription.PropertyType;
             }
         }
         XmlToClrImporter.ClrTypeDescription description1 = this.ReconcilePropertyType(existingType, clrTypeDescription);
         if (propertyDescription == null)
         {
             description.AddProperty(element2.Name, description1);
         }
         else
         {
             propertyDescription.PropertyType = description1;
         }
     }
 }