I have a different scenario. I need to create instance of a class which is public but having all its constructors as internal. The class has no default constructor.
I tried the below ways. But it didnt work.
Activator.CreateInstance(typeof(ClassName));
Activator.CreateInstance(typeof(ClassName), nonpublic:true);
Activator.CreateInstance(typeof(ClassName),true);
Activator.CreateInstance(typeof(ClassName), new object[]{double,bool});
I also tried this. But ended up with System.MissingMethodException.
var constructors = typeof(ClassName).GetConstructors();
foreach(var ctor in constructors)
ctor.Invoke(new object[] {double, bool});
I cant able to use BindingFlags in Xamrarin. Am stuck, Does anyone have a solution for this?
Aucun commentaire:
Enregistrer un commentaire