Skip to content

Instantly share code, notes, and snippets.

View leandromoh's full-sized avatar
💭
Talk is Cheap, Show me the code!

Leandro Fernandes leandromoh

💭
Talk is Cheap, Show me the code!
View GitHub Profile
@leandromoh
leandromoh / ReadOnlySpan<char> to Enum.cs
Last active December 19, 2021 04:57
Converts ReadOnlySpan<char> to Enum generating an expression tree #3
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Linq;
using System.Linq.Expressions;
// ``` ini
//
// BenchmarkDotNet=v0.13.1, OS=Windows 10.0.18363.1440 (1909/November2019Update/19H2)
static void Resultado()
{
var updates = new[]
{
new Data { Name = "A1", ReferenceDate = DateTime.Today },
new Data { Name = "B1", ReferenceDate = DateTime.Today },
new Data { Name = "C1", ReferenceDate = DateTime.Today },
new Data { Name = "D1", ReferenceDate = DateTime.Today },
new Data { Name = "A2", ReferenceDate = DateTime.Today.AddMinutes(10) },
@leandromoh
leandromoh / mixin example.cs
Last active August 26, 2020 15:37
generate a type that inherit some type and implements a decorator pattern for interfaces
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace ConsoleApp3
{
static class Program
{
@leandromoh
leandromoh / NullPropagationVisitor.cs
Last active December 10, 2023 02:38
visitor that modify expression tree for safe null propagation! This code is now maintained in https://github.com/leandromoh/NullPropagationVisitor
using System;
using System.Diagnostics;
using System.Linq.Expressions;
namespace ConsoleApp3
{
static class Program
{
private static string Foo(string s) => s;
@leandromoh
leandromoh / Anonymous type with Expression.cs
Created June 9, 2020 15:00
Anonymous extension method that allow create a new instance of anonymous with new values, similar to with expression of records in C# and F#
public static class AnonymousExtension
{
static void Main(string[] args)
{
var person = new { FirstName = "Scott", LastName = "Hunter", Sex = 'M', Age = 25 };
var otherPerson = person.With(new { LastName = "Hanselman" });
Console.WriteLine(otherPerson);
}
<div id="Estados" class="timeline p-25">
<div class="t-view m-0 m-t-20 Estados">
<input type="hidden" name="Estados.index" autocomplete="off" value="30f0929e-f646-4f3c-a7a6-d432c1b0ce5a">
<div class="tv-header media m-0 p-20">
<ul class="actions">
<li>
<a href="#" onclick="return false;" class="deleteRow">
<i class="zmdi zmdi-delete"></i>
http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-part-1/
https://mleeb.wordpress.com/2013/11/23/editing-nested-lists-in-asp-mvc-4/
http://www.joe-stevens.com/2011/06/06/editing-and-binding-nested-lists-with-asp-net-mvc-2/
http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-1
http://nadeemkhedr.com/how-the-unobtrusive-jquery-validate-plugin-works-internally-in-asp-net-mvc/
public static SelectList ToSelectList<T, A>(this IEnumerable<T> source, Func<T, A> valueSelector, Func<T, string> textSelector, A? selectdOption = null, string nullOption = "Todos")
where T : class
where A : struct
{
var descriptions = source.ToDictionary(valueSelector, textSelector);
var ordered = descriptions.OrderBy(i => i.Value).Select(i => new KeyValuePair<A?, string>(i.Key, i.Value));
var defaul = Enumerable.Repeat(new KeyValuePair<A?, string>(null, nullOption), 1);
return new SelectList(defaul.Concat(ordered), "Key", "Value", selectdOption ?? defaul.First().Key);
preprocessor directives
goto
operator overload
pointer
methods not virtual by default
unsigned integer types
user-defined casts
output parameters
destructor
CountBy;
AtLeast, AtMost, Exactly & CountBetween;
Sequence
Repeat
SkipLast
AggregateRight
Unfold
ScanRight
PadLeft
Move