C# Passing a Generic Class As a Method Parameter
<p>I have a <code>CreateMessage class</code> that is meant to handle incoming messages from a <code>TCPClient</code>, get the user type and return how the message should be formatted to its calling <code>method</code>.</p>

<p>In the method <code>GetUserType</code>, I want to pass <code>UserBaseType</code> as a parameter, which is a <code>generic abstract class</code> that takes a <code>Type</code> of <code>UserType</code>. However, it gives me the error:</p>

<blockquote>
  <p>Using the generic type 'UserTypeBase' requires one type argument.</p>
</blockquote>

<p>I'm still trying to wrap my head around using generics and constraints, so I don't know if I'm going about this the wrong way. I've done a bit of digging to try to find a solution myself, but haven't found anything that more or less tailors to what I'm trying to do.</p>

<pre><code>internal class CreateMessage
{
    internal static string user;
    internal static string message;

    internal CreateMessage(string data)
    {
        user = Lists.users[data.Substring(1, 3)];
        message = data.Substring(5, data.Length - 5);
    }

    private UserType GetUserType(UserTypeBase type)
    {
        return type.CreateType();
    }

    internal string Message()
    {
        UserType Type = null;
        if (user.Contains("[M]"))
            Type = GetUserType(UserMod);
        else if (user.Contains("[B]"))
            Type = GetUserType(UserVIP);
        else
            Type = GetUserType(UserRegular);
        return Type.Message();
    }
}
</code></pre>

<p><strong>UserBaseType.cs</strong></p>

<pre><code>internal abstract class UserTypeBase&lt;T&gt; where T: UserType
{
    public abstract string User { get; }
    public abstract string Message { get; }
    public abstract T CreateType();
}
</code></pre>