I have a ConcurrentDictionary
:
Node n = new Node()
{
Id = 1,
Title = "New title"
};
this.nodes.AddOrUpdate((int)n.Id, n, (key, existingVal) =>
{
existingVal.Update(n);
return existingVal;
});
My Node
class implements Update
which update all properties on the object to be updated. This works fine but it seems ridiculous that I have to write it every time since it's the same for all cases.
I can create a Func
and a function to use since it's always the same:
...
new Func<int, Node, Node>(UpdateNode)
...
private Node UpdateNode(int id, Node node)
{
return node;
}
How can I implement a function
where I can also access n
?