Created
August 12, 2016 07:18
-
-
Save jkotas/8cf994304c56b7d5ec6e54d8ed0e585f to your computer and use it in GitHub Desktop.
NativeCallableAttribute + AddOf intrinsic
This file contains hidden or 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.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