Any idea for a solution to handle overloads when dynamically implementing methods?

Gary Willoughby dev at nomad.so
Mon Sep 9 13:16:42 PDT 2013


Just wondered if i could pick you brains for a nice solution to 
dynamically add methods to a class, paying particular attention 
to overloads. I'm currently writing a mocking framework and 
everything's coming along nicely and i'm wondering how to handle 
replacing overloads of the mocked class.

To create a new mocked class this is the code:

	auto mock = new Mock!Person();

Simple enough, mock now contains an extended class with all the 
methods set to assert(false) because there are no implementations 
yet. What i need to do is to add the implementations dynamically. 
This is the code i propose.

	mock.addMethod("getAge", int delegate(){
		return 40;
	});

	assert(mock.getAge() == 40);

Which i guess would be easy to implement but it doesn't handle 
overloads because the method string doesn't contain enough 
information to define which overload it's implementing.

Any nice ideas what would be a nice way of supporting this? I 
thought i'd ask while i have a think and get some tea. :)


More information about the Digitalmars-d-learn mailing list