Created
March 3, 2018 17:21
-
-
Save svick/fc4fa28d97f5a4393e3a6130b9c43009 to your computer and use it in GitHub Desktop.
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
| Option Strict On | |
| Imports System | |
| Imports Microsoft.CodeAnalysis.CSharp.Scripting | |
| Module Program | |
| Sub Main() | |
| Dim hashCode As Byte = 42 | |
| Dim data As Byte() = { 1, 2, 3 } | |
| hashCode = CSharp(Of Byte, Byte(), Integer, Byte)( | |
| "(hashCode, data, i) => unchecked((byte)((hashCode ^ data[i]) * 0x100000001b3))", | |
| hashCode, data, 0) | |
| Console.WriteLine(hashCode) | |
| End Sub | |
| Function CSharp(Of T1, T2, T3, TResult)(cSharpLambda As String, param1 As T1, param2 As T2, param3 As T3) As TResult | |
| Dim execute = "TResult Execute<T1, T2, T3, TResult>(System.Func<T1, T2, T3, TResult> func, T1 param1, T2 param2, T3 param3) => func(param1, param2, param3);" | |
| Dim script = $"{execute} Execute({cSharpLambda}, Param1, Param2, Param3)" | |
| Dim globals = New Globals(Of T1, T2, T3) With { .Param1 = param1, .Param2 = param2, .Param3 = param3 } | |
| Return CSharpScript.EvaluateAsync(Of TResult)(script, globals:=globals).GetAwaiter().GetResult() | |
| End Function | |
| End Module | |
| Public Class Globals(Of T1, T2, T3) | |
| Public Property Param1 As T1 | |
| Public Property Param2 As T2 | |
| Public Property Param3 As T3 | |
| End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment