Skip to content

Instantly share code, notes, and snippets.

View richlander's full-sized avatar

Rich Lander richlander

View GitHub Profile
@richlander
richlander / vb-null-conditional-operator.vb
Created July 20, 2015 17:57
Null-Conditional operator (?.)
Dim length As Integer = If(customers?.Length, 0) ' 0 if customers is null
@richlander
richlander / csharp-nameof-operator.cs
Created July 20, 2015 17:57
C# 6 NameOf operator
if (x == null) throw new ArgumentNullException(nameof(x));
@richlander
richlander / vb-nameof-operator.vb
Created July 20, 2015 17:58
VB NameOf operator
If x Is Nothing Then Throw New ArgumentNullException(NameOf(x))
@richlander
richlander / csharp-read-only-auto-properties.cs
Created July 20, 2015 19:06
C# 6 Read-only Auto-Properties
public class Customer
{
public string First { get; } = "Jane";
public string Last { get; } = "Doe";
}
@richlander
richlander / fsharp-tail-call.fs
Created July 28, 2015 18:00
F# repro code for RyuJit tail call issue.
open System
type T() =
member __.F1(arg1 : string byref, arg2, arg3 : Nullable<int>, arg4 : bool) =
arg1 <- arg1
__.F2(arg1, arg2, arg3, arg4)
member __.F2(_ : string, _ : obj, arg : Nullable<int>, _ : bool) =
Console.WriteLine("{0}", arg) // prints "random" number
@richlander
richlander / ryujit-tail-call.cs
Created July 28, 2015 22:06
Annotated C# repro code for RyuJit tail call issue
// This repro documents a minimal example of the RyuJIT tail call issue (July 2015).
// All of the characteristics described in the repro need to be present to trigger the bad codegen.
using System;
// Simple struct containing two integers (size 8).
struct MyStruct
{
public MyStruct(int a, int b)
{
A = a;
@richlander
richlander / adaptive-csharp-winrt.cs
Created July 30, 2015 17:10
Adaptive C# code for WinRT
async Task SetupAsync()
{
if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
{
await StatusBar.GetForCurrentView().HideAsync();
}
}
@richlander
richlander / expression-tree.cs
Created September 28, 2015 15:18
Expression tree code that required (and got) a fix with .NET Native
Expression<Func<int>> e = () => 1;
e = e.Update(Expression.Constant(2), null);
int i = e.Compile().Invoke(); // should return "2"
@richlander
richlander / dotnet-native-shared-framework-directive.xml
Created September 28, 2015 18:34
Instructions to opt-in to using the .NET Native Shared Framework
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<UseDotNetNativeSharedAssemblyFrameworkPackage>true</UseDotNetNativeSharedAssemblyFrameworkPackage>
@richlander
richlander / getting-started-core.md
Last active December 14, 2016 16:00
Getting Started Writing a .NET Core app and Class Library

Getting Started Writing a .NET Core app and Class Library

These instructions are basic and a work in progress. They will be improving a lot over time.

Once you've followed the steps in this document, use the following sample to see the changes you need to make to your project: https://github.com/dotnet/corefxlab/tree/master/samples/ClassLib.

Installing the tools