VB to C # translation

In VB(ASP.NET)

Application("myapp")= Server.CreateObject("APP.Engine ")

aa = Application("myapp").myMethod(2)

works.

I tried it in C#

Application["myapp"]= Server.CreateObject("APP.Engine")

but

Application[" myapp"].myMethod(2)

Failed

'object' does not contain a definition for'myMethod'

How to expose public interface in C#?

If you have access to the defined type (that is, not the original COM object), you can simply convert:

((APP.Engine)Application["myapp"]).myMethod(2);

If you are using c# 4.0, you can perform the following operations:

dymamic myApp = Application["myapp"];
myApp.myMethod(2);

Otherwise, you will have to use reflection and Type.InvokeMember(…) to use dynamic method invocation

In VB(ASP.NET)

Application("myapp")= Server.CreateObject("APP.Engine")

aa = Application("myapp").myMethod(2)

works.

I tried it in C#

Application["myapp"]= Server.CreateObject("APP.Engine")

pre>

But

Application["myapp"].myMethod(2)

Failed

'object' does not contain a definition for'myMethod'

How to expose public interface in C#?

If you have access to the defined type (that is, not the original COM object), you can simply convert:

((APP.Engine)Application["myapp"]).myMethod(2);

If you are using c#4.0, you can do the following:

dymamic myApp = Application["myapp"];
myApp.myMethod(2);

Otherwise, you will have to use reflection and Type.InvokeMember (...)Use dynamic method call

Leave a Comment

Your email address will not be published.