Here is a sample piece of code where im trying to send a var type variable to another function as a reference parameter.
Type type = Type.GetType(te1.GetValue("class1"));
MethodInfo method = type.GetMethod("fnc1");
var obj1 = Activator.CreateInstance(type);
I cant use (class1)Activator.CreateInstance(type) since the variable class1 will be decided at runtime. That's why im using reflection here.
method.Invoke(obj1, new object[] { });
class2 cls2= new class2 ();
cls2.fnc2(ref obj1);//getting error 'cannot convert object to class type'
Im getting error as the fnc2 function receive parameter as a type of class1.
public string fnc2(ref class1 obj3)
{
}
How i can handle this? I need to get the parameter as a type of class1 using reflection. So i used the type var. I cant use dynamic since im using framework 3.5.
My requirement is create a object of class1>> execute a function of class1>> retain the object and pass that object to another function of class2 and process there.Also the name class1 and class2 will be decided dynamically and cannot be hard coded.