View BearerPolicyEvaluator.cs
public sealed class BearerPolicyEvaluator : IPolicyEvaluator | |
{ | |
private const string Scheme = "Bearer"; | |
public Task<AuthenticateResult> AuthenticateAsync(AuthorizationPolicy _, HttpContext context) | |
{ | |
if (!context.Request.Headers.ContainsKey("Authorization")) | |
return Task.FromResult(AuthenticateResult.Fail("No Authorization header found!")); | |
string authHeader = context.Request.Headers["Authorization"]; |
View JsonContent.cs
public sealed class JsonContent : StreamContent | |
{ | |
private static MediaTypeHeaderValue JsonMediaType => new MediaTypeHeaderValue("application/json"); | |
public JsonContent(Stream stream) : base(stream) | |
{ | |
Headers.ContentType = JsonMediaType; | |
} | |
public static JsonContent Create(object value) |
View IntegerArray.cs
using System; | |
using System.Collections.Generic; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Order; | |
using BenchmarkDotNet.Running; | |
namespace App | |
{ | |
public sealed class Program | |
{ |
View RepositoryPattern.cs
//Insert new record to database | |
public interface ICreatableRepository<T> | |
{ | |
int Create(T value); | |
} | |
//List records | |
public interface IListableRepository<T> | |
{ | |
IList<T> List(DataParameterDictionary dataParameters); |
View FeedPagerService.cs
internal static class FeedPagerService | |
{ | |
private const int PageSize = 10; | |
internal static (List<FeedItem> feeds, int pageSize, int maxRecords) SkipRecords(int pageIndex, List<FeedItem> feeds) | |
{ | |
if (pageIndex < 0) pageIndex = 0; //fix negative | |
var startPage = pageIndex <= 1 ? 0 : (pageIndex - 1) * PageSize; |
View Extensions.cs
using static System.Net.HttpStatusCode; | |
internal static class Extensions | |
{ | |
internal static string AsString(this HttpStatusCode status) => status switch | |
{ | |
Continue => nameof(Continue), | |
SwitchingProtocols => nameof(SwitchingProtocols), | |
Processing => nameof(Processing), | |
EarlyHints => nameof(EarlyHints), |
View Logger.cs
internal sealed class Logger : ILogger | |
{ | |
private readonly FileStream _writer = new FileStream(Config.Configuration["LogFile"], FileMode.Create, FileAccess.Write, | |
FileShare.None, 1024, FileOptions.SequentialScan); | |
private readonly UTF8Encoding _utf = new UTF8Encoding(true); | |
private readonly byte[] _line; | |
internal Logger() => _line = _utf.GetBytes(Environment.NewLine); |
View Sample.ps1
([system.reflection.assembly]::loadfile("")).FullName |
View PropertySetter.cs
using System; | |
using System.Collections.Generic; | |
using System.Linq.Expressions; | |
using System.Reflection; | |
internal sealed class PropertySetter<T> | |
{ | |
private const BindingFlags Flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase; | |
private readonly Type _type = typeof(T); |
NewerOlder