This file contains 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
char[] array1 = ['b', 'c']; | |
char[] array2 = ['d', 'e']; | |
char[] mergedArray = ['a', .. array1, .. array2, 'f']; | |
Console.WriteLine(string.Join(",", mergedArray)); // Output: a, b, c, d, e, f | |
var list1 = new List<int> { 1, 2 }; | |
List<int> mergedList = [ ..list1, 3 ]; | |
Console.WriteLine(string.Join(",", mergedList)); // Output: 1, 2, 3 |
This file contains 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.Server.HttpSys; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddHttpContextAccessor(); | |
builder.WebHost.UseHttpSys(options => | |
{ | |
options.AllowSynchronousIO = false; | |
options.Authentication.Schemes = AuthenticationSchemes.None; |
This file contains 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
namespace Microsoft.AspNetCore.Server.HttpSys | |
{ | |
public interface IHttpSysRequestTimingFeature | |
{ | |
ReadOnlySpan<long> Timestamps { get; } | |
bool TryGetTimestamp(HttpSysRequestTimingType timestampType, out long timestamp); | |
bool TryGetElapsedTime(HttpSysRequestTimingType startingTimestampType, HttpSysRequestTimingType endingTimestampType, out TimeSpan elapsed); | |
} | |
} |
This file contains 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 DemoAspNetCore8.ErrorHandling; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddExceptionHandler<TimeOutExceptionHandler>(); | |
builder.Services.AddExceptionHandler<DefaultExceptionHandler>(); | |
var app = builder.Build(); | |
app.UseExceptionHandler(opt => { }); |
This file contains 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.Diagnostics; | |
using Microsoft.AspNetCore.Mvc; | |
using System.Net; | |
namespace DemoAspNetCore8.ErrorHandling; | |
public class TimeOutExceptionHandler : IExceptionHandler | |
{ | |
private readonly ILogger<DefaultExceptionHandler> _logger; | |
public TimeOutExceptionHandler(ILogger<DefaultExceptionHandler> logger) |
This file contains 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 DemoAspNetCore8.ErrorHandling; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddExceptionHandler<DefaultExceptionHandler>(); | |
var app = builder.Build(); | |
app.UseExceptionHandler(opt => { }); |
This file contains 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.Diagnostics; | |
using Microsoft.AspNetCore.Mvc; | |
using System.Net; | |
namespace DemoAspNetCore8.ErrorHandling; | |
public class DefaultExceptionHandler : IExceptionHandler | |
{ | |
private readonly ILogger<DefaultExceptionHandler> _logger; | |
public DefaultExceptionHandler(ILogger<DefaultExceptionHandler> logger) |
This file contains 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 class Product(string name, int categoryId) | |
{ | |
public Product() : this("Default", -1) { ProductDescription = "InvalidProductId"; } | |
public Product(string name) : this(name, 0) { } | |
public string Name => name; | |
public int CategoryId => categoryId; | |
public string ProductDescription { get; private set; } | |
} |
This file contains 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
var product1 = new Product(); | |
var product2 = new Product("Basic"); | |
var product3 = new Product("My product", 1); | |
public class Product(string name, int categoryId) | |
{ | |
public Product() : this("Default", -1) { } | |
public Product(string name) : this(name, 0) {} |
This file contains 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 (HttpClient client = new HttpClient()) | |
using (HttpResponseMessage response = await client.PatchAsJsonAsync("http://someuri.com", new { Name = "Anthony" })) | |
using (HttpContent content = response.Content) | |
{ | |
string result = await content.ReadAsStringAsync(); | |
} |
NewerOlder