Ejemplo n.º 1
0
        /// <summary>
        /// Creates a block of code associated with asynchronously disposable resource.
        /// </summary>
        /// <param name="resource">The disposable resource.</param>
        /// <param name="configureAwait"><see langword="true"/> to call <see cref="ValueTask.ConfigureAwait(bool)"/> with <see langword="false"/> argument when awaiting <see cref="IAsyncDisposable.DisposeAsync"/> method.</param>
        /// <param name="body">The delegate used to construct the block of code.</param>
        /// <returns>The constructed expression.</returns>
        /// <seealso cref="IsAwaitable"/>
        public static UsingExpression Create(Expression resource, bool configureAwait, Statement body)
        {
            var result = new UsingExpression(resource, configureAwait);

            result.Body = body(result.Resource);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a block of code associated with disposable resource.
        /// </summary>
        /// <param name="resource">The disposable resource.</param>
        /// <param name="body">The delegate used to construct the block of code.</param>
        /// <returns>The constructed expression.</returns>
        public static UsingExpression Create(Expression resource, Statement body)
        {
            var result = new UsingExpression(resource);

            result.Body = body(result.Resource);
            return(result);
        }