Next: , Previous: Using pragma foreign_proc for C#, Up: Interfacing with C#   [Contents] Using pragma foreign_export for C#

A ‘pragma foreign_export’ declaration for C# has the form:

:- pragma foreign_export("C#", MercuryMode, "C#_Name").

For example,

:- pragma foreign_export("C#", foo(in, in, out), "FOO").

The type signature of the C# interface to a Mercury procedure is as described in C# data passing conventions.

Calling polymorphically typed Mercury procedures from C# is a little bit more difficult than calling ordinary (monomorphically typed) Mercury procedures. The simplest method is to just create monomorphic forwarding procedures that call the polymorphic procedures, and export them, rather than exporting the polymorphic procedures.

If you do export a polymorphically typed Mercury procedure, the compiler will prepend one ‘type_info’ argument to the parameter list of the C# interface function for each distinct type variable in the Mercury procedure’s type signature. The caller must arrange to pass in appropriate ‘type_info’ values corresponding to the types of the other arguments passed. These ‘type_info’ arguments can be obtained using the Mercury ‘type_of’ function in the Mercury standard library module ‘type_desc’.