C# Static types cannot be used as parameters

You can't pass a static type to a method as a parameter because then it would have to be instantiated, and you can't create an instance of a static class.


It's not recommended but you can simulate use of Static classes as parameters. Create an Instance class like this :

public class Instance
{

    public Type StaticObject { get; private set; }

    public Instance(Type staticType)
    {
        StaticObject = staticType;
    }

    public object Call(string name, params object[] parameters)
    {
        MethodInfo method = StaticObject.GetMethod(name);
        return method.Invoke(StaticObject, parameters);
    }

    public object Call(string name)
    {
        return Call(name, null);
    }

}

Then your function where you would use the static class :

    private static void YourFunction(Instance instance)
    {
        instance.Call("TheNameOfMethodToCall", null);
    }

For instance.Call :

  • The first parameter is the name of the method of your static class to call
  • The second parameter is the list of arguments to pass to the method.

And use like this :

    static void Main(string[] args)
    {

        YourFunction(new Instance(typeof(YourStaticClass)));

        Console.ReadKey();

    }