Creating a Copy of a Custom Sitemap in SharePoint 2010

I wanted it cached and I was planning to use the HTTPruntime to handle the caching in my code. The issue I ran into was that since the root object was a complex reference type with deep nested elements, the changes and trimmings I made to the data ended up propagating all the way back into the HTTP Run time cached object. I came across this link which seemed to cover the issue.

How do I clone a generic list in C#? – Stack Overflow If your elements are value types, then you can just do: List newList = new List (oldList); However, if they are reference types and you w…

However that method required that and iclonable interface be implemented. So that did not work since the object was just a bare data class/structure.

Copy-Clone custom object in C# | Wacdesigns This post relates how to Copy/Clone custom object in C# (Deep and Shallow Clone). In this example I will be having a base class that all …

This method looked promising, but also did not work. So I accepted that I was going to have to create my own copy logic and attach it to the base object as a method. So I did some searching and found this very helpful article.

C# Class For Making a Deep Copy Clone of an Arbitrary Object | Thomas Happ Submitted by Thomas on Sat, 2006-10-14 09:38. Here is a C# class that can create a deep copy clone of an arbitrary object. The thing that…

the only change I needed to make was swapping out one argument type here.

Type Methods (System) Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited f…

the original article called for a fieldinfo array to be grabbed from the type, but the way I had it set up, I needed to grab the propertyInfo array from getproperties. And since this was a List<string> type in my example, I then had to iterate over it to copy the object. Once I made these changes, I was able to new up a copy of the original object, avoid all the calls back to the taxonomy store, and make whatever trims and modifications I wanted without corrupting the base object. pretty handy, and not to hard to pull off.


Originally posted on How SharePoint Annoyed Me Today.