Accessing C# Object in java as method parameter using jni4net

365 Views Asked by At

We are able to call java in C# code and able to pass Strings and integers as method parameters. Able to access Strings are integers directly by using java java.lang.String and java.lang.Integer with out issues. But when we pass C# custom object as method parameter we could not find a way to access it. Eg: Employee.cs is the C# class with parameter name. Used proxygen to create EmployeeLibraray.dll, EmployeeLibraray.j4n.dll and EmployeeLibraray.j4n.

C# code where we are trying to pass C# object

var bs = new BridgeSetup();
bs.AddAllJarsClassPath("./");
Bridge.CreateJVM(bs);
Bridge.RegisterAssembly(typeof(JavaTest).Assembly);
JavaTest obj = new JavaTest();    ================================> JavaTest 
is the class generated using proxygen where it is called in C#
EmployeeLibraray.Employee e = new EmployeeLibraray.Employee();   
===========> Custom C# object to be passed to Java 
 e.LoginName = "test";
 obj.execute( e);

Code in java

public void execute(system.Object inputObj) throws Exception {
}

Question

How should we cast the inputObj as Employee so that can access directly e.getName().

0

There are 0 best solutions below