Type myType = typeof(string); PropertyInfo[] properties = myType.GetProperties(); foreach (PropertyInfo property in properties) { Console.WriteLine(property.Name); }
Type myType = typeof(MyClass); MyClass myObject = (MyClass)Activator.CreateInstance(myType);This code uses the Type class and the Activator class to create an instance of the MyClass type. It first gets a Type object representing the MyClass type, and then uses the Activator class to create an instance of that type. This code does not use any package libraries.