EDIT: . Unfortunately, there was no way to find out whether the constructor for the class in question is sensitive to when or how many times it is called, or if the state of the object changes during the method, so it will need to be created from scratch every time. Ignore the dictionary and just think that delegates are created in line mode during the method :-)
Let's say I have the following method with the local variable Dictionary of Type to Action.
void TakeAction(Type type)
{
// Random types chosen for example.
var actions = new Dictionary<Type, Action>()
{
{typeof(StringBuilder), () =>
{
// ..
}},
{typeof(DateTime), () =>
{
// ..
}}
};
actions[type].Invoke();
}
. # , - ? ? , , , , , .