You should create some interface:
public interface ISomeInterface
{
string calc(string str);
}
Then implement it by your classes:
public class Class1 : ISomeInterface
{
//your code
}
public class Class2 : ISomeInterface
{
//your code
}
Then change your method ProcessModel() to:
public static void ProcessModel(ISomeInterface model)
{
String abc = model.calc("100");
}
OR
If you really don't want to use interfaces for some reason you can use reflection. Your classes should have method with the same names:
public static string CallMethodOfSomeObject(object obj, string methodName, params object[] parameters)
{
var type = obj.GetType();
var method = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
//use this if you use C#6 or higher version
return (string)method?.Invoke(obj, parameters);
//use this if you use C#5 or lower version
if (method != null)
{
return (string)method.Invoke(obj, parameters);
}
return null;
}
And your method ProcessModel():
public static void ProcessModel(object model)
{
String abc = CallMethodOfSomeObject(model, "calc", "100");
}
Also, consider changing ProcessModel() return type to string:
public static string ProcessModel(ISomeInterface model)
{
return model.calc("100");
}
//OR
public static string ProcessModel(object model)
{
return CallMethodOfSomeObject(model, "calc", "100");
}
And call this method is every case inside switch:
case "Case1":
Class1 obj1 = new Class1 ();
string abc = ProcessModel(obj1);
break;
case "Case2":
Class2 obj2 = new Class2 ();
string abc = ProcessModel(obj2);
break;
ICalculableor similar) which has a single method (calc(string value)). Then get each of your classes to implement this interface, and define your method asProcessModel(ICalculable calculable). Google "program to an interface" for more info about this - it's pretty fundamental to OO programming.