class
myClass
{
public string Name {
get; set; }
public string Surname {
get; set; }
}
private
static void CopyObj()
{
myClass source = new
myClass { Name = "Sergio", Surname =
"Russo" };
myClass destination =
new myClass();
foreach (PropertyInfo p
in source.GetType().GetProperties())
{
try
{
if ((p.CanRead) && (p.CanWrite))
{
var o = p.GetValue(source,
null);
if (o != null)
{
if (o is
Guid)
{
if (((Guid)o) !=
Guid.Empty)
p.SetValue(destination, o,
null);
}
else
{
p.SetValue(destination,
o, null);
}
}
}
}
catch (Exception)
{
//Manage exception
throw;
}
}
}
Regards,
Bubu
http://zsvipullo.blogspot.it