Skip to content

Instantly share code, notes, and snippets.

using Nemerle;
using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
@philiplaureano
philiplaureano / gist:5423458
Created April 19, 2013 21:46
An example of how I used CFF explorer to generate the byte array for sampling and roundtripping an MS-DOS header from a .NET assembly.
public ShouldMatchGivenHeaderBytesWhenWrittenToTargetStream() : void
{
def bytes = array[ // dos header start
0x4d : byte, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00,
0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff,
0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@philiplaureano
philiplaureano / gist:5689661
Created June 1, 2013 08:17
Here's the simplest possible BDD framework I could conceive, using Nemerle. It uses FizzBuzz as a demonstration.
using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using System;
using System.Collections.Generic;
using System.Console;
using System.Linq;
public class FizzBuzzer
@philiplaureano
philiplaureano / gist:51413336b6c3c6d604e3
Last active September 15, 2016 11:51
Currying and chaining funcs and actions together in C#
public static class FunctionalBindingExtensions
{
public static Action<T2> Bind<T1, T2>(this Action<T1, T2> action, Func<T1> getValueFunc)
{
return action.Bind(getValueFunc());
}
public static Action<T1> Bind<T1, T2>(this Action<T1, T2> action, Func<T2> getValueFunc)
{
@philiplaureano
philiplaureano / gist:f481e6b0ec68173d04d9
Last active August 29, 2015 14:04
An example of how to use LinFu's new ability to append extension methods to an existing dynamic type and treat it as if it were an instance method
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using LinFu.Finders;
using LinFu.Finders.Interfaces;
using LinFu.Reflection;
using CLRDynamicObject = System.Dynamic.DynamicObject;
@philiplaureano
philiplaureano / gist:6bcc6e81fd00b49e4aae
Created July 29, 2014 03:14
An example of how to implement partially-applied generic factories with Functify so that you can create functions that create generic type factory methods with only some of the type parameters left open
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FunctifyBench
{
using Functify;
@philiplaureano
philiplaureano / InstantiatingGenericMethodsWithFunctify
Last active August 29, 2015 14:04
An example of how to use Functify to call and instantiate a generic method at runtime.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FunctifyBench
{
using System.Reflection;
Yep. If you want app-wide AOP, here's the interface that you need to implement that does the method replacement:
public interface IMethodCallProvider
{
void AddMethodCalls(object target, MethodBase hostMethod, IEnumerable<MethodBase> interceptedMethods,
IMethodCallMap methodCallMap, StackTrace stackTrace);
}
Most of the parameters on the AddMethodCalls method are self explanatory, except for the methodCallMap parameter, which looks like this:
@philiplaureano
philiplaureano / DeflectorInstanceMethodInterceptionDemo.cs
Last active March 28, 2016 09:15
An example of how easy it is to intercept instance method calls with Deflector.NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SampleLibrary;
namespace Deflector.Demos
{
class Program
@philiplaureano
philiplaureano / Reflection.cs
Created May 22, 2017 23:59 — forked from TryJSIL/Reflection.cs
Reflection in JSIL
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
);