How to call a delegate held in a Variant array?

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Sep 10 14:15:34 PDT 2013


On Tue, Sep 10, 2013 at 10:09:33PM +0200, Gary Willoughby wrote:
> How to call a delegate held in a Variant array? I'm toying with some
> dynamic delegate code and wondered if i put a delegate in a Variant
> how would i call it?
> 
> class C
> {
> 	private Variant[string] _methods;
> 
> 	public void addMethod(T)(string name, T func)
> 	{
> 		this._methods[name] = func;
> 	}
> }
> 
> auto obj = new C();
> 
> obj.addMethod("test", delegate(){
> 	return 34;
> });
> 
> Now, how do i call the delegate held in 'this._methods["test"]'?

My first guess would be: _methods["test"]();

Or does that not work?


T

-- 
Старый друг лучше новых двух.


More information about the Digitalmars-d-learn mailing list