Beispiel #1
0
        /// <summary>
        /// Removes a context, setting all commands to a (non-thread safe) enumerable of
        /// all the commands attached to that context.
        ///
        /// If the context was never registered, will return false and set commands to null.
        ///
        /// Subsequent calls to TryRemove with the same context will return false unless it is
        /// re-registered with TryCreate.
        /// </summary>
        /// <param name="ctx">The context to remove for.</param>
        /// <param name="commands">The commands to remove.</param>
        public bool TryRemove(object ctx, out ProfiledCommandEnumerable commands)
        {
            var cell = ProfileContextCell.ToLookupBy(ctx);

            if (!profiledCommands.TryRemove(cell, out ConcurrentProfileStorageCollection storage))
            {
                commands = default(ProfiledCommandEnumerable);
                return(false);
            }

            commands = storage.EnumerateAndReturnForReuse();
            return(true);
        }
        /// <summary>
        /// Returns true and sets val to the tracking collection associated with the given context if the context
        /// was registered with TryCreate.
        ///
        /// Otherwise returns false and sets val to null.
        /// </summary>
        public bool TryGetValue(object ctx, out ConcurrentProfileStorageCollection val)
        {
            var cell = ProfileContextCell.ToLookupBy(ctx);

            return(profiledCommands.TryGetValue(cell, out val));
        }