Пример #1
0
        /// <summary>
        /// Performs the actual job of disposing the object.
        /// </summary>
        /// <param name="disposing">
        /// Passes the information whether this method is called by <see cref="Dispose()"/> (explicitly or
        /// implicitly at the end of a <c>using</c> statement), or by the <see cref="M:~SymmetricKeyCipherBase"/>.
        /// </param>
        /// <remarks>
        /// If the method is called with <paramref name="disposing"/><c>==true</c>, i.e. from <see cref="Dispose()"/>,
        /// it will try to release all managed resources (usually aggregated objects which implement <see cref="IDisposable"/> as well)
        /// and then it will release all unmanaged resources if any. If the parameter is <c>false</c> then
        /// the method will only try to release the unmanaged resources.
        /// </remarks>
        protected virtual void Dispose(
            bool disposing)
        {
            // if it is disposed or in a process of disposing - return.
            if (Interlocked.Exchange(ref _disposed, 1) != 0)
            {
                return;
            }

            if (disposing)
            {
                Symmetric.Dispose();

                if (KeyStorage is IDisposable disposable)
                {
                    disposable.Dispose();
                }
            }
        }