Skip to content

Instantly share code, notes, and snippets.

@TryJSIL
TryJSIL / tryjsil.cs
Created February 28, 2013 07:51
Simple Unsafe Structs
using System;
using System.Runtime.InteropServices;
public static class Program {
public static unsafe void Main (string[] args) {
var bytes = new byte[8];
fixed (byte* pBytes = bytes) {
var pStruct = (MyStruct*)pBytes;
*pStruct = new MyStruct {
@TryJSIL
TryJSIL / DynamicDOM.cs
Created April 27, 2012 11:33
Dynamic DOM
using System;
using JSIL;
using JSIL.Meta;
public static class Program {
public static int x = 10;
public static int y = 20;
public static void Main () {
dynamic document = Builtins.Global["document"];
@TryJSIL
TryJSIL / Reflection.cs
Created April 27, 2012 13:08
Reflection
using System;
using System.Reflection;
using System.Collections.Generic;
public static class Program {
public static void Main (string[] args) {
Common.Util.ListMembers<MethodInfo>(
typeof(T),
BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public
);
@TryJSIL
TryJSIL / MulticastDelegates.cs
Created April 27, 2012 12:56
Multicast Delegates
using System;
public static class Program {
public static void Main (string[] args) {
Action<int> a =
(i) => Console.WriteLine("a({0})", i);
Action<int> b =
(i) => Console.WriteLine("b({0})", i);
Action<int> c = (Action<int>)Delegate.Combine(a, b);
@TryJSIL
TryJSIL / SealedMethods.cs
Created April 27, 2012 12:52
Sealed Methods
using System;
public class Foo {
public void Func1 () {
Console.Write("F1 ");
}
public virtual void Func2 () {
Console.Write("F2 ");
this.Func1();
@TryJSIL
TryJSIL / RefParameters.cs
Created April 27, 2012 12:53
Ref Parameters
using System;
public static class Program {
public static void Increment (ref int x) {
x += 1;
}
public static void IncrementTwice (ref int x) {
Increment(ref x);
Increment(ref x);
@TryJSIL
TryJSIL / InheritGenericClass.cs
Created April 27, 2012 12:57
Generic Inheritance
using System;
public class GenericClass<T> {
public virtual void Method (T value) {
Console.WriteLine("GenericClass<{0}>.Method({1})", typeof(T), value);
}
}
public class MyClass<T> : GenericClass<T> {
public override void Method (T value) {
@TryJSIL
TryJSIL / events1.cs
Created April 27, 2012 11:34
MSDN Events Tutorial
// http://msdn.microsoft.com/en-us/library/aa645739%28v=vs.71%29.aspx
// events1.cs
using System;
namespace MyCollections
{
using System.Collections;
// A delegate type for hooking up change notifications.
public delegate void ChangedEventHandler(object sender, EventArgs e);
@TryJSIL
TryJSIL / tryjsil.cs
Created February 24, 2013 11:57
Unsafe Code Test
using System;
public static class Program {
public static unsafe void Main (string[] args) {
var ints = new int[] { 0, 1, 2, 3 };
fixed (int* pInts = ints) {
var pBytes = (byte*)pInts;
for (var i = 0; i < (ints.Length * 4); i++)
@TryJSIL
TryJSIL / tryjsil.cs
Created November 7, 2012 11:33
Int64
using System;
public class Program {
public static void Main () {
var i = 0;
var x = 1L;
Console.WriteLine("Left shift");
Console.WriteLine(x);
Console.WriteLine("{0} {1}", 1, Format(x << 1));