This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // See https://aka.ms/new-console-template for more information | |
| using BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Running; | |
| using System.Runtime.CompilerServices; | |
| using System.Runtime.InteropServices; | |
| BenchmarkRunner.Run<Benchmarks>(); | |
| public class Benchmarks | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.AspNetCore.TestHost; | |
| var builder = WebApplication.CreateBuilder(args); | |
| builder.WebHost.UseTestServer(); | |
| var app = builder.Build(); | |
| var group = app.MapGroup("/"); | |
| group.AddEndpointFilter(async (efiContext, next) => | |
| { | |
| var result = await next(efiContext); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class ServiceCollectionExtensions | |
| { | |
| internal static readonly string ModulesKey = "Modules"; | |
| public static IServiceCollection AddModules(this IServiceCollection serviceCollection, HostBuilderContext builderContext) | |
| { | |
| var modulesSection = builderContext.Configuration.GetSection(ModulesKey); | |
| foreach (var moduleName in modulesSection.GetChildren()) | |
| { | |
| var type = Type.GetType(moduleName.Value, true, false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Security.Cryptography; | |
| var time = DateTime.Now; | |
| var files = Directory.EnumerateFiles("C:\\Program Files (x86)\\Steam", "*", SearchOption.AllDirectories) | |
| .AsParallel() | |
| .Select(p => new FileInfo(p)) | |
| .GroupBy(p => p.Length) | |
| .Where(p => p.Count() > 1 && p.Key > 0) | |
| .SelectMany(p => p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Converter : JsonConverterFactory | |
| { | |
| public override bool CanConvert(Type typeToConvert) | |
| { | |
| return typeToConvert | |
| .GetInterfaces() | |
| .Any(p => p.IsGenericType && p.GetGenericTypeDefinition() == typeof(IFloatingPoint<>)); | |
| } | |
| public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [JsonConverter(typeof(MyConverter))] | |
| record My(string? String, int? Number); | |
| class MyConverter : JsonConverter<My> | |
| { | |
| public override My? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| { | |
| if (reader.TokenType != JsonTokenType.StartArray) | |
| throw new JsonException(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async Task Main() | |
| { | |
| var hb = new HostBuilder(); | |
| hb | |
| .ConfigureAppConfiguration(p => p.AddInMemoryCollection(new Dictionary<string, string> { { "Property", "Value" } })) | |
| .ConfigureServices(s => | |
| { | |
| s.AddSingleton(typeof(IConfigureOptions<>), typeof(Confgiuration<>)); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class InstantConverter : IMappingSchemaConverter<Instant, DateTime> | |
| { | |
| private readonly DateTimeZone _currentZone; | |
| public InstantConverter(IConfiguration config, ILogger<InstantConverter> logger) | |
| { | |
| var zoneName = config.GetValue<string>(ViewConfigurationExtensions.DefaultTimezoneConfigurationKey); | |
| var systemDefaultTimeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); | |
| if (!string.IsNullOrEmpty(zoneName)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Reflection; | |
| using System.Text.Json; | |
| using System.Text.Json.Serialization; | |
| var data = new A[] { new B { PropA = "A-B", PropB = "B-B" }, new C { PropA = "A-C", PropC = "C-C" } }; | |
| var options = new JsonSerializerOptions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static async IAsyncEnumerable<ReadOnlySequence<byte>> GetJsonAsync(PipeReader reader, [EnumeratorCancellation] CancellationToken cancellationToken = default) | |
| { | |
| var state = new JsonReaderState(new JsonReaderOptions() { AllowTrailingCommas = true }); | |
| try | |
| { | |
| while (true) | |
| { | |
| var rr = await reader.ReadAsync(cancellationToken); | |
| var buffer = rr.Buffer; |