Accessing C# Object in java as method parameter.

53 views
Skip to first unread message

Kiran Hariyapuraju

unread,
Oct 29, 2018, 4:39:50 AM10/29/18
to jni4net
Hi,

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().















Reply all
Reply to author
Forward
0 new messages