Please is possible optimise this code, with dictionary? Or otherwise.
if (node.Type.Equals(NodeType.CONTAINER))
{
DataUtils.ContainerToData((INode<ContainerValue>) node, data);
}
else if (node.Type.Equals(NodeType.TEXT))
{
DataUtils.TextToData((INode<TextValue>) node, data);
}
I have 15 this conditions.
I thought that dictionary will work, but how make casting? (INode<pair.Value>) node
. I looking somethink solution like is this:
var dictionary = new Dictionary<string, Type>();
dictionary.Add(NodeType.CONTAINER, tyeof(ContainerValue));
dictionary.Add(NodeType.TEXT, tyeof(TextValue));
foreach (var pair in dictionary)
{
if(node.Type.Equals(pair.Key))
{
// wrong
DataUtils.ContainerToData((INode<pair.Value>) node, data);
}
}