internal static Gateway Gateway(ContextStack context) { var gateway = context.Gateway; if (gateway is null) { throw new InvalidOperationException("Network Gateway Node has not been configured. Please check that 'Gateway' is set in the Client context."); } return(gateway); }
public IEnumerable <T> GetAll <T>(string name) { for (ContextStack <TContext>?ctx = this; ctx != null; ctx = ctx._parent) { if (ctx._map.TryGetValue(name, out object?asObject) && asObject is T t) { yield return(t); } } }
internal static Account Payer(ContextStack context) { var payer = context.Payer; if (payer is null) { throw new InvalidOperationException("The Payer account has not been configured. Please check that 'Payer' is set in the Client context."); } return(payer); }
// Value is forced to be set, but shouldn't be used // if method returns false, ignore nullable warnings private bool TryGet <T>(string name, out T value) { for (ContextStack <TContext> ctx = this; ctx != null; ctx = ctx._parent) { if (ctx._map.TryGetValue(name, out object asObject)) { if (asObject is T t) { value = t; } else { value = default; } return(true); } } value = default; return(false); }
public ContextStack(ContextStack <TContext>?parent) { _parent = parent; _map = new Dictionary <string, object?>(); if (parent == null) { // Root Context, holds the channels and is // only accessible via other contexts // so the ref count starts at 0 _refCount = 0; _channels = new ConcurrentDictionary <string, Channel>(); } else { // Not the root context, will be held // by a client or call context. Ref count // starts at 1 for convenience _refCount = 1; _channels = parent._channels; parent.addRef(); } }