//这里有一些代码
object target = Activator.CreateInstance(typeof(T));
PropertyInfo[] sourceProperties = sourceType.GetProperties();
foreach (PropertyInfo pi in sourceProperties)
{
PropertyInfo targetPi = typeof(T).GetProperty(pi.Name); //returns null why?
object piValue = pi.GetValue(source, null);
try
{
if (targetPi != null) // it doesnt work
{
targetPi.SetValue(target,piValue, null); // target has typeof(T)
}
}
catch { }
}
return(T)target;
}