CreateSimpleType() static private method

static private CreateSimpleType ( StorageType typeCode, Type type ) : SimpleType
typeCode StorageType
type System.Type
return SimpleType
示例#1
0
        internal void HandleColumn(XmlElement node, DataTable table)
        {
            Debug.Assert(FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS) ||
                         FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS), "Illegal node type");

            string     instanceName;
            string     strName;
            Type       type;
            string     strType;
            string     strValues;
            int        minOccurs = 0;
            int        maxOccurs = 1;
            string     strDefault;
            DataColumn column;

            string strUse = node.GetAttribute(Keywords.USE);



            // Get the name
            if (node.Attributes.Count > 0)
            {
                string strRef = node.GetAttribute(Keywords.REF);

                if (strRef != null && strRef.Length > 0)
                {
                    return; //skip ref nodes. B2 item
                }
                strName = instanceName = GetInstanceName(node);
                column  = table.Columns[instanceName, _schemaUri];
                if (column != null)
                {
                    if (column.ColumnMapping == MappingType.Attribute)
                    {
                        if (FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS))
                        {
                            throw ExceptionBuilder.DuplicateDeclaration(strName);
                        }
                    }
                    else
                    {
                        if (FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS))
                        {
                            throw ExceptionBuilder.DuplicateDeclaration(strName);
                        }
                    }
                    instanceName = GenUniqueColumnName(strName, table);
                }
            }
            else
            {
                strName = instanceName = "";
            }

            // Now get the type
            XmlElement typeNode = FindTypeNode(node);

            SimpleType xsdType = null;

            if (typeNode == null)
            {
                strType = node.GetAttribute(Keywords.TYPE);
                throw ExceptionBuilder.UndefinedDatatype(strType);
            }

            strType   = typeNode.GetAttribute(Keywords.DT_TYPE, Keywords.DTNS);
            strValues = typeNode.GetAttribute(Keywords.DT_VALUES, Keywords.DTNS);
            if (strType == null || strType.Length == 0)
            {
                strType = "";
                type    = typeof(string);
            }
            else
            {
                type = ParseDataType(strType, strValues);
                // HACK: temp work around special types
                if (strType == "float")
                {
                    strType = "";
                }

                if (strType == "char")
                {
                    strType = "";
                    xsdType = SimpleType.CreateSimpleType(StorageType.Char, type);
                }


                if (strType == "enumeration")
                {
                    strType = "";
                    xsdType = SimpleType.CreateEnumeratedType(strValues);
                }

                if (strType == "bin.base64")
                {
                    strType = "";
                    xsdType = SimpleType.CreateByteArrayType("base64");
                }

                if (strType == "bin.hex")
                {
                    strType = "";
                    xsdType = SimpleType.CreateByteArrayType("hex");
                }
            }

            bool isAttribute = FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS);

            GetMinMax(node, isAttribute, ref minOccurs, ref maxOccurs);

            strDefault = null;

            // Does XDR has default?
            strDefault = node.GetAttribute(Keywords.DEFAULT);


            bool bNullable = false;

            column = new DataColumn(XmlConvert.DecodeName(instanceName), type, null,
                                    isAttribute ? MappingType.Attribute : MappingType.Element);

            SetProperties(column, node.Attributes); // xmlschema.SetProperties will skipp setting expressions
            column.XmlDataType = strType;
            column.SimpleType  = xsdType;
            column.AllowDBNull = (minOccurs == 0) || bNullable;
            column.Namespace   = (isAttribute) ? String.Empty : _schemaUri;
// webdata 97925
// We will skip handling expression columns in SetProperties, so we need set the expressions here
            if (node.Attributes != null)
            {
                for (int i = 0; i < node.Attributes.Count; i++)
                {
                    if (node.Attributes[i].NamespaceURI == Keywords.MSDNS)
                    {
                        if (node.Attributes[i].LocalName == "Expression")
                        {
                            column.Expression = node.Attributes[i].Value;
                            break;
                        }
                    }
                }
            }

            String targetNamespace = node.GetAttribute(Keywords.TARGETNAMESPACE);

            if (targetNamespace != null && targetNamespace.Length > 0)
            {
                column.Namespace = targetNamespace;
            }

            table.Columns.Add(column);
            if (strDefault != null && strDefault.Length != 0)
            {
                try {
                    column.DefaultValue = SqlConvert.ChangeTypeForXML(strDefault, type);
                }
                catch (System.FormatException) {
                    throw ExceptionBuilder.CannotConvert(strDefault, type.FullName);
                }
            }
        }
        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);
                }
            }
        }