Creating non-generic delegate when there is generic one
5 posts
• Page 1 of 1
Creating non-generic delegate when there is generic one
Hello
I'm working on porting a php-gtk application to phalanger/gtk-sharp. Currently I'm stuck on the following problem:
There is an event (Gtk.MenuItem.Activated) that only accepts System.EventHandler delegates (but not System.EventHandler<TEventArgs> variety). When I try to create a delegate based on http://wiki.php-compiler.net/Code_Sampl ... chronously sample, it creates generic version:
So the question is: how do I create System\EventHandler instead of System\EventHandler<:T:> ?
PS: I also tried to inherit System\EventHandler in my own class, but unfortunately it's marked final and thus non-extendable.
I'm working on porting a php-gtk application to phalanger/gtk-sharp. Currently I'm stuck on the following problem:
There is an event (Gtk.MenuItem.Activated) that only accepts System.EventHandler delegates (but not System.EventHandler<TEventArgs> variety). When I try to create a delegate based on http://wiki.php-compiler.net/Code_Sampl ... chronously sample, it creates generic version:
- Code: Select all
$h = new \System\EventHandler(function() {});
\var_dump($h);
$item = $this->ui->GetWidget('quit_menu_item');
\var_dump(\get_class($item), $item->Activated);
$item->Activated->Add($h);
- Code: Select all
object(System\EventHandler<:System\Object:>)#1051914240 (2) {
["Method"]=>
{Void <^DelegateStub>(PHP.Core.Reflection.DObject, System.Object, System.Object)}
["Target"]=>
{object}
}
string(17) "Gtk\ImageMenuItem"
object(EventClass<:System\EventHandler:>)#380650752 (0) {
}
Error: Argument 'handler' must be of type 'System\EventHandler'.
So the question is: how do I create System\EventHandler instead of System\EventHandler<:T:> ?
PS: I also tried to inherit System\EventHandler in my own class, but unfortunately it's marked final and thus non-extendable.
- weirdan
- Posts: 17
- Joined: June 4th, 2013, 1:11 am
Re: Creating non-generic delegate when there is generic one
I guess Phalanger cannot have two classes with the same name "EventHandler", so it uses the last one it founds.
You can try implicit conversion,
Phalanger automatically converts callable PHP object to .NET delegate representation of correct type.
If it won't work, you can implement some factory method in C#, and call that helper method from PHP.
You can try implicit conversion,
- Code: Select all
$item->Activated->Add(function(){});
Phalanger automatically converts callable PHP object to .NET delegate representation of correct type.
If it won't work, you can implement some factory method in C#, and call that helper method from PHP.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Creating non-generic delegate when there is generic one
Jakub Misek wrote:If it won't work, you can implement some factory method in C#, and call that helper method from PHP.
I tried that, but I guess my sharp-fu is not strong enough. Will try implicit conversion once I get back from work.
- weirdan
- Posts: 17
- Joined: June 4th, 2013, 1:11 am
Re: Creating non-generic delegate when there is generic one
Implicit conversion worked, thank you for the pointer.
- weirdan
- Posts: 17
- Joined: June 4th, 2013, 1:11 am
Re: Creating non-generic delegate when there is generic one
Great! I'm glad it works.
Thanks,
Thanks,
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 11 guests