Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type type = typeof(Car);
- ConstructorInfo[] allNonStaticCtors = type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
- foreach(var ctor in allNonStaticCtors)
- {
- var parameters = ctor.GetParameters();
- foreach(var parameter in parameters)
- {
- Console.WriteLine($" - {paramter.ParameterType} {parameter.Name}"); // type and name
- }
- }
- //
- var constructor = type.GetConstructor (BindingFlags.Instance | BindingFlags.NonPublic, new Type[] {typeof(int)}); // get ctor with int
- var car = (Ferrari)constructor.Invoke(new obj[] {123});
Add Comment
Please, Sign In to add comment