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;
default:
return;
}
if (!flag)
{
this._xmlw.WriteEndElement();
}
}
}