Created
September 3, 2012 15:38
-
-
Save otf/3610123 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LogicalCallContextEvent<'T>() = | |
let id = Guid.NewGuid() | |
member this.Publish = this :> IDelegateEvent<Handler<'T>> | |
member this.Trigger(arg:'T) = | |
if CallContext.LogicalGetData(id.ToString()) <> null then | |
(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>).Invoke(this, arg) | |
interface IDelegateEvent<Handler<'T>> with | |
member this.AddHandler(handler : Handler<'T>) = | |
CallContext.LogicalSetData(id.ToString(), Delegate.Combine(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>, handler) :?> Handler<'T>) | |
member this.RemoveHandler(handler: Handler<'T>) = | |
CallContext.LogicalSetData(id.ToString(), Delegate.Remove(CallContext.LogicalGetData(id.ToString()) :?> Handler<'T>, handler) :?> Handler<'T>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment