internal void AddXdoProperty(PropertyDescriptor pd, object instance, XmlElement root, XmlDocument xd)
{
Type type = pd.PropertyType;
bool bisDataColumn = false;
DataColumn col = null; // it may cause problem to assign null here, I will need to change this.
bool bIsSqlType = false;
bool bImplementsInullable = false;
if (instance is DataColumn)
{
col = (DataColumn)instance;
bisDataColumn = true;
bIsSqlType = col.IsSqlType;
bImplementsInullable = col.ImplementsINullable;
}
if (bImplementsInullable == false &&
type != typeof(string) && // DO NOT REMOVE THIS CHECK
type != typeof(bool) &&
type != typeof(Type) &&
type != typeof(object) &&
type != typeof(CultureInfo) &&
type != typeof(long) &&
type != typeof(int))
{
return;
}
if ((!pd.ShouldSerializeValue(instance) || !pd.Attributes.Contains(DesignerSerializationVisibilityAttribute.Visible)) && (bIsSqlType == false))
{
return;
}
object propInst = pd.GetValue(instance);
if (propInst is InternalDataCollectionBase)
return;
if (propInst is PropertyCollection)
{
return;
}
// SDUB: perf: Why not have this as a table?
// there are several xdo properties that equal to some xml attributes, we should not explicitly ouput them.
if (
string.Equals(pd.Name, "Namespace", StringComparison.Ordinal) ||
string.Equals(pd.Name, "PrimaryKey", StringComparison.Ordinal) ||
string.Equals(pd.Name, "ColumnName", StringComparison.Ordinal) ||
string.Equals(pd.Name, "DefaultValue", StringComparison.Ordinal) ||
string.Equals(pd.Name, "TableName", StringComparison.Ordinal) ||
string.Equals(pd.Name, "DataSetName", StringComparison.Ordinal) ||
string.Equals(pd.Name, "AllowDBNull", StringComparison.Ordinal) ||
string.Equals(pd.Name, "Unique", StringComparison.Ordinal) ||
string.Equals(pd.Name, "NestedInDataSet", StringComparison.Ordinal) ||
string.Equals(pd.Name, "Locale", StringComparison.Ordinal) ||
string.Equals(pd.Name, "CaseSensitive", StringComparison.Ordinal) ||
string.Equals(pd.Name, "RemotingFormat", StringComparison.Ordinal)
)
{
return;
}
if (bisDataColumn)
{
if (string.Equals(pd.Name, "DataType", StringComparison.Ordinal))
{
string dt = XmlDataTypeName(col.DataType);
if (bIsSqlType || (col.DataType == typeof(System.Numerics.BigInteger)))
{
root.SetAttribute(Keywords.MSD_DATATYPE, Keywords.MSDNS, col.DataType.FullName);
}
else if ((dt.Length == 0) || bImplementsInullable || ((dt == Keywords.XSD_ANYTYPE) && (col.XmlDataType != Keywords.XSD_ANYTYPE)) || (col.DataType == typeof(DateTimeOffset)))
{
// in Whidbey, XmlDataTypeName function changed to return "anyType" for typeof(Object)
// should still always hit this code path for all non-built in types
// to handle version qualified typeof(Object) and other CDT objects correctly
// we must write the output exactly the same way as we read it
SetMSDataAttribute(root, col.DataType);
}
return;
}
if (string.Equals(pd.Name, "Attribute", StringComparison.Ordinal))
{
return;
}
}
string textValue = pd.Converter.ConvertToString(propInst);
root.SetAttribute(pd.Name, Keywords.MSDNS, textValue);
return;
}