tags:

views:

20

answers:

0

I have a class that has ConcurrentDictionary inside. From the class, I expose only few methods. I just realized that method TryGetValue doesn't expose copies of object from dictionary but rather the objects themselves. So I want to deepcopy them :) Let's say I have a method like that:

    public IList<MyClass> TryGetMyClass(long someId)
    {
        IList<MyClass> classes= null;
        concurrentDictionary.TryGetValue(bpLevelId, out classes);
        return classes.CloneDeep();
    }

If so, what should I lock it, by using:

   lock(((ICollection)concurrentDictionary).SyncRoot)

or

   lock(someLocalObject)

?