System.Data.XSDSchema.InstantiateSimpleTable C# (CSharp) Method

InstantiateSimpleTable() private method

private InstantiateSimpleTable ( XmlSchemaElement node ) : DataTable
node System.Xml.Schema.XmlSchemaElement
return DataTable
        internal DataTable InstantiateSimpleTable(XmlSchemaElement node)
        {
            DataTable table;
            string typeName = XmlConvert.DecodeName(GetInstanceName(node));
            string _TableUri;

            _TableUri = node.QualifiedName.Namespace;
            table = _ds.Tables.GetTable(typeName, _TableUri);

            if (!FromInference && table != null)
            {
                throw ExceptionBuilder.DuplicateDeclaration(typeName);
            }

            if (table == null)
            {
                table = new DataTable(typeName);
                table.Namespace = _TableUri;
                // If msdata:targetNamespace node on element, then use it to override table.Namespace.
                table.Namespace = GetStringAttribute(node, "targetNamespace", _TableUri);

                if (!FromInference)
                {
                    table.MinOccurs = node.MinOccurs;
                    table.MaxOccurs = node.MaxOccurs;
                }
                else
                {
                    string prefix = GetPrefix(_TableUri);
                    if (prefix != null)
                        table.Prefix = prefix;
                }

                SetProperties(table, node.UnhandledAttributes);
                SetExtProperties(table, node.UnhandledAttributes);
            }


            XmlSchemaComplexType ct = node.SchemaType as XmlSchemaComplexType;
            // We assume node.ElementSchemaType.BaseSchemaType to be null for 
            //  <xs:element name="foo"/> and not null for <xs:element name="foo" type="xs:string"/>
            bool isSimpleContent = ((node.ElementSchemaType.BaseXmlSchemaType != null) || (ct != null && ct.ContentModel is XmlSchemaSimpleContent));

            if (!FromInference || (isSimpleContent && table.Columns.Count == 0))
            {// for inference backward compatability
                HandleElementColumn(node, table, false);
                string colName;

                if (FromInference)
                {
                    int i = 0;
                    colName = typeName + "_Text";
                    while (table.Columns[colName] != null)
                        colName = colName + i++;
                }
                else
                {
                    colName = typeName + "_Column";
                }

                table.Columns[0].ColumnName = colName;
                table.Columns[0].ColumnMapping = MappingType.SimpleContent;
            }

            if (!FromInference || _ds.Tables.GetTable(typeName, _TableUri) == null)
            { // for inference; special case: add table if doesnot exists in collection
                _ds.Tables.Add(table);
                if (FromInference)
                {
                    _tableDictionary.Add(table, new List<DataTable>());
                }
            }

            // handle all the unique and key constraints related to this table

            if ((_dsElement != null) && (_dsElement.Constraints != null))
            {
                foreach (XmlSchemaIdentityConstraint key in _dsElement.Constraints)
                {
                    if (key is XmlSchemaKeyref)
                        continue;
                    if (GetTableName(key) == table.TableName)
                        HandleConstraint(key);
                }
            }
            table._fNestedInDataset = false;

            return (table);
        }