Wednesday, July 02, 2008

Cloning using Serialization

I found some great C# code the other day which allows deep copying of objects, rather than shallow copies which object.Clone() does. Saved heaps of time mucking around with the ICloneable interface, and basically rewriting heaps of code.

You need to decorate the class(es) that you want to clone with the [Serializable] attribute. If you are trying to clone a object of a type which has members of some other class, those classes need to be serializable too.

public static object Clone(object obj)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, obj);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
return bf.Deserialize(ms);
}

Labels: , ,

Ebay International Search Gadget rewritten

For any of you that use the Ebay international search gadget on the right hand side of the blog, I have just rewritten it as it was not working anymore.

I am have also added an Amazon international search gadget.

Use them directly from this site or add them to your iGoogle page. Note that the international functionadoes not work if you use the gadgets directly from this site. It only links to the respective US sites. You need to add it to a your iGoogle page to get the full functionality.

Tuesday, May 06, 2008

Creating Excel/Office 2007 Addins in Visual Studio 2008

A month or 2 ago I went to the Heroes launch of VS 2008 in Adelaide. There are some exciting things happening in VS2008, especially with the Shared Addin in VS2008. Previously, you needed to go through the mess of creating a Shim, and manually creating XML to write to a ribbon. Now, they have made it simple. There is a Ribbon control to add which creates all the XML in the background, and all the shimming stuff happens automatically.

Create a New Project


Adding a Ribbon Control


Adding Controls from the Toolbox to the Ribbon


Finally!!! It is easy.