using System;
using System.Runtime.CompilerServices;
namespace System.Runtime.InteropServices
{
/// Provides a means for accessing a managed object from unmanaged memory.
// Token: 0x02000316 RID: 790
[ComVisible(true)]
[MonoTODO("Struct should be [StructLayout(LayoutKind.Sequential)] but will need to be reordered for that.")]
public struct GCHandle
{
// Token: 0x060021FF RID: 8703 RVA: 0x00079550 File Offset: 0x00077750
private GCHandle(IntPtr h)
{
this.handle = (int)h;
}
// Token: 0x06002200 RID: 8704 RVA: 0x00079560 File Offset: 0x00077760
private GCHandle(object obj)
{
this = new GCHandle(obj, GCHandleType.Normal);
}
// Token: 0x06002201 RID: 8705 RVA: 0x0007956C File Offset: 0x0007776C
private GCHandle(object value, GCHandleType type)
{
if (type < GCHandleType.Weak || type > GCHandleType.Pinned)
{
type = GCHandleType.Normal;
}
this.handle = GCHandle.GetTargetHandle(value, 0, type);
}
/// Gets a value indicating whether the handle is allocated.
/// true if the handle is allocated; otherwise, false.
// Token: 0x1700064D RID: 1613
// (get) Token: 0x06002202 RID: 8706 RVA: 0x00079590 File Offset: 0x00077790
public bool IsAllocated
{
get
{
return this.handle != 0;
}
}
/// Gets or sets the object this handle represents.
/// The object this handle represents.
/// The handle was freed, or never initialized.
///
///
///
// Token: 0x1700064E RID: 1614
// (get) Token: 0x06002203 RID: 8707 RVA: 0x000795A0 File Offset: 0x000777A0
// (set) Token: 0x06002204 RID: 8708 RVA: 0x000795D4 File Offset: 0x000777D4
public object Target
{
get
{
if (!this.IsAllocated)
{
throw new InvalidOperationException(Locale.GetText("Handle is not allocated"));
}
return GCHandle.GetTarget(this.handle);
}
set
{
this.handle = GCHandle.GetTargetHandle(value, this.handle, (GCHandleType)(-1));
}
}
/// Retrieves the address of an object in a handle.
/// The address of the of the Pinned object as an .
/// The handle is any type other than .
///
///
///
// Token: 0x06002205 RID: 8709 RVA: 0x000795EC File Offset: 0x000777EC
public IntPtr AddrOfPinnedObject()
{
IntPtr addrOfPinnedObject = GCHandle.GetAddrOfPinnedObject(this.handle);
if (addrOfPinnedObject == (IntPtr)(-1))
{
throw new ArgumentException("Object contains non-primitive or non-blittable data.");
}
if (addrOfPinnedObject == (IntPtr)(-2))
{
throw new InvalidOperationException("Handle is not pinned.");
}
return addrOfPinnedObject;
}
/// Allocates a handle for the specified object.
/// A new that protects the object from garbage collection. This must be released with when it is no longer needed.
/// The object that uses the .
/// An instance with nonprimitive (non-blittable) members cannot be pinned.
///
///
///
// Token: 0x06002206 RID: 8710 RVA: 0x00079640 File Offset: 0x00077840
public static GCHandle Alloc(object value)
{
return new GCHandle(value);
}
/// Allocates a handle of the specified type for the specified object.
/// A new of the specified type. This must be released with when it is no longer needed.
/// The object that uses the .
/// One of the values, indicating the type of to create.
/// An instance with nonprimitive (non-blittable) members cannot be pinned.
///
///
///
// Token: 0x06002207 RID: 8711 RVA: 0x00079648 File Offset: 0x00077848
public static GCHandle Alloc(object value, GCHandleType type)
{
return new GCHandle(value, type);
}
/// Releases a .
/// The handle was freed or never initialized.
///
///
///
// Token: 0x06002208 RID: 8712 RVA: 0x00079654 File Offset: 0x00077854
public void Free()
{
GCHandle.FreeHandle(this.handle);
this.handle = 0;
}
// Token: 0x06002209 RID: 8713
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool CheckCurrentDomain(int handle);
// Token: 0x0600220A RID: 8714
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern object GetTarget(int handle);
// Token: 0x0600220B RID: 8715
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int GetTargetHandle(object obj, int handle, GCHandleType type);
// Token: 0x0600220C RID: 8716
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void FreeHandle(int handle);
// Token: 0x0600220D RID: 8717
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr GetAddrOfPinnedObject(int handle);
/// Determines whether the specified object is equal to the current object.
/// true if the specified object is equal to the current object; otherwise, false.
/// The object to compare with the current object.
// Token: 0x0600220E RID: 8718 RVA: 0x00079668 File Offset: 0x00077868
public override bool Equals(object o)
{
return o != null && o is GCHandle && this.handle == ((GCHandle)o).handle;
}
/// Returns an identifier for the current object.
/// An identifier for the current object.
// Token: 0x0600220F RID: 8719 RVA: 0x000796A0 File Offset: 0x000778A0
public override int GetHashCode()
{
return this.handle.GetHashCode();
}
/// Returns a new object created from a handle to a managed object.
/// A new object that corresponds to the value parameter.
/// An handle to a managed object to create a object from.
/// The value of the parameter is .
// Token: 0x06002210 RID: 8720 RVA: 0x000796B0 File Offset: 0x000778B0
public static GCHandle FromIntPtr(IntPtr value)
{
return (GCHandle)value;
}
/// Returns the internal integer representation of a object.
/// An object that represents a object.
/// A object to retrieve an internal integer representation from.
// Token: 0x06002211 RID: 8721 RVA: 0x000796B8 File Offset: 0x000778B8
public static IntPtr ToIntPtr(GCHandle value)
{
return (IntPtr)value;
}
/// A is stored using an internal integer representation.
/// The integer value.
/// The for which the integer is required.
///
///
///
// Token: 0x06002212 RID: 8722 RVA: 0x000796C0 File Offset: 0x000778C0
public static explicit operator IntPtr(GCHandle value)
{
return (IntPtr)value.handle;
}
/// A is stored using an internal integer representation.
/// The .
/// An that indicates the handle for which the conversion is required.
///
///
///
// Token: 0x06002213 RID: 8723 RVA: 0x000796D0 File Offset: 0x000778D0
public static explicit operator GCHandle(IntPtr value)
{
if (value == IntPtr.Zero)
{
throw new ArgumentException("GCHandle value cannot be zero");
}
if (!GCHandle.CheckCurrentDomain((int)value))
{
throw new ArgumentException("GCHandle value belongs to a different domain");
}
return new GCHandle(value);
}
/// Returns a value indicating whether two objects are equal.
/// true if the and parameters are equal; otherwise, false.
/// A object to compare with the parameter.
/// A object to compare with the parameter.
// Token: 0x06002214 RID: 8724 RVA: 0x0007971C File Offset: 0x0007791C
public static bool operator ==(GCHandle a, GCHandle b)
{
return a.Equals(b);
}
/// Returns a value indicating whether two objects are not equal.
/// true if the and parameters are not equal; otherwise, false.
/// A object to compare with the parameter.
/// A object to compare with the parameter.
// Token: 0x06002215 RID: 8725 RVA: 0x0007972C File Offset: 0x0007792C
public static bool operator !=(GCHandle a, GCHandle b)
{
return !a.Equals(b);
}
// Token: 0x04000D3B RID: 3387
private int handle;
}
}