Skip to content

Instantly share code, notes, and snippets.

View bleroy's full-sized avatar

Bertrand Le Roy bleroy

View GitHub Profile
var mc = new MyClass
{
Age = 23,
FirstName = "Bertrand",
LastName = "Le Roy",
};
var bytes = MessagePackSerializer.Serialize(mc);
var mc2 = MessagePackSerializer.Deserialize<MyClass>(bytes);
[MessagePackObject]
public class MyClass
{
// Key is serialization index, it is important for versioning.
[Key(0)]
public int Age { get; set; }
[Key(1)]
public string FirstName { get; set; }
@bleroy
bleroy / WeekIn.NET.20170320.md
Last active June 4, 2017 20:55
Tips for the Week in .NET
@bleroy
bleroy / WeekIn.NET.20170314.md
Last active November 19, 2022 23:59
Tips for the Week in .NET
@bleroy
bleroy / WeekIn.NET.20170307.md
Last active March 6, 2017 12:27
Tips for the Week in .NET
from d in data.ToInjectable()
select new
{
Id = d.Id,
Value = d.Name.LimitText(10)
}
[InjectLambda]
public static string LimitText(this string value, int maxLength)
{
if (value != null && value.Length > maxLength)
return value.Substring(0, maxLength);
return value;
}
public static Expression<Func<string, int, string>> LimitText()
{
@bleroy
bleroy / WeekIn.NET.20170228.md
Last active February 27, 2017 22:42
Tips for the Week in .NET
using PhotoSauce.MagicScaler;
const int size = 150;
const int quality = 75;
var settings = new ProcessImageSettings() {
Width = size,
Height = size,
ResizeMode = CropScaleMode.Max,
SaveFormat = FileFormat.Jpeg,
string[] history = new string[] { "ls -a", "dotnet run", "git init" };
ReadLine.AddHistory(history);
ReadLine.AutoCompletionHandler = (t, s) =>
{
if (t.StartsWith("git"))
return new string[] { "init", "clone", "pull", "push" };
else
return null;
};