Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few people have suggested using the call stack to get the module information. If you want to get the <em>type</em> of object that made the call, it's not too bad. Unfortunately there is no feasible (ie: simple, portable and functional) method to extract <em>instance</em> information from data in the call stack. There are several reasons why, including problems with optimization inlining methods that then do not show on the stack... which can interfere with calling <em>type</em> detection as well.</p> <p>Given this fact, the short answer is that you have to provide a <code>Module</code> object as a parameter to the methods you are calling in the DLL. The method suggested by @p.s.w.g is one way of achieving this, but has the disadvantage of potentially polluting the symbol space of the <code>Module</code> class. This can be solved by having the <code>Module</code> class implement a protected or public API member that exposes the functions you want to provide:</p> <pre><code>public abstract class Module { internal int ID; public class APIWrapper { Module module; public APIWrapper(Module module) { this.module = module; } public void method1() { apiimpl.method1(this.module); } public int method2() { return apiimpl.method2(this.module); } } public readonly APIWrapper API; public Module() { ID = generate_module_identity(); API = new APIWrapper(this); } public abstract void ModuleStart(); } internal static class apiimpl { public static void method1(Module module) { ... } public static int method2(Module module) { ... } } </code></pre> <p>The other developers can then use it this way:</p> <pre><code>class MyModule : Module { public override void ModuleStart() { API.method1(); } } </code></pre> <p>This encapsulates the methods that your DLL exposes, without introducing too much pollution of the symbol space of the <code>Module</code> class hierarchy.</p> <p>[opinion type="my" value="YMMV"]</p> <p>However, I suggest that you seriously reconsider using this type of abstraction. If the methods you are calling require some information about the specific <code>Module</code> instance that is calling them, it should be clear in the method's parameters. Encouraging your team to follow guidelines that lead to clarity can be more important than finding ways to abstract away small details.</p> <p>[/opinion]</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload