当前位置: 首页>>代码示例>>C#>>正文


C# DataColumn.IsValueCustomTypeInstance方法代码示例

本文整理汇总了C#中System.Data.DataColumn.IsValueCustomTypeInstance方法的典型用法代码示例。如果您正苦于以下问题:C# DataColumn.IsValueCustomTypeInstance方法的具体用法?C# DataColumn.IsValueCustomTypeInstance怎么用?C# DataColumn.IsValueCustomTypeInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.DataColumn的用法示例。


在下文中一共展示了DataColumn.IsValueCustomTypeInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateColumn

        private void GenerateColumn(DataRow row, DataColumn col, DataRowVersion version)
        {
            string columnValueAsString = null;
            columnValueAsString = col.GetColumnValueAsString(row, version);
            if (columnValueAsString == null)
            {
                if (col.ColumnMapping == MappingType.SimpleContent)
                {
                    this._xmlw.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
                }
            }
            else
            {
                bool flag;
                string prefix = (col.Namespace.Length != 0) ? col.Prefix : string.Empty;
                switch (col.ColumnMapping)
                {
                    case MappingType.Element:
                    {
                        flag = true;
                        object obj2 = row[col, version];
                        if ((!col.IsCustomType || !col.IsValueCustomTypeInstance(obj2)) || typeof(IXmlSerializable).IsAssignableFrom(obj2.GetType()))
                        {
                            this._xmlw.WriteStartElement(prefix, col.EncodedColumnName, col.Namespace);
                            flag = false;
                        }
                        Type type = obj2.GetType();
                        if (col.IsCustomType)
                        {
                            if ((obj2 != DBNull.Value) && (!col.ImplementsINullable || !DataStorage.IsObjectSqlNull(obj2)))
                            {
                                if (col.IsValueCustomTypeInstance(obj2))
                                {
                                    if (!flag && (obj2.GetType() != col.DataType))
                                    {
                                        this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", DataStorage.GetQualifiedName(type));
                                    }
                                    if (!flag)
                                    {
                                        col.ConvertObjectToXml(obj2, this._xmlw, null);
                                    }
                                    else
                                    {
                                        if (obj2.GetType() != col.DataType)
                                        {
                                            throw ExceptionBuilder.PolymorphismNotSupported(type.AssemblyQualifiedName);
                                        }
                                        XmlRootAttribute xmlAttrib = new XmlRootAttribute(col.EncodedColumnName) {
                                            Namespace = col.Namespace
                                        };
                                        col.ConvertObjectToXml(obj2, this._xmlw, xmlAttrib);
                                    }
                                }
                                else
                                {
                                    if (((type == typeof(Type)) || (type == typeof(Guid))) || ((type == typeof(char)) || DataStorage.IsSqlType(type)))
                                    {
                                        this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", type.FullName);
                                    }
                                    else if (obj2 is Type)
                                    {
                                        this._xmlw.WriteAttributeString("msdata", "InstanceType", "urn:schemas-microsoft-com:xml-msdata", "Type");
                                    }
                                    else
                                    {
                                        string str3 = "xs:" + XmlTreeGen.XmlDataTypeName(type);
                                        this._xmlw.WriteAttributeString("xsi", "type", "http://www.w3.org/2001/XMLSchema-instance", str3);
                                        this._xmlw.WriteAttributeString("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
                                    }
                                    if (!DataStorage.IsSqlType(type))
                                    {
                                        this._xmlw.WriteString(col.ConvertObjectToXml(obj2));
                                    }
                                    else
                                    {
                                        col.ConvertObjectToXml(obj2, this._xmlw, null);
                                    }
                                }
                            }
                            break;
                        }
                        if (((type == typeof(char)) || (type == typeof(string))) && XmlDataTreeWriter.PreserveSpace(columnValueAsString))
                        {
                            this._xmlw.WriteAttributeString("xml", "space", "http://www.w3.org/XML/1998/namespace", "preserve");
                        }
                        this._xmlw.WriteString(columnValueAsString);
                        break;
                    }
                    case MappingType.Attribute:
                        this._xmlw.WriteAttributeString(prefix, col.EncodedColumnName, col.Namespace, columnValueAsString);
                        return;

                    case MappingType.SimpleContent:
                        this._xmlw.WriteString(columnValueAsString);
                        return;

                    case MappingType.Hidden:
                        this._xmlw.WriteAttributeString("msdata", "hidden" + col.EncodedColumnName, "urn:schemas-microsoft-com:xml-msdata", columnValueAsString);
                        return;

//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:NewDiffgramGen.cs

示例2: GenerateColumn

        private void GenerateColumn(DataRow row, DataColumn col, DataRowVersion version) {
            string value = null;

            value = col.GetColumnValueAsString(row, version); // this is useless for CTD
            if (value == null) {
                if (col.ColumnMapping == MappingType.SimpleContent)
                    _xmlw.WriteAttributeString(Keywords.XSI, Keywords.XSI_NIL, Keywords.XSINS, Keywords.TRUE);
                return;
            }

            string colPrefix = (col.Namespace.Length != 0) ? col.Prefix : String.Empty;
            switch (col.ColumnMapping) {

                case MappingType.Attribute:
                    _xmlw.WriteAttributeString(colPrefix, col.EncodedColumnName, col.Namespace, value);
                    break;

                case MappingType.Hidden:
                    _xmlw.WriteAttributeString(Keywords.MSD, "hidden"+col.EncodedColumnName, Keywords.MSDNS, value);
                    break;

                case MappingType.SimpleContent:
                    _xmlw.WriteString(value);
                    break;

                case MappingType.Element:
                    bool startElementSkipped = true;
                    object columnValue = row[col, version];
                    // if the object is built in type or if it implements IXMLSerializable, write the start Element, otherwise
                    //(if CDT and does not implement IXmlSerializable) skip it
                    if (!col.IsCustomType || !col.IsValueCustomTypeInstance(columnValue) ||(typeof(IXmlSerializable).IsAssignableFrom(columnValue.GetType()))) {
                        _xmlw.WriteStartElement( colPrefix, col.EncodedColumnName, col.Namespace);
                        startElementSkipped = false;
                    }
                    Type valuesType = columnValue.GetType();
                    if (!col.IsCustomType ) { // if column's type is built in type CLR or SQLType
                        if(valuesType == typeof(char) || valuesType == typeof(string)) {
                            if (XmlDataTreeWriter.PreserveSpace(value)) {
                                _xmlw.WriteAttributeString(Keywords.XML, Keywords.SPACE, Keywords.XML_XMLNS, Keywords.PRESERVE);
                            }
                        }
                        _xmlw.WriteString(value);
                    }
                    else { // Columns type is CDT
                        if  ((columnValue != DBNull.Value) && (!col.ImplementsINullable || !DataStorage.IsObjectSqlNull(columnValue))){
                            if (col.IsValueCustomTypeInstance(columnValue)/* && valuesType != typeof(Type)*/) {// value is also CDT
                                // if SkippedElement, ie does not implement IXMLSerializable: so No Polymorphysm Support.
                                if (!startElementSkipped && columnValue.GetType() != col.DataType) {
                                    _xmlw.WriteAttributeString(Keywords.MSD, Keywords.MSD_INSTANCETYPE, Keywords.MSDNS, DataStorage.GetQualifiedName(valuesType));
                                }
                                if (!startElementSkipped) {
                                    col.ConvertObjectToXml(columnValue, _xmlw, null); // XmlRootAttribute MUST be passed null
                                }
                                else{
                                    // this guy does not implement IXmlSerializable, so we need to handle serialization via XmlSerializer
                                    if (columnValue.GetType() != col.DataType) { // throw if polymorphism; not supported
                                        throw ExceptionBuilder.PolymorphismNotSupported(valuesType.AssemblyQualifiedName);
                                    }
                                    // therefore we are skipping the start element, but by passing XmlRootAttribute with the same name as
                                    // we open the start element (column's name), XmlSerializer will open and close it for us
                                    XmlRootAttribute xmlAttrib = new XmlRootAttribute(col.EncodedColumnName);
                                    xmlAttrib.Namespace = col.Namespace;
                                    col.ConvertObjectToXml(columnValue, _xmlw, xmlAttrib);
                                }
                            }
                            else { // value is built in CLR type (eg: string, int etc.)
                             // these basic clr types do not have direct xsd type mappings
                                if (valuesType == typeof(Type) || valuesType == typeof(Guid)|| valuesType == typeof(Char) ||
                                    DataStorage.IsSqlType(valuesType) ) { // if unmapped type or SQL type write msdata:Datatype=typeofinstance
                                        _xmlw.WriteAttributeString(Keywords.MSD, Keywords.MSD_INSTANCETYPE, Keywords.MSDNS, valuesType.FullName);
                                }
                                else if (columnValue is Type) {
                                    _xmlw.WriteAttributeString(Keywords.MSD, Keywords.MSD_INSTANCETYPE, Keywords.MSDNS, Keywords.TYPEINSTANCE);
                                }
                                else {
                                    string xsdTypeName = Keywords.XSD_PREFIXCOLON+ XmlTreeGen.XmlDataTypeName(valuesType);
                                    _xmlw.WriteAttributeString(Keywords.XSI, Keywords.TYPE, Keywords.XSINS, xsdTypeName);
                                    _xmlw.WriteAttributeString (Keywords.XMLNS_XSD, Keywords.XSDNS);                                    
                                }
                                if (!DataStorage.IsSqlType(valuesType)) {
                                    _xmlw.WriteString(col.ConvertObjectToXml(columnValue));
                                }
                                else {
                                    col.ConvertObjectToXml(columnValue, _xmlw, null);
                                }
                            }
                        }
                    }

                    if (!startElementSkipped) {
                        _xmlw.WriteEndElement();
                    }
                    break;
                }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:95,代码来源:xmlsaver.cs


注:本文中的System.Data.DataColumn.IsValueCustomTypeInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。