mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-07 06:58:39 +00:00
Implement custom delegate calling (#60)
This commit is contained in:
@@ -73,6 +73,22 @@ module TestCases =
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain = [ CliType.Numeric (CliNumericType.Int32 1) ]
|
||||
}
|
||||
{
|
||||
FileName = "CustomDelegate.cs"
|
||||
ExpectedReturnCode = 8
|
||||
NativeImpls = MockEnv.make ()
|
||||
LocalVariablesOfMain =
|
||||
[
|
||||
// filter
|
||||
CliType.ObjectRef (Some (ManagedHeapAddress 2))
|
||||
// result
|
||||
CliType.OfBool true
|
||||
// result, cloned for "if(result)" check
|
||||
CliType.OfBool true
|
||||
// ret
|
||||
CliType.Numeric (CliNumericType.Int32 8)
|
||||
]
|
||||
}
|
||||
{
|
||||
FileName = "ArgumentOrdering.cs"
|
||||
ExpectedReturnCode = 42
|
||||
|
@@ -28,6 +28,7 @@
|
||||
<EmbeddedResource Include="sources\Threads.cs" />
|
||||
<EmbeddedResource Include="sources\ResizeArray.cs" />
|
||||
<EmbeddedResource Include="sources\ArgumentOrdering.cs" />
|
||||
<EmbeddedResource Include="sources\CustomDelegate.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
27
WoofWare.PawPrint.Test/sources/CustomDelegate.cs
Normal file
27
WoofWare.PawPrint.Test/sources/CustomDelegate.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
public delegate bool MyFilter(object item, object criteria);
|
||||
|
||||
public class DelegateDemo
|
||||
{
|
||||
// This static field initialization will generate the exact IL pattern:
|
||||
public static readonly MyFilter FilterField = FilterImpl;
|
||||
|
||||
// The static method that the delegate points to
|
||||
private static bool FilterImpl(object item, object criteria)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int Main(string[] argv)
|
||||
{
|
||||
// Force static constructor to run
|
||||
var filter = FilterField;
|
||||
|
||||
// Test the delegate
|
||||
bool result = filter("test item", "criterion");
|
||||
if (result)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user