Skip to content

Instantly share code, notes, and snippets.

View richlander's full-sized avatar

Rich Lander richlander

View GitHub Profile
@richlander
richlander / implicit-quotation-method-arguments.fs
Created July 20, 2015 17:25
Implicit quotation of method arguments
type Test =
static member EchoExpression([<ReflectedDefinition(true)>] x : Expr<_>) =
let expression, value = (* decompose AST of x *)
printfn "%s evaluates to %O" expression value
let x, y, z = 42, 89.0, 92.5
Test.EchoExpression(x) // "x evaluates to 42"
Test.EchExpression(Math.Max(y, z)) // "Math.Max(y, z) evaluates to 92.5"
@richlander
richlander / vs2015-enc-csharp.cs
Created July 20, 2015 17:39
Example of supported C# syntax for EnC in Visual Studio 2015
public MainWindow()
{
InitializeComponent();
Loaded += async (o, e) => {
await Task.Delay(1000);
_strings = new string[] { "EnC now supports more features!", "Thanks to Roslyn!"};
label.Content = (from str in _strings
where str.StartsWith("Enc")
select str).FirstOrDefault();
@richlander
richlander / csharp-static-imports.cs
Created July 20, 2015 17:42
C# 6 Static Imports
using static System.Console;
using static System.Math;
using static System.DayOfWeek;
class Program
{
static void Main()
{
WriteLine(Sqrt(3 * 3 + 4 * 4));
WriteLine(Friday - Monday);
@richlander
richlander / vb-static-imports.vb
Created July 20, 2015 17:43
VB Static Imports
Imports System.Console
Imports System.Math
Imports System.DateOfWeek
Module Program
Sub Main()
WriteLine(Sqrt(3 * 3 + 4 * 4))
WriteLine(Friday - Monday)
End Sub
End Module
@richlander
richlander / multi-line-string-literals.vb
Created July 20, 2015 17:44
VB Multiline string literals
Dim s = "Write your haiku with
No vbCrLf
In VB14"
@richlander
richlander / csharp-multiline-string-literals.cs
Created July 20, 2015 17:47
C# Multiline String Literals
var s = @"Write your haiku with
No \r\n escapes
In C# v1";
@richlander
richlander / vb-read-only-auto-properties.vb
Created July 20, 2015 17:49
VB Read-only Auto-Properties
Public Class Customer
Public ReadOnly Property First As String = "Jane"
Public ReadOnly Property Last As String = "Doe"
End Class
@richlander
richlander / csharp-string-interpolation.cs
Created July 20, 2015 17:52
C# 6 String Interpolation
var s = $"{p.Name} is {p.Age} year{{s}} old";
@richlander
richlander / vb-string-interpolation.vb
Created July 20, 2015 17:54
VB String Interpolation
Dim s = $"{p.Name} is {p.Age} year{{s}} old"
@richlander
richlander / csharp-null-conditional-operator.cs
Created July 20, 2015 17:56
Null-Conditional operator (?.)
int length = customers?.Length ?? 0; // 0 if customers is null