All pastes #25280 Raw Edit

Anonymous

public text v1 · immutable
#25280 ·published 2005-10-12 01:57 UTC
rendered paste body
#import <ObjCSharpBridge.h>
#import <Foundation/Foundation.h>

@implementation MyActor : NSObject
- (void) invokeHandler: (id) handler bridge: (id) bridge
{
        Class ArrayListClass = [bridge getClass: "System.Collections.ArrayList"];

        id arraylist = [ArrayListClass initWithInt32:2];

        [arraylist AddWithObject:self];
        [arraylist AddWithObject:nil];

        [handler DynamicInvokeWithObjectArray:[arraylist ToArray]];
}
@end

@implementation MyTarget : NSObject
- (void) targetMethod: (id) sender args: (id) args
{
        NSLog (@"I was invoked by a %s", [[sender className] cString]);
}
@end

int main (void) {
        // Make Apple shut up
        [[NSAutoreleasePool alloc] init];

        // Get the bridge and initialize it
        id bridge = [[ObjCSharpBridge alloc] init];

        NSLog (@"Load bridge classes.");
        Class MyActorClass = [bridge getClass: "MyActor"];
        Class MyTargetClass = [bridge getClass: "MyTarget"];
        Class EventHandlerClass = [bridge getClass: "System.EventHandler"];

        NSLog (@"Instantiate bridge classes.");
        id actor = [[MyActorClass alloc] init];
        id target = [[MyTargetClass alloc] init];

        NSLog (@"Call invoker.");
        [actor invokeHandler: [EventHandlerClass initWithTarget: target Selector: "targetMethod:args:"] bridge: bridge];

        return 1;
}