Skip to content

Instantly share code, notes, and snippets.

View rootn3rd's full-sized avatar

Pankaj Chaurasia rootn3rd

View GitHub Profile
@rootn3rd
rootn3rd / Program.cs
Created June 30, 2023 20:48
Specification Pattern Example
List<User> list = new()
{
new ("Raymond", 14, false),
new ("Shayna", 34, true),
new ("Vijay",20, false)
};
Console.WriteLine("\nSingle Expr--------");
ExpressionSpecification<User> exp = new(u => u.IsGraduated);
@rootn3rd
rootn3rd / Program.cs
Created February 22, 2023 17:24
WeakDelegate demo
using System;
using System.Diagnostics;
namespace WeakDelegate
{
// Containee needn't know anything about weak references, etc.
// It just fires its events as normal.
class Containee
{
public Containee(string id) { _id = id; }
@rootn3rd
rootn3rd / ExprGetter.cs
Created July 26, 2022 19:58
Expression based property setters
using BenchmarkDotNet.Attributes;
using System.Linq.Expressions;
BenchmarkDotNet.Running.BenchmarkRunner.Run<Runner>();
public class Runner
{
Person p = new Person() { Name = "Pankaj" };
[Benchmark]
public void SetUsingReflection()
@rootn3rd
rootn3rd / Program.cs
Created February 4, 2020 18:25
Fluent API Builder Quirks
using System;
using System.Linq.Expressions;
using System.Reflection;
namespace BuilderPattern
{
class Program
{
static void Main(string[] args)
{
@rootn3rd
rootn3rd / Quine.cs
Last active January 14, 2022 09:49
Quine C#
class Program
{
static void Main(string[] args)
{
var s = @"class Program {{
static void Main(string[] args) {{
var s = @{0}{1}{0};
System.Console.WriteLine(s, (char)34, s);
}}
}}";