You can't really do that. The closest you could come would be:
Func<T, T, bool> ConvertToBinaryConditionOperator<T>(string op)
and then:
if (ConvertToBinaryConditionOperator<int>(input)(a, b))
{
}
The tricky bit is what ConvertToBinaryConditionOperator
would do. You might want to look at Marc Gravell's work on implementing generic operators in MiscUtil. Expression trees could be really useful in this case, although I believe Marc has a working approach which works on .NET 2 as well.
So in this case you might have something like (using MiscUtil)
public static Func<T, T, bool> ConvertToBinaryConditionOperator<T>(string op)
{
switch (op)
{
case "<": return Operator.LessThan<T>;
case ">": return Operator.GreaterThan<T>;
case "==": return Operator.Equal<T>;
case "<=": return Operator.LessThanOrEqual<T>;
// etc
default: throw new ArgumentException("op");
}
}