This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//example emit code borrowed and lightly modified from http://www.c-sharpcorner.com/uploadfile/puranindia/reflection-and-reflection-emit-in-C-Sharp/ | |
using System; | |
using System.Reflection; | |
using System.Reflection.Emit; | |
using System.Threading; | |
namespace ConsoleApplication12 { | |
// declare the interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using NullableInt = System.Nullable<int>; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("null:"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace JustATest | |
{ | |
// public struct InheritingTuple(int A, int B) : (int, int)(A, B); | |
// same: public struct InheritingTuple(int A, int B) : (int A, int B)(A, B); | |
// same, better?: public struct InheritingTuple(int A, int B) : (int A: A, int B: B); | |
// compiles as: | |
// public struct InheritingTuple(int A, int B) : ValueTuple<int, int>(A, B); | |
// should this be allowed? | |
// I think no: ValueTuple<T...> structs sealed? | |
// where would attribute go? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using System.Diagnostics; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
namespace ConsoleApplication1 { | |
internal partial class Program { | |
private const int Iterations = 10000; | |
private static void Main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void NewArrayUsesCachedArray() { | |
var verifier = CompileAndVerify(@" | |
namespace System | |
{ | |
public class Object { } | |
public class ValueType { } | |
public struct Int32 { } | |
public class String { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(int, int) LocateRange<TKey, TValue> (SortedList<TKey, TValue> list, Func<Tkey, bool> beforeRange, Func<Tkey, bool> inRange, Func<Tkey, bool> afterRange) | |
{ | |
// | |
// searches list for the range of items that meet the specified criteria | |
// returns (-1, -1) if nothing found or the indices if it is | |
// | |
// example searching a string keyed list by items that start with some value: | |
// | |
// given: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SliceExtensions | |
{ | |
public static Slice<T> ToSlice<T>(this T[] array) | |
{ | |
return new Slice<T>(array); | |
} | |
public static Slice<T> ToSlice<T>(this T[] array, int offset, int length) | |
{ | |
return new Slice<T>(array, offset, length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Code size 66 (0x42) | |
.maxstack 7 | |
IL_0000: ldnull | |
IL_0001: ldtoken ""int Test.ModAdd2(params int[])"" | |
IL_0006: call ""System.Reflection.MethodBase System.Reflection.MethodBase.GetMethodFromHandle(System.RuntimeMethodHandle)"" | |
IL_000b: castclass ""System.Reflection.MethodInfo"" | |
IL_0010: ldc.i4.1 | |
IL_0011: newarr ""System.Linq.Expressions.Expression"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the meat and potatoes... | |
public class DataStoreCodeGen { | |
private const TypeAttributes public_sealed_class = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit; | |
private const MethodAttributes public_ctor = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; | |
private const MethodAttributes get_set = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.SpecialName; | |
// singleton reference to module containing all generated storage interfaces | |
private static ModuleBuilder ModuleBuilder { get; } = CreateModuleBuilder(); |