Skip to content

Instantly share code, notes, and snippets.

Avatar

Jb Evain jbevain

View GitHub Profile
@jbevain
jbevain / roslyn-enumerable-of-t.diff
Last active Aug 29, 2015
Roslyn patch to add syntactic sugar to C# replacing IEnumerable<T> with T~
View roslyn-enumerable-of-t.diff
diff --git a/Src/Compilers/CSharp/Source/Binder/Binder_Symbols.cs b/Src/Compilers/CSharp/Source/Binder/Binder_Symbols.cs
index ce0a903..b34b498 100644
--- a/Src/Compilers/CSharp/Source/Binder/Binder_Symbols.cs
+++ b/Src/Compilers/CSharp/Source/Binder/Binder_Symbols.cs
@@ -379,6 +379,20 @@ namespace Microsoft.CodeAnalysis.CSharp
return new PointerTypeSymbol(elementType);
}
+ case SyntaxKind.EnumerableType:
+ {
View sizeof.cs
using System;
using System.Reflection.Emit;
static class SizeOf<TStruct> where TStruct : struct
{
public static readonly int Value;
static SizeOf()
{
var method = new DynamicMethod("", typeof(int), Type.EmptyTypes);
@jbevain
jbevain / gist:c42dd13616117b9cd5a7
Last active Aug 29, 2015
VSTU sample of Expression Evaluation tests
View gist:c42dd13616117b9cd5a7
[Test]
public void StructInstanceMembers()
{
AssertExpressionsAtLine(21, "Types.cs", new Evaluations
{
{ "one",
Expect("one", Quoted("<X:1 Y:1 Z:1>"), "Victor",
Expect("X", "1f", "System.Single"),
Expect("Y", "1f", "System.Single"),
Expect("Z", "1f", "System.Single"))
@jbevain
jbevain / gist:933a81871c55e716f208
Last active Aug 29, 2015
Allocating strings from unmanaged memory
View gist:933a81871c55e716f208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
namespace StringPool
{
View TypedRef.cs
using System;
using System.Reflection;
using System.Reflection.Emit;
static class TypedRef
{
public static TClass RoundTrip<TClass>(TClass instance) where TClass : class
{
var method = new DynamicMethod("", typeof(TClass), new [] {typeof(TClass)}, true);
var il = method.GetILGenerator();
@jbevain
jbevain / NamespaceProjectHook.cs
Created Nov 26, 2014
Project Generation Hook to insert namespace in the project files
View NamespaceProjectHook.cs
using System;
using UnityEngine;
using UnityEditor;
using SyntaxTree.VisualStudio.Unity.Bridge;
[InitializeOnLoad]
public class NamespaceProjectHook
{
View test.rs
#![feature(lang_items)]
#![allow(unstable)]
#![allow(non_camel_case_types)]
extern crate libc;
extern crate unicode;
mod w32 {
use libc::types::os::arch::extra::{HANDLE, LPCWSTR};
View a.The Code You Run.cs
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, CoreCLR!");
}
}
@jbevain
jbevain / TinySwitch.cs
Last active Aug 29, 2015
Switch opcode size analyser for CoreCLR #918
View TinySwitch.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
namespace TinySwitch
{
class Program
@jbevain
jbevain / BackingFieldResolver.cs
Created Apr 29, 2009
Code to resolve a property's backing field.
View BackingFieldResolver.cs
//
// BackingFieldResolver.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// WARNING: code now lives in http://github.com/jbevain/mono.reflection
//
// (C) 2009 Novell, Inc. (http://www.novell.com)
//