public object GetObject(System.Data.DataSet ds,Type type)
{
if(ds==null)return null;
if(ds.Tables.Count<=0)return null;
if(ds.Tables[0].Rows.Count<=0)return null;
LHY.XMLConfiglib.Entity entity=LHY.XMLConfiglib.ConfigXML.AllEntity[type.FullName];
object obj=type.Assembly.CreateInstance(type.FullName,true);
foreach(LHY.XMLConfiglib.Attr at in entity.AttrCollection)
{
System.Reflection.PropertyInfo pinfo=obj.GetType().GetProperty(at.Name);
if(pinfo.CanWrite)
pinfo.SetValue(obj,Convert.ChangeType(ds.Tables[0].Rows[0][at.DBName],pinfo.PropertyType),null);
}
return obj;
}
其中主要的地方是Convert.ChangeType的应用,如果没有这个方法,那么将会出错。