Esempio n. 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;
     }
 }
Esempio n. 2
0
        private IType GetOrCreateCollectionType(XmlToClrImporter.ClrTypeDescription description, string collectionTypeBaseName)
        {
            string collectionTypeName = collectionTypeBaseName + this.xmlToClrAdapter.CollectionSuffix;

            if (this.compositeTypes.Find((Predicate <XmlToClrImporter.ClrTypeDescription>)(t => collectionTypeName == t.Name)) != null)
            {
                throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.XmlTwoNodesUsageNotSupported, new object[2]
                {
                    (object)collectionTypeBaseName,
                    (object)collectionTypeName
                }));
            }
            IType type = this.collectionTypes.Find((Predicate <IType>)(t => collectionTypeName == t.Name));

            if (type != null)
            {
                return(type);
            }
            IType itemType;

            if (description.IsCollectionWrapper)
            {
                XmlToClrImporter.ClrPropertyDescription property = description.Properties[0];
                itemType = property.PropertyType != description?this.GetPropertyType(property) : description.Type;
            }
            else
            {
                itemType = description.Type;
            }
            if (itemType == this.rootType)
            {
                throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.XmlRecursiveRootTypeNotSupported, new object[1]
                {
                    (object)this.rootType.Name
                }));
            }
            IType collectionType = this.xmlToClrAdapter.CreateCollectionType(collectionTypeName, itemType);

            this.collectionTypes.Add(collectionType);
            return(collectionType);
        }
Esempio n. 3
0
 private void NormalizeTypeDescriptions()
 {
     this.rootType.ShouldDelete = false;
     foreach (XmlToClrImporter.ClrTypeDescription clrTypeDescription in this.compositeTypes)
     {
         if (clrTypeDescription.Category == XmlToClrImporter.ClrTypeCategory.Empty)
         {
             clrTypeDescription.ConvertEmptyToComposite();
         }
         else
         {
             foreach (XmlToClrImporter.ClrPropertyDescription propertyDescription1 in clrTypeDescription.Properties)
             {
                 if (propertyDescription1.PropertyType == XmlToClrImporter.ClrTypeDescription.EmptyAttribute)
                 {
                     propertyDescription1.PropertyType = this.stringTypeDescription;
                 }
                 else if (propertyDescription1.PropertyType.IsCollectionWrapper)
                 {
                     XmlToClrImporter.ClrPropertyDescription propertyDescription2 = propertyDescription1.PropertyType.Properties[0];
                     propertyDescription1.PropertyType.ShouldDelete = propertyDescription1.PropertyType != propertyDescription2.PropertyType;
                     if (!propertyDescription1.IsCollection)
                     {
                         propertyDescription1.PropertyType           = propertyDescription2.PropertyType;
                         propertyDescription1.IsCollection           = true;
                         propertyDescription1.IsExplicitCollection   = true;
                         propertyDescription1.CollectionTypeBaseName = propertyDescription2.CollectionTypeBaseName;
                     }
                 }
                 else
                 {
                     propertyDescription1.PropertyType.ShouldDelete = false;
                 }
             }
         }
     }
     this.compositeTypes.RemoveAll((Predicate <XmlToClrImporter.ClrTypeDescription>)(t => t.ShouldDelete));
 }
Esempio n. 4
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;
         }
     }
 }
Esempio n. 5
0
 public XmlToClrImporter.ClrPropertyDescription AddProperty(string name, XmlToClrImporter.ClrTypeDescription description)
 {
     XmlToClrImporter.ClrPropertyDescription propertyDescription = new XmlToClrImporter.ClrPropertyDescription(name, description);
     this.Properties.Add(propertyDescription);
     return(propertyDescription);
 }
Esempio n. 6
0
 private IType GetPropertyType(XmlToClrImporter.ClrPropertyDescription property)
 {
     return(property.IsCollection ? this.GetOrCreateCollectionType(property.PropertyType, property.CollectionTypeBaseName) : property.PropertyType.Type);
 }