internal static void SetProperties(object instance, XmlAttribute[] attrs)
{
// This is called from both XSD and XDR schemas.
// Do we realy need it in XSD ???
if (attrs == null)
return;
for (int i = 0; i < attrs.Length; i++)
{
if (attrs[i].NamespaceURI == Keywords.MSDNS)
{
string name = attrs[i].LocalName;
string value = attrs[i].Value;
if (name == "DefaultValue" || name == "Ordinal" || name == "Locale" || name == "RemotingFormat")
continue;
if (name == "Expression" && instance is DataColumn) // we will handle columnexpressions at HandleColumnExpression
continue;
if (name == "DataType")
{
DataColumn col = instance as DataColumn;
if (col != null)
{
col.DataType = DataStorage.GetType(value);
}
continue;
}
PropertyDescriptor pd = TypeDescriptor.GetProperties(instance)[name];
if (pd != null)
{
// Standard property
Type type = pd.PropertyType;
TypeConverter converter = XMLSchema.GetConverter(type);
object propValue;
if (converter.CanConvertFrom(typeof(string)))
{
propValue = converter.ConvertFromString(value);
}
else if (type == typeof(Type))
{
propValue = Type.GetType(value);
}
else if (type == typeof(CultureInfo))
{
propValue = new CultureInfo(value);
}
else
{
throw ExceptionBuilder.CannotConvert(value, type.FullName);
}
pd.SetValue(instance, propValue);
}
}
}
}// SetProperties