I want to call my method via reflection, but my class uses a reference type value:
public class MyClass
{
public void Save(MyEntity entity)
{
}
}
How can I pass MyEntity
by using below code? Save
method has class type parameter.
Assembly loadedAssembly = Assembly.LoadFile(dll);
//if (loadedAssembly.GetName().Name== "FFSNext.Domain")
Assembly asm = Assembly.LoadFrom($"{binPath}FFSNext.Domain.dll");
Type t = asm.GetType("XXX.Domain.XY.Products.Products.Myprovider.ProductClass");
//Get and display the method.
MethodBase Mymethodbase = t.GetMethod("Save");
Console.Write("\nMymethodbase = " + Mymethodbase);
//Get the ParameterInfo array.
ParameterInfo[] Myarray = Mymethodbase.GetParameters();
Type testType = t;
object testInstance = Activator.CreateInstance(testType);
MethodInfo openMethod = testType.GetMethod("Save");
openMethod.Invoke(testInstance, new object[] { new Product() });
Aucun commentaire:
Enregistrer un commentaire