3

I want to have specific methods with a specific pattern recognized at compile time and registered along with a specified id trough mixins in a parent class.

ex.: take a method 'X' from a class with a predetermined id:5, what I want is that, in a mixin in a parent class, method X will be registered as a delegate with its id to be called later on by its id.

What would be the best way to specify the Id considering I want the id to be of type int and only the specified methods to be registered?

should I (if it is even possible) do it with a custom annotation pretty much like the @property but with an argument, like:

@autoregister(id)
void method(...)

if it is possible to do it this way, an example or a link to the documentation on how to do it would be nice since I didn't find it in the documentation.

if it is not possible I'll use the function's signature as a string instead but I really want to do it with a numeric identifier instead of a possibly quite long string as much as possible.

1 Answer 1

1

Making custom annotations is not possible at the moment (but it will be in the future).

However, you can make your own method-naming convention that will allow you to do something similar to what you have described. I do not have time to think deeply how to accomplish this, but I would start with having a method like:

public void id30_doSomething(/* params */) {
  // body
} 
alias id30_doSomething doSomething;

// finally, lets do something with all these methods
// and generate mixin...

After this you could probably list all methods and find if their names match id([0-9]*)_.*, if so, then you generate mixin to register them in the parent...

1
  • As of now that's pretty much the solution I am using, and after thinking more about it, I feel that annotations would harm the D language more than they would add to it, but that's a point for a different discussion. Thanks for your contribution, but I am still hoping to find a different solution or comments on how to improve this. I mostly use it for method referencing trough network between C# and D applications. Jun 29, 2012 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.