Accessing C# Object in java as method parameter.

已查看 52 次
跳至第一个未读帖子

Kiran Hariyapuraju

未读,
2018年10月29日 04:39:502018/10/29
收件人 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().















回复全部
回复作者
转发
0 个新帖子