I have this method that I want to use to return an Object that i have created by passing in the type name:
public object GetObjectType(object objectTypeName)
{
Type objecType = objectTypeName.GetType();
return Activator.CreateInstance(objecType);
}
When I do this:
var a = GetObjectType("Person");
I get: No parameterless constructor defined for this object.
Im not too sure what this CreateInstance
does so im flying blind here.
Do I need to add something to my class which looks like this:
public class Person
{
public string Name {get; set;}
}