pulumi/sdk/dotnet/Pulumi.Automation/PulumiFn.TStack.cs
Sean Fausett 3530ba3205
[dotnet] Fix Resharper code issues (#7178)
* Fix resharper code issues for language usage opportunities

* Fix resharper code issues for common practices and code improvements

* Fix resharper code issues for potential code quality issues

* Fix resharper code issues for redundancies in code

* Fix xunit test output

* Update changelog

* Fix resharper code issues for compiler warnings

* Fix resharper code issues for inconsistent naming

* Add resharper solution settings file

* Fix resharper code issues for potential code quality issues

* Fix resharper code issues for redundancies in code

* Fix resharper code issues for redundancies in symbol declarations
2021-06-10 10:32:33 -04:00

51 lines
1.6 KiB
C#

// Copyright 2016-2021, Pulumi Corporation
using System;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
namespace Pulumi.Automation
{
internal class PulumiFn<TStack> : PulumiFn where TStack : Stack
{
private readonly Func<TStack> _stackFactory;
public PulumiFn(Func<TStack> stackFactory)
{
this._stackFactory = stackFactory;
}
internal override async Task<ExceptionDispatchInfo?> InvokeAsync(IRunner runner, CancellationToken cancellationToken)
{
ExceptionDispatchInfo? info = null;
await runner.RunAsync(() =>
{
try
{
return this._stackFactory();
}
// because we are newing a generic, reflection comes in to
// construct the instance. And if there is an exception in
// the constructor of the user-provided TStack, it will be wrapped
// in TargetInvocationException - which is not the exception
// we want to throw to the consumer.
catch (TargetInvocationException ex) when (ex.InnerException != null)
{
info = ExceptionDispatchInfo.Capture(ex.InnerException);
throw;
}
catch (Exception ex)
{
info = ExceptionDispatchInfo.Capture(ex);
throw;
}
}).ConfigureAwait(false);
return info;
}
}
}