Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Threading.Tasks;
using System;
using System.Net.Http;
async Task Main()
{
var isAvailable = await IsArticleAvailable();
Console.WriteLine(isAvailable);
}
async Task<bool> IsArticleAvailable()
{
var articlePath = "/blog/clean-code-error-handling";
return await IsPathAvailable(articlePath);
}
async Task<bool> IsPathAvailable(string articlePath)
{
var baseUrl = "https://www.code4it.dev/";
return await IsResourceAvailable(baseUrl, articlePath);
}
async Task<bool> IsResourceAvailable(string baseUrl, string articlePath)
{
using (HttpClient client = new HttpClient() { BaseAddress = new Uri(baseUrl) })
{
HttpResponseMessage response = await client.GetAsync(articlePath);
return response.IsSuccessStatusCode;
}
}
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[CompilerGenerated]
internal static class <Program>$
{
private sealed class <<<Main>$>g__Main|0_0>d : IAsyncStateMachine
{
public int <>1__state;
public AsyncTaskMethodBuilder <>t__builder;
private bool <isAvailable>5__1;
private bool <>s__2;
private TaskAwaiter<bool> <>u__1;
private void MoveNext()
{
int num = <>1__state;
try
{
TaskAwaiter<bool> awaiter;
if (num != 0)
{
awaiter = <<Main>$>g__IsArticleAvailable|0_1().GetAwaiter();
if (!awaiter.IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
<<<Main>$>g__Main|0_0>d stateMachine = this;
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter<bool>);
num = (<>1__state = -1);
}
<>s__2 = awaiter.GetResult();
<isAvailable>5__1 = <>s__2;
Console.WriteLine(<isAvailable>5__1);
}
catch (Exception exception)
{
<>1__state = -2;
<>t__builder.SetException(exception);
return;
}
<>1__state = -2;
<>t__builder.SetResult();
}
void IAsyncStateMachine.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
this.MoveNext();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
}
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
{
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
this.SetStateMachine(stateMachine);
}
}
private sealed class <<<Main>$>g__IsArticleAvailable|0_1>d : IAsyncStateMachine
{
public int <>1__state;
public AsyncTaskMethodBuilder<bool> <>t__builder;
private string <articlePath>5__1;
private bool <>s__2;
private TaskAwaiter<bool> <>u__1;
private void MoveNext()
{
int num = <>1__state;
bool result;
try
{
TaskAwaiter<bool> awaiter;
if (num != 0)
{
<articlePath>5__1 = "/blog/clean-code-error-handling";
awaiter = <<Main>$>g__IsPathAvailable|0_2(<articlePath>5__1).GetAwaiter();
if (!awaiter.IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
<<<Main>$>g__IsArticleAvailable|0_1>d stateMachine = this;
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter<bool>);
num = (<>1__state = -1);
}
<>s__2 = awaiter.GetResult();
result = <>s__2;
}
catch (Exception exception)
{
<>1__state = -2;
<articlePath>5__1 = null;
<>t__builder.SetException(exception);
return;
}
<>1__state = -2;
<articlePath>5__1 = null;
<>t__builder.SetResult(result);
}
void IAsyncStateMachine.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
this.MoveNext();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
}
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
{
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
this.SetStateMachine(stateMachine);
}
}
private sealed class <<<Main>$>g__IsPathAvailable|0_2>d : IAsyncStateMachine
{
public int <>1__state;
public AsyncTaskMethodBuilder<bool> <>t__builder;
public string articlePath;
private string <baseUrl>5__1;
private bool <>s__2;
private TaskAwaiter<bool> <>u__1;
private void MoveNext()
{
int num = <>1__state;
bool result;
try
{
TaskAwaiter<bool> awaiter;
if (num != 0)
{
<baseUrl>5__1 = "https://www.code4it.dev/";
awaiter = <<Main>$>g__IsResourceAvailable|0_3(<baseUrl>5__1, articlePath).GetAwaiter();
if (!awaiter.IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
<<<Main>$>g__IsPathAvailable|0_2>d stateMachine = this;
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter<bool>);
num = (<>1__state = -1);
}
<>s__2 = awaiter.GetResult();
result = <>s__2;
}
catch (Exception exception)
{
<>1__state = -2;
<baseUrl>5__1 = null;
<>t__builder.SetException(exception);
return;
}
<>1__state = -2;
<baseUrl>5__1 = null;
<>t__builder.SetResult(result);
}
void IAsyncStateMachine.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
this.MoveNext();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
}
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
{
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
this.SetStateMachine(stateMachine);
}
}
private sealed class <<<Main>$>g__IsResourceAvailable|0_3>d : IAsyncStateMachine
{
public int <>1__state;
public AsyncTaskMethodBuilder<bool> <>t__builder;
public string baseUrl;
public string articlePath;
private HttpClient <client>5__1;
private HttpResponseMessage <response>5__2;
private HttpResponseMessage <>s__3;
private TaskAwaiter<HttpResponseMessage> <>u__1;
private void MoveNext()
{
int num = <>1__state;
bool isSuccessStatusCode;
try
{
if (num != 0)
{
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(baseUrl);
<client>5__1 = httpClient;
}
try
{
TaskAwaiter<HttpResponseMessage> awaiter;
if (num != 0)
{
awaiter = <client>5__1.GetAsync(articlePath).GetAwaiter();
if (!awaiter.IsCompleted)
{
num = (<>1__state = 0);
<>u__1 = awaiter;
<<<Main>$>g__IsResourceAvailable|0_3>d stateMachine = this;
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
return;
}
}
else
{
awaiter = <>u__1;
<>u__1 = default(TaskAwaiter<HttpResponseMessage>);
num = (<>1__state = -1);
}
<>s__3 = awaiter.GetResult();
<response>5__2 = <>s__3;
<>s__3 = null;
isSuccessStatusCode = <response>5__2.IsSuccessStatusCode;
}
finally
{
if (num < 0 && <client>5__1 != null)
{
((IDisposable)<client>5__1).Dispose();
}
}
}
catch (Exception exception)
{
<>1__state = -2;
<>t__builder.SetException(exception);
return;
}
<>1__state = -2;
<>t__builder.SetResult(isSuccessStatusCode);
}
void IAsyncStateMachine.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
this.MoveNext();
}
[DebuggerHidden]
private void SetStateMachine(IAsyncStateMachine stateMachine)
{
}
void IAsyncStateMachine.SetStateMachine(IAsyncStateMachine stateMachine)
{
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
this.SetStateMachine(stateMachine);
}
}
private static void <Main>$(string[] args)
{
}
[AsyncStateMachine(typeof(<<<Main>$>g__Main|0_0>d))]
[DebuggerStepThrough]
internal static Task <<Main>$>g__Main|0_0()
{
<<<Main>$>g__Main|0_0>d stateMachine = new <<<Main>$>g__Main|0_0>d();
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[AsyncStateMachine(typeof(<<<Main>$>g__IsArticleAvailable|0_1>d))]
[DebuggerStepThrough]
internal static Task<bool> <<Main>$>g__IsArticleAvailable|0_1()
{
<<<Main>$>g__IsArticleAvailable|0_1>d stateMachine = new <<<Main>$>g__IsArticleAvailable|0_1>d();
stateMachine.<>t__builder = AsyncTaskMethodBuilder<bool>.Create();
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[AsyncStateMachine(typeof(<<<Main>$>g__IsPathAvailable|0_2>d))]
[DebuggerStepThrough]
internal static Task<bool> <<Main>$>g__IsPathAvailable|0_2(string articlePath)
{
<<<Main>$>g__IsPathAvailable|0_2>d stateMachine = new <<<Main>$>g__IsPathAvailable|0_2>d();
stateMachine.<>t__builder = AsyncTaskMethodBuilder<bool>.Create();
stateMachine.articlePath = articlePath;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[AsyncStateMachine(typeof(<<<Main>$>g__IsResourceAvailable|0_3>d))]
[DebuggerStepThrough]
internal static Task<bool> <<Main>$>g__IsResourceAvailable|0_3(string baseUrl, string articlePath)
{
<<<Main>$>g__IsResourceAvailable|0_3>d stateMachine = new <<<Main>$>g__IsResourceAvailable|0_3>d();
stateMachine.<>t__builder = AsyncTaskMethodBuilder<bool>.Create();
stateMachine.baseUrl = baseUrl;
stateMachine.articlePath = articlePath;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
}
{
"version": 1,
"target": "C#",
"mode": "Debug"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment