SetProperties() static private method

static private SetProperties ( object instance, XmlAttributeCollection attrs ) : void
instance object
attrs System.Xml.XmlAttributeCollection
return void
        internal DataTable InstantiateSimpleTable(DataSet dataSet, XmlElement node)
        {
            XmlAttributeCollection attrs = node.Attributes;
            int    minOccurs             = 1;
            int    maxOccurs             = 1;
            string instanceName          = this.GetInstanceName(node);

            if (dataSet.Tables.GetTable(instanceName, this._schemaUri) != null)
            {
                throw ExceptionBuilder.DuplicateDeclaration(instanceName);
            }
            string    tableName = XmlConvert.DecodeName(instanceName);
            DataTable instance  = new DataTable(tableName)
            {
                Namespace = this._schemaUri
            };

            this.GetMinMax(node, ref minOccurs, ref maxOccurs);
            instance.MinOccurs = minOccurs;
            instance.MaxOccurs = maxOccurs;
            XMLSchema.SetProperties(instance, attrs);
            instance.repeatableElement = true;
            this.HandleColumn(node, instance);
            instance.Columns[0].ColumnName = tableName + "_Column";
            this._ds.Tables.Add(instance);
            return(instance);
        }
        internal DataTable InstantiateTable(DataSet dataSet, XmlElement node, XmlElement typeNode)
        {
            DataTable table;
            string    name = "";
            XmlAttributeCollection attrs = node.Attributes;
            int       minOccurs          = 1;
            int       maxOccurs          = 1;
            string    str2          = null;
            ArrayList tableChildren = new ArrayList();

            if (attrs.Count > 0)
            {
                name  = this.GetInstanceName(node);
                table = dataSet.Tables.GetTable(name, this._schemaUri);
                if (table != null)
                {
                    return(table);
                }
            }
            table = new DataTable(XmlConvert.DecodeName(name))
            {
                Namespace = this._schemaUri
            };
            this.GetMinMax(node, ref minOccurs, ref maxOccurs);
            table.MinOccurs = minOccurs;
            table.MaxOccurs = maxOccurs;
            this._ds.Tables.Add(table);
            this.HandleTypeNode(typeNode, table, tableChildren);
            XMLSchema.SetProperties(table, attrs);
            if (str2 != null)
            {
                string[]     strArray    = str2.TrimEnd(null).Split(null);
                int          length      = strArray.Length;
                DataColumn[] columnArray = new DataColumn[length];
                for (int i = 0; i < length; i++)
                {
                    DataColumn column2 = table.Columns[strArray[i], this._schemaUri];
                    if (column2 == null)
                    {
                        throw ExceptionBuilder.ElementTypeNotFound(strArray[i]);
                    }
                    columnArray[i] = column2;
                }
                table.PrimaryKey = columnArray;
            }
            foreach (DataTable table2 in tableChildren)
            {
                DataRelation           relation       = null;
                DataRelationCollection childRelations = table.ChildRelations;
                for (int j = 0; j < childRelations.Count; j++)
                {
                    if (childRelations[j].Nested && (table2 == childRelations[j].ChildTable))
                    {
                        relation = childRelations[j];
                    }
                }
                if (relation == null)
                {
                    DataColumn parentKey   = table.AddUniqueKey();
                    DataColumn childColumn = table2.AddForeignKey(parentKey);
                    relation = new DataRelation(table.TableName + "_" + table2.TableName, parentKey, childColumn, true)
                    {
                        CheckMultipleNested = false,
                        Nested = true
                    };
                    table2.DataSet.Relations.Add(relation);
                    relation.CheckMultipleNested = true;
                }
            }
            return(table);
        }
        internal void HandleColumn(XmlElement node, DataTable table)
        {
            DataColumn column;
            Type       type;
            string     str3;
            string     str4;
            int        minOccurs = 0;
            int        maxOccurs = 1;

            node.GetAttribute("use");
            if (node.Attributes.Count > 0)
            {
                string str7 = node.GetAttribute("ref");
                if ((str7 != null) && (str7.Length > 0))
                {
                    return;
                }
                str3   = str4 = this.GetInstanceName(node);
                column = table.Columns[str4, this._schemaUri];
                if (column != null)
                {
                    if (column.ColumnMapping == MappingType.Attribute)
                    {
                        if (XMLSchema.FEqualIdentity(node, "attribute", "urn:schemas-microsoft-com:xml-data"))
                        {
                            throw ExceptionBuilder.DuplicateDeclaration(str3);
                        }
                    }
                    else if (XMLSchema.FEqualIdentity(node, "element", "urn:schemas-microsoft-com:xml-data"))
                    {
                        throw ExceptionBuilder.DuplicateDeclaration(str3);
                    }
                    str4 = XMLSchema.GenUniqueColumnName(str3, table);
                }
            }
            else
            {
                str3 = str4 = "";
            }
            XmlElement element = this.FindTypeNode(node);
            SimpleType type2   = null;

            if (element == null)
            {
                throw ExceptionBuilder.UndefinedDatatype(node.GetAttribute("type"));
            }
            string attribute = element.GetAttribute("type", "urn:schemas-microsoft-com:datatypes");
            string dtValues  = element.GetAttribute("values", "urn:schemas-microsoft-com:datatypes");

            if ((attribute == null) || (attribute.Length == 0))
            {
                attribute = "";
                type      = typeof(string);
            }
            else
            {
                type = this.ParseDataType(attribute, dtValues);
                if (attribute == "float")
                {
                    attribute = "";
                }
                if (attribute == "char")
                {
                    attribute = "";
                    type2     = SimpleType.CreateSimpleType(type);
                }
                if (attribute == "enumeration")
                {
                    attribute = "";
                    type2     = SimpleType.CreateEnumeratedType(dtValues);
                }
                if (attribute == "bin.base64")
                {
                    attribute = "";
                    type2     = SimpleType.CreateByteArrayType("base64");
                }
                if (attribute == "bin.hex")
                {
                    attribute = "";
                    type2     = SimpleType.CreateByteArrayType("hex");
                }
            }
            bool isAttribute = XMLSchema.FEqualIdentity(node, "attribute", "urn:schemas-microsoft-com:xml-data");

            this.GetMinMax(node, isAttribute, ref minOccurs, ref maxOccurs);
            string str2 = null;

            str2 = node.GetAttribute("default");
            bool flag2 = false;

            column = new DataColumn(XmlConvert.DecodeName(str4), type, null, isAttribute ? MappingType.Attribute : MappingType.Element);
            XMLSchema.SetProperties(column, node.Attributes);
            column.XmlDataType = attribute;
            column.SimpleType  = type2;
            column.AllowDBNull = (minOccurs == 0) || flag2;
            column.Namespace   = isAttribute ? string.Empty : this._schemaUri;
            if (node.Attributes != null)
            {
                for (int i = 0; i < node.Attributes.Count; i++)
                {
                    if ((node.Attributes[i].NamespaceURI == "urn:schemas-microsoft-com:xml-msdata") && (node.Attributes[i].LocalName == "Expression"))
                    {
                        column.Expression = node.Attributes[i].Value;
                        break;
                    }
                }
            }
            string str5 = node.GetAttribute("targetNamespace");

            if ((str5 != null) && (str5.Length > 0))
            {
                column.Namespace = str5;
            }
            table.Columns.Add(column);
            if ((str2 != null) && (str2.Length != 0))
            {
                try
                {
                    column.DefaultValue = SqlConvert.ChangeTypeForXML(str2, type);
                }
                catch (FormatException)
                {
                    throw ExceptionBuilder.CannotConvert(str2, type.FullName);
                }
            }
            for (XmlNode node2 = node.FirstChild; node2 != null; node2 = node2.NextSibling)
            {
                if (XMLSchema.FEqualIdentity(node2, "description", "urn:schemas-microsoft-com:xml-data"))
                {
                    column.Description(((XmlElement)node2).InnerText);
                }
            }
        }