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 DatabaseQueryResult<T> | |
{ | |
private enum ResultType | |
{ | |
Found, | |
Empty, | |
ClientError, | |
ServerError | |
} | |
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 Encryption(IJSRuntime jsRuntime) | |
{ | |
public async Task<string> GetEncryptionKeyAsync() => | |
await jsRuntime.InvokeAsync<string>("getEncryptionKey") ?? string.Empty; | |
public async Task<string> EncryptAsync(string value) => | |
await jsRuntime.InvokeAsync<string>("encrypt", value) ?? string.Empty; | |
public async Task<string> DecryptAsync(string value) => | |
await jsRuntime.InvokeAsync<string>("decrypt", value) ?? string.Empty; |
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 static class DatabaseMigrator | |
{ | |
static NpgsqlCommand GetCommand(string query, NpgsqlConnection connection, NpgsqlTransaction? transaction) | |
{ | |
var command = connection.CreateCommand(); | |
command.Connection = connection; | |
command.CommandText = query; | |
if (transaction is not null) |
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 JSONValue {} | |
public class JSONObject : JSONValue | |
{ | |
public Dictionary<string, JSONValue> Pairs { get; set; } | |
public JSONObject(IEnumerable<KeyValuePair<string, JSONValue>> pairs) | |
{ | |
Pairs = new Dictionary<string, JSONValue>(); | |
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 static class SwitchExtensions | |
{ | |
public static TReturn Switch<TInput, TReturn>(this TInput input, params (Predicate<TInput> check, Func<TInput, TReturn> value)[] cases) => | |
Switch(input, c => default, cases); | |
public static TReturn Switch<TInput, TReturn>(this TInput input, Func<TInput, TReturn> defaultCase, params (Predicate<TInput> check, Func<TInput, TReturn> value)[] cases) => | |
cases | |
.Concat(new (Predicate<TInput> check, Func<TInput, TReturn> value)[] { (c => true, defaultCase) }) | |
.First(c => c.check(input)) | |
.value(input); |
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
This is a test cla |
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 static class ClaimsExtensions | |
{ | |
public static string GetClaimValue(this HttpContext context, string type) | |
{ | |
if (context.User.Identity is ClaimsIdentity id) | |
{ | |
if (id.Claims.FirstOrDefault(c => c.Type == type) is Claim claim) | |
{ | |
return claim.Value; | |
} |
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 static class ClaimsExtensions | |
{ | |
public static string GetClaimValue(this HttpContext context, string type) | |
{ | |
if (context.User.Claims.FirstOrDefault(c => c.Type == type) is Claim claim) | |
{ | |
return claim.Value; | |
} | |
else throw new ArgumentException(type + " is not found in claims."); | |
} |
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
<html> | |
<body> | |
<table cellpadding="0" cellspacing="0" width="100%" height="100%"> | |
<tr> | |
<td width="100%" height="100%" valign="center"> | |
<center> | |
<img src="image.png"/> | |
</center> | |
</td> | |
</tr> |
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
//in Parse.cs | |
public static Parser<U> EnumerateInput<T, U>(IEnumerable<T> input, Func<T, Parser<U>> parser) | |
{ | |
if (input == null) throw new ArgumentNullException("input"); | |
if (parser == null) throw new ArgumentNullException("parser"); | |
return EnumerateInput(input.ToArray(), parser); | |
} | |
public static Parser<U> EnumerateInput<T, U>(T[] input, Func<T, Parser<U>> parser) |
NewerOlder