Checking the GridColumnType using a switch statement I am trying to refactor a switch statement. I know that you can replace a switch with a Dictionary, or a strategy pattern but it kind of feels like overkill for what I have.

Switch

var filters = new List&lt;ColumnFilter&gt;();
switch (gridColumnDataType)
                {
                    case "System.String":
                        if (filterColumnType != typeof(RuleTextNode))
                            filters.Add(columnFilter);
                        break;
                    case "System.DateTime":
                        if (filterColumnType != typeof(RuleDateNode))
                            filters.Add(columnFilter);
                        break;
                    case "System.Boolean":
                        if (filterColumnType != typeof(RuleBoolNode))
                            filters.Add(columnFilter);
                        break;
                    default:
                        if (gridColumnType.IsNumericType())
                            if (filterColumnType != typeof(RuleNumberNode))
                                filters.Add(columnFilter);
                        break;
                }
            }


Explanation

I have a grid and each grid column has its own datatype column. Like DataType = "String.DateTime" And there is a filter on each column. Now the problem is every now and again the filter an column does not have the same DataType. Thank you Infragistics.

What the switch is doing is checking what the GridColumnType is and if it's, let's say, a System.String, the FilterColumnType should be of type RuleTextNode. If it is not, I am just adding it in the ColumnFilter List.

All the RuleTypes have the same underlying type FilteringNode.

Having said all of that, what would be the best way the rewrite the switch to avoid the code duplication and the switch?
The only possible solution I can come up with, to shorten/simplify your code, is to extract the redundant code and place it in a separate method TryAddFilter for example:

private void TryAddFilter(FilteringNode node)
{
    if (filterColumnType != typeof(node))
        filters.Add(columnFilter);
}


And then call this method from the switch-statement:

switch (gridColumnDataType)
{
    case "System.String": TryAddFilter(RuleTextNode); break;
    case "System.DateTime": TryAddFilter(RuleDateNode); break;
    case "System.Boolean": TryAddFilter(RuleBoolNode); break;
    default:
        if (gridColumnType.IsNumericType())
            TryAddFilter(RuleNumberNode); break;
}