mirror of
https://github.com/digital-jellyfish/Virtu.git
synced 2024-11-24 10:30:55 +00:00
acd7892436
Fixed some code analysis warnings. Dropped Extended Strongly Typed Resource Generator dependency. --HG-- extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4035615
33 lines
842 B
C#
33 lines
842 B
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.Permissions;
|
|
|
|
namespace Jellyfish.Library
|
|
{
|
|
public static class GCHandleHelpers
|
|
{
|
|
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
|
|
public static void Pin(object value, Action<IntPtr> action)
|
|
{
|
|
if (action == null)
|
|
{
|
|
throw new ArgumentNullException("action");
|
|
}
|
|
|
|
GCHandle gcHandle = new GCHandle();
|
|
try
|
|
{
|
|
gcHandle = GCHandle.Alloc(value, GCHandleType.Pinned);
|
|
action(gcHandle.AddrOfPinnedObject());
|
|
}
|
|
finally
|
|
{
|
|
if (gcHandle.IsAllocated)
|
|
{
|
|
gcHandle.Free();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|