public XChannel(ChannelIdentification channelIdentification, object?targetId, bool exclusiveChannel, IWeakDelegate weakDelegate) { this.Identification = channelIdentification; this.TargetId = targetId; this.ExclusiveChannel = exclusiveChannel; this.WeakDelegate = weakDelegate; }
private static XChannel AddXChannel(LinkedList <XChannel> list, ChannelIdentification identification, object?targetId, bool exclusiveChannel, IWeakDelegate weakDelegate) { // lock (cs) required. if (exclusiveChannel) { if (list.Count > 0) { // other channel already exists. throw new InvalidOperationException(); } } else { if (list.First?.Value.ExclusiveChannel == true) { // Exclusive channel exists. throw new InvalidOperationException(); } } // New XChannel var channel = new XChannel(identification, targetId, exclusiveChannel, weakDelegate); // list: Identification to XChannels. channel.Node = list.AddLast(channel); return(channel); }
public static XChannel Open <TMessage, TResult>(Func <TMessage, TResult> method, object?targetId = null, bool exclusiveChannel = false) { XChannel channel; var identification = new ChannelIdentification(typeof(TMessage), typeof(TResult)); lock (cs) { var list = Cache_WeakFunction <TMessage, TResult> .List; channel = AddXChannel(list, identification, targetId, exclusiveChannel, new WeakFunc <TMessage, TResult>(method)); CleanupList(list); } return(channel); }