Skip to content

Instantly share code, notes, and snippets.

@jkotas
Created August 12, 2016 07:18
Show Gist options
  • Save jkotas/8cf994304c56b7d5ec6e54d8ed0e585f to your computer and use it in GitHub Desktop.
Save jkotas/8cf994304c56b7d5ec6e54d8ed0e585f to your computer and use it in GitHub Desktop.
NativeCallableAttribute + AddOf intrinsic
using System;
using System.Runtime.InteropServices;
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Method)]
public sealed class NativeCallableAttribute : Attribute
{
public string EntryPoint;
public CallingConvention CallingConvention;
public NativeCallableAttribute()
{
}
}
[AttributeUsage((System.AttributeTargets.Method | System.AttributeTargets.Class))]
public class McgIntrinsicsAttribute : Attribute
{
}
[McgIntrinsics]
public static class AddrOfIntrinsics
{
// This method is implemented elsewhere in the toolchain
internal static IntPtr AddrOf<T>(T ftn) { throw new PlatformNotSupportedException(); }
}
}
internal class Program
{
[NativeCallable]
private static void foo()
{
}
private static void Main(string[] args)
{
Console.WriteLine(AddrOfIntrinsics.AddrOf(new Action(foo)).ToString("x"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment