Creating a generic Clone() method for dictionaries
I wanted to create a Clone method for dictionaries which returns the same type as the Dictionary on which the method was called:
This would be quite easy if we would do an extension method for every type of dictionary, but I wanted to do this for all IDictionary implementations. Here is my solution:
Since cloning works by creating a new instance with the source dictionary as constructor parameter, we have to use Activator.CreateInstance to create a new instance.
Comments
Post a Comment