private DataColumn GetMappedColumn (TableMapping table, string name, string prefix, string ns, MappingType type, Type optColType)
{
DataColumn col = table.GetColumn (name);
// Infer schema
if (col == null) {
col = new DataColumn (name);
col.Prefix = prefix;
col.Namespace = ns;
col.ColumnMapping = type;
switch (type) {
case MappingType.Element:
table.Elements.Add (col);
break;
case MappingType.Attribute:
table.Attributes.Add (col);
break;
case MappingType.SimpleContent:
table.SimpleContent = col;
break;
case MappingType.Hidden:
// To generate parent key
col.DataType = optColType;
table.ReferenceKey = col;
break;
}
}
else if (col.ColumnMapping != type) // Check mapping type
throw new DataException (String.Format ("There are already another column that has different mapping type. Column is {0}, existing mapping type is {1}", col.ColumnName, col.ColumnMapping));
return col;
}