Constraint cannot be special class 'System.Object'
===

 My function requires you pass it a string and a Type as T. Based on T i want to parse the string val as that type, but I get the error from the title of this question. Anyone that has any insight or other ways of accomplishing this function, I would greatly appreciate it. 

  

    T Parse<T>(string val) where T : System.Object
    	{
    		TypeCode code = Type.GetTypeCode(typeof(T));
    		switch (code)
    		{
    			case TypeCode.Boolean:
    				return System.Boolean.Parse(val);
    				break;
    			case TypeCode.Int32:
    				return Int32.Parse(val);
    				break;
    			case TypeCode.Double:
    				return Double.Parse(val);
    				break;
    			case TypeCode.String:
    				return (string)val;
    				break;
    		}
    		return null;
    	}