本文整理汇总了C#中GCHandleType类的典型用法代码示例。如果您正苦于以下问题:C# GCHandleType类的具体用法?C# GCHandleType怎么用?C# GCHandleType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GCHandleType类属于命名空间,在下文中一共展示了GCHandleType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScopedGCHandle
/// <summary>
/// 指定したオブジェクトに指定した型のハンドルを割り当てます
/// </summary>
/// <param name="value">GCの対象からはずすオブジェクト</param>
/// <param name="type">作成する System.Runtime.InteropServices.GCHandle の型を示す、System.Runtime.InteropServices.GCHandleType 値の 1 つ</param>
#else
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <param name="type"></param>
#endif
public ScopedGCHandle(object value, GCHandleType type)
{
if (value != null)
{
this.Handle = GCHandle.Alloc(value, type);
}
}
示例2: RhHandleAlloc
internal static IntPtr RhHandleAlloc(Object value, GCHandleType type)
{
IntPtr h = RhpHandleAlloc(value, type);
if (h == IntPtr.Zero)
throw new OutOfMemoryException();
return h;
}
示例3: GCHandle
internal GCHandle(object value, GCHandleType type)
{
// MS does not crash/throw on (most) invalid GCHandleType values (except -1)
if ((type < GCHandleType.Weak) || (type > GCHandleType.Pinned))
type = GCHandleType.Normal;
handle = GetTargetHandle (value, 0, type);
}
示例4: UnsafeGCHandle
// Allocate a handle storing the object and the type.
private UnsafeGCHandle(Object value, GCHandleType type)
{
Debug.Assert((uint)type <= (uint)GCHandleType.Normal, "unexpected handle type");
_handle = InternalCalls.RhpHandleAlloc(value, type);
if (_handle == IntPtr.Zero)
throw new OutOfMemoryException();
}
示例5: GCHandle
// Allocate a handle storing the object and the type.
internal GCHandle(Object value, GCHandleType type)
{
m_handle = InternalAlloc(value, type);
// Record if the handle is pinned.
if (type == GCHandleType.Pinned)
SetIsPinned();
}
示例6: ScopedGCHandle
/// <summary>
/// 指定したオブジェクトに指定した型のハンドルを割り当てます
/// </summary>
/// <param name="value">GCの対象からはずすオブジェクト</param>
/// <param name="type">作成する System.Runtime.InteropServices.GCHandle の型を示す、System.Runtime.InteropServices.GCHandleType 値の 1 つ</param>
#else
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <param name="type"></param>
#endif
public ScopedGCHandle(object value, GCHandleType type)
{
if (value != null)
{
handle = GCHandle.Alloc(value, type);
}
disposed = false;
}
示例7: GCHandle
internal GCHandle(object value, GCHandleType type)
{
if (type > GCHandleType.Pinned)
{
throw new ArgumentOutOfRangeException("type", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
}
this.m_handle = InternalAlloc(value, type);
if (type == GCHandleType.Pinned)
{
this.SetIsPinned();
}
}
示例8: SafeGCHandle
/// <summary>
/// Initializes a new instance of the <see cref="SafeGCHandle"/> class referring to the target in the given way.
/// </summary>
/// <param name="target">The object to reference.</param>
/// <param name="type">The way to reference the object.</param>
public SafeGCHandle(object target, GCHandleType type)
: base(IntPtr.Zero, true)
{
RuntimeHelpers.PrepareConstrainedRegions();
try
{
// The StyleCop warning for this try block is incorrect; it is required to create a Constrained Execution Region
}
finally
{
this.SetHandle(GCHandle.ToIntPtr(GCHandle.Alloc(target, type)));
}
}
示例9: GCHandle
[System.Security.SecurityCritical] // auto-generated
internal GCHandle(Object value, GCHandleType type)
{
// Make sure the type parameter is within the valid range for the enum.
if ((uint)type > (uint)MaxHandleType)
throw new ArgumentOutOfRangeException("type", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
Contract.EndContractBlock();
m_handle = InternalAlloc(value, type);
// Record if the handle is pinned.
if (type == GCHandleType.Pinned)
SetIsPinned();
}
示例10: GCHandle
// Allocate a handle storing the object and the type.
internal GCHandle(Object value, GCHandleType type)
{
// Make sure the type parameter is within the valid range for the enum.
if ((uint)type > (uint)MaxHandleType)
{
throw new ArgumentOutOfRangeException(); // "type", SR.ArgumentOutOfRange_Enum;
}
if (type == GCHandleType.Pinned)
GCHandleValidatePinnedObject(value);
_handle = RuntimeImports.RhHandleAlloc(value, type);
// Record if the handle is pinned.
if (type == GCHandleType.Pinned)
SetIsPinned();
}
示例11: RhHandleAlloc
public static IntPtr RhHandleAlloc(object value, GCHandleType type)
{
IntPtr h = InternalCalls.RhpHandleAlloc(value, type);
if (h == IntPtr.Zero)
{
// Throw the out of memory exception defined by the classlib, using the return address of this method
// to find the correct classlib.
ExceptionIDs exID = ExceptionIDs.OutOfMemory;
IntPtr returnAddr = BinderIntrinsics.GetReturnAddress();
Exception e = EH.GetClasslibException(exID, returnAddr);
throw e;
}
return h;
}
示例12: Alloc
public static GCHandle Alloc (object value, GCHandleType type) {
throw new NotImplementedException();
}
示例13: AutoFreeGCHandle
public AutoFreeGCHandle(object targetObject, GCHandleType type = GCHandleType.Pinned)
{
_handle = GCHandle.Alloc(targetObject, type);
}
示例14: GetGCHandle
internal IntPtr GetGCHandle(GCHandleType type)
{
return RuntimeTypeHandle.GetGCHandle(this.GetNativeHandle(), type);
}
示例15: Alloc
[System.Security.SecurityCritical] // auto-generated_required
public static GCHandle Alloc(Object value, GCHandleType type)
{
return new GCHandle(value, type);
}