Skip to content

Instantly share code, notes, and snippets.

View IsEvenSourceGenerator.cs
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
namespace IsEvenSourceGenerator
{
[Generator]
View Program.cs
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace BenchmarkCore
{
class Program
{
static void Main(string[] args)
{
View WebServer.cs
/// ProcessRequest is called for every new request
public void ProcessRequest()
{
DoSomethingAsync().Wait();
}
View Program.cs
interface IInterface
{
void DoSomething();
}
class Implementation : IInterface
{
public void DoSomething()
{
// This method can't return a Task,
View ApiWebRequestFactoryTests.cs
/// <summary>
/// This test ensures that the ApiWebRequestFactory behaves correctly when
/// a different type of WebRequest is assigned to the http:// prefix
/// </summary>
[Fact]
public void OverrideHttpPrefix()
{
// Couldn't find a way to "officially" unregister a prefix but that shouldn't stop us
var prefixListProperty = typeof(WebRequest).GetProperty("PrefixList", BindingFlags.Static | BindingFlags.NonPublic);
var oldPrefixList = prefixListProperty.GetValue(null);
View ApiWebRequestFactory.cs
internal class ApiWebRequestFactory : IApiRequestFactory
{
public IApiRequest Create(Uri endpoint)
{
return new ApiWebRequest(WebRequest.CreateHttp(endpoint));
}
}
View Program.cs
WebRequest.RegisterPrefix("http://", new CustomWebRequestFactory());
View ApiWebRequestFactory.cs
internal class ApiWebRequestFactory : IApiRequestFactory
{
public IApiRequest Create(Uri endpoint)
{
return new ApiWebRequest((HttpWebRequest)WebRequest.Create(endpoint));
}
}
View KestrelTimeout.cs
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace KestrelTimeout
{
View StartupAssemblyLoadContext.cs
class StartupAssemblyLoadContext : AssemblyLoadContext
{
private readonly AssemblyDependencyResolver _resolver;
public StartupAssemblyLoadContext()
{
_resolver = new AssemblyDependencyResolver(Assembly.GetExecutingAssembly().Location);
}
protected override Assembly Load(AssemblyName assemblyName)