In a business library where Silverlight and .net need to be supported I have a class method in an object that returns a new object of the same type with all the fields copied over to create a duplicate object .
(I can't just call the standard New method because it won't work under silverlight so I'm caling the async method and waiting on the result which can't fail since the DataPortal_Create is simple property setting not involving the database)
Is this kosher?
public Client Duplicate()
{
Client dest = null;
Client.New((o, e) =>
{
if (e.Error != null)
throw e.Error;
else
dest = e.Object;
});
while (dest == null) ;//<--seems ugly but how else ?
... copy fields etc etc ...
}
How about this (given that no database access is required)?
public Client Duplicate()
{
var result = new Client();
result.MarkNew();
using (BypassPropertyChecks)
{
using (result.BypassPropertyChecks)
{
result.Name = this.Name;
// copy all properties
}
}
result.BusinessRules.CheckRules();
return result;
}
Yes, that would definitely work. Thanks Rocky.
Copyright (c) Marimer LLC