Skip to content

Instantly share code, notes, and snippets.

@demaderios
demaderios / ServiceExtensions.cs
Last active May 21, 2020 19:22
Custom .Net Core policy using Func
public static void ConfigureAuthorization(this IServiceCollection services)
{
services.AddAuthorization(options =>
{
options.AddPolicy("CanAccessSuperTopSecretArea", policy =>
{
context => context.User.HasClaim(claim => claim.Type == "TopSecretUser" || claim.Type == "OtherTopSecretUser" ||
context.User.IsInRole("SupremeOverlord"))
}
}
@demaderios
demaderios / RegularExpressionExtractor.cs
Last active May 21, 2020 19:13
C# regular expression extractor
public static List<string> RegularExpressionExtractor(string input, string regexpattern)
{
var regexPatternToMatch = new Regex(regexpattern);
var listOfResults = regexPatternToMatch.Matches(input)
.Cast<Match>()
.Select(m => m.Value)
.ToList();
return listOfResults;
}