System.WeakReference

using System.Security.Permissions;
using System.Runtime.InteropServices;
namespace System
{
[Serializable,ComVisible(true)]
    [SecurityPermissionAttribute(SecurityAction.InheritanceDemand,Flags=SecurityPermissionFlag.UnmanagedCode)]
public class WeakReference:System.Object,System.Runtime.Serialization.ISerializable
{
        internal volatile System.IntPtr m_handle;
internal bool m_IsLongReference;
public WeakReference(object target):this(target,false)
{
//.maxstack  8
//IL_0000:  ldarg.0
//IL_0001:  ldarg.1
//IL_0002:  ldc.i4.0
//IL_0003:  call       instance void System.WeakReference::.ctor(object,
//bool)
//IL_0008:  ret
}
public WeakReference(object target,bool trackResurrection):base()
{
//.maxstack  8
//IL_0000:  ldarg.0
//IL_0001:  call       instance void System.Object::.ctor()
//IL_0006:  ldarg.0
//IL_0007:  ldarg.2
//IL_0008:  stfld      bool System.WeakReference::m_IsLongReference
//IL_000d:  ldarg.0
//IL_000e:  ldarg.1
//IL_000f:  ldarg.2
//IL_0010:  brtrue.s   IL_0015
//IL_0012:  ldc.i4.0
//IL_0013:  br.s       IL_0016
//IL_0015:  ldc.i4.1
//IL_0016:  call       native int System.Runtime.InteropServices.GCHandle::InternalAlloc(object,
//valuetype System.Runtime.InteropServices.GCHandleType)
//IL_001b:  volatile.
//IL_001d:  stfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0022:  ret
            this.m_IsLongReference=trackResurrection;            
            if(trackResurrection)
            {
                this.m_handle=GCHandle.InternalAlloc(target,GCHandleType.WeakTrackResurrection);            
            }
            else
            {
                this.m_handle=GCHandle.InternalAlloc(target,GCHandleType.Weak);  
            }
}
protected WeakReference(System.Runtime.Serialization.SerializationInfo info,System.Runtime.Serialization.StreamingContext context):base()
{
//.maxstack  4
            //.locals init (object V_0)                                     
//IL_0000:  ldarg.0
//IL_0001:  call       instance void System.Object::.ctor()
//IL_0006:  ldarg.1
//IL_0007:  brtrue.s   IL_0014
//IL_0009:  ldstr      "info"
//IL_000e:  newobj     instance void System.ArgumentNullException::.ctor(string)
//IL_0013:  throw
//IL_0014:  ldarg.1
//IL_0015:  ldstr      "TrackedObject"
//IL_001a:  ldtoken    System.Object
//IL_001f:  call       class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0024:  callvirt   instance object System.Runtime.Serialization.SerializationInfo::GetValue(string,
//class System.Type)
//IL_0029:  stloc.0
//IL_002a:  ldarg.0
//IL_002b:  ldarg.1
//IL_002c:  ldstr      "TrackResurrection"
//IL_0031:  callvirt   instance bool System.Runtime.Serialization.SerializationInfo::GetBoolean(string)
//IL_0036:  stfld      bool System.WeakReference::m_IsLongReference
//IL_003b:  ldarg.0
//IL_003c:  ldloc.0
//IL_003d:  ldarg.0
//IL_003e:  ldfld      bool System.WeakReference::m_IsLongReference
//IL_0043:  brtrue.s   IL_0048
//IL_0045:  ldc.i4.0
//IL_0046:  br.s       IL_0049
//IL_0048:  ldc.i4.1
//IL_0049:  call       native int System.Runtime.InteropServices.GCHandle::InternalAlloc(object,
//valuetype System.Runtime.InteropServices.GCHandleType)
//IL_004e:  volatile.
//IL_0050:  stfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0055:  ret
            object V_0;
            if(info==null)
            {
                throw new System.ArgumentNullException("info");
            }
            else
            {
                V_0=info.GetValue("TrackedObject",typeof(object));
                //IL_002a
                this.m_IsLongReference=info.GetBoolean("TrackResurrection");                
                if(this.m_IsLongReference)
                {
                    this.m_handle=GCHandle.InternalAlloc(V_0,GCHandleType.WeakTrackResurrection);
                }
                else
                {
                    this.m_handle=GCHandle.InternalAlloc(V_0,GCHandleType.Weak);
                }
            }

}
        public new virtual bool IsAlive
        {
            get
            {
                ;
            }            
            //.get instance bool System.WeakReference::get_IsAlive()
        }
public new virtual bool get_IsAlive()
{
//.maxstack  2
            //.locals init (native int V_0,                   
//bool V_1)
//IL_0000:  ldarg.0
//IL_0001:  volatile.
//IL_0003:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0008:  stloc.0
//IL_0009:  ldsfld     native int System.IntPtr::Zero
//IL_000e:  ldloc.0
//IL_000f:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_0014:  brfalse.s  IL_0018
//IL_0016:  ldc.i4.0
//IL_0017:  ret
//IL_0018:  ldloc.0
//IL_0019:  call       object System.Runtime.InteropServices.GCHandle::InternalGet(native int)
//IL_001e:  ldnull
//IL_001f:  ceq
//IL_0021:  ldc.i4.0
//IL_0022:  ceq
//IL_0024:  stloc.1
//IL_0025:  ldarg.0
//IL_0026:  volatile.
//IL_0028:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_002d:  ldsfld     native int System.IntPtr::Zero
//IL_0032:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_0037:  brtrue.s   IL_003b
//IL_0039:  ldloc.1
//IL_003a:  ret
//IL_003b:  ldc.i4.0
//IL_003c:  ret
            System.IntPtr V_0;
            bool V_1;
            V_0=this.m_handle;
            if(System.IntPtr.Zero==V_0)
            {
                return false;
            }
            else
            {
                V_1=(GCHandle.InternalGet(V_0)==null)==false;
                //IL_0025
                if (this.m_handle == System.IntPtr.Zero)
                {
                    return false;
                }
                else
                {
                    return V_1;
                }
            }
}
        public new virtual bool TrackResurrection
        {
            get
            {
                ;
            }            
            //.get instance bool System.WeakReference::get_TrackResurrection()
        }
public new virtual bool get_TrackResurrection()
{
//.maxstack  8
//IL_0000:  ldarg.0
//IL_0001:  ldfld      bool System.WeakReference::m_IsLongReference
//IL_0006:  ret
            return this.m_IsLongReference;
}
        public new virtual object Target
        {
            get
            {
                ;
            }
            set
            {
                ;
            }
            //.set instance void System.WeakReference::set_Target(object)
            //.get instance object System.WeakReference::get_Target()
        }
public new virtual object get_Target()
{
//.maxstack  2
//.locals init (native int V_0,
//object V_1)
//IL_0000:  ldarg.0
//IL_0001:  volatile.
//IL_0003:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0008:  stloc.0
//IL_0009:  ldsfld     native int System.IntPtr::Zero
//IL_000e:  ldloc.0
//IL_000f:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_0014:  brfalse.s  IL_0018
//IL_0016:  ldnull
//IL_0017:  ret
//IL_0018:  ldloc.0
//IL_0019:  call       object System.Runtime.InteropServices.GCHandle::InternalGet(native int)
//IL_001e:  stloc.1
//IL_001f:  ldarg.0
//IL_0020:  volatile.
//IL_0022:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0027:  ldsfld     native int System.IntPtr::Zero
//IL_002c:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_0031:  brtrue.s   IL_0035
//IL_0033:  ldloc.1
//IL_0034:  ret
//IL_0035:  ldnull
//IL_0036:  ret
            System.IntPtr V_0;
            object V_1;
            V_0=this.m_handle;
            if (System.IntPtr.Zero == V_0)
            {
                return null;
            }
            else
            {
                V_1=GCHandle.InternalGet(V_0);
                if (this.m_handle == System.IntPtr.Zero)
                {
                    return null;
                }
                else
                {
                    return V_1;
                }
            }
}
public new virtual void set_Target(object @value)
{
//.maxstack  4
//.locals init (native int V_0,
//object V_1)
//IL_0000:  ldarg.0
//IL_0001:  volatile.
//IL_0003:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0008:  stloc.0
//IL_0009:  ldloc.0
//IL_000a:  ldsfld     native int System.IntPtr::Zero
//IL_000f:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_0014:  brfalse.s  IL_0026
//IL_0016:  ldstr      "InvalidOperation_HandleIsNotInitialized"
//IL_001b:  call       string System.Environment::GetResourceString(string)
//IL_0020:  newobj     instance void System.InvalidOperationException::.ctor(string)
//IL_0025:  throw
//IL_0026:  ldloc.0
//IL_0027:  call       object System.Runtime.InteropServices.GCHandle::InternalGet(native int)
//IL_002c:  stloc.1
//IL_002d:  ldarg.0
//IL_002e:  volatile.
//IL_0030:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0035:  stloc.0
//IL_0036:  ldloc.0
//IL_0037:  ldsfld     native int System.IntPtr::Zero
//IL_003c:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_0041:  brfalse.s  IL_0053
//IL_0043:  ldstr      "InvalidOperation_HandleIsNotInitialized"
//IL_0048:  call       string System.Environment::GetResourceString(string)
//IL_004d:  newobj     instance void System.InvalidOperationException::.ctor(string)
//IL_0052:  throw
//IL_0053:  ldloc.0
//IL_0054:  ldarg.1
//IL_0055:  ldloc.1
//IL_0056:  ldc.i4.0
//IL_0057:  call       object System.Runtime.InteropServices.GCHandle::InternalCompareExchange(native int,
//object,
//object,
//bool)
//IL_005c:  pop
//IL_005d:  ldarg.0
//IL_005e:  call       void System.GC::KeepAlive(object)
//IL_0063:  ret
            System.IntPtr V_0;
            object V_1;
            V_0 = this.m_handle;
            if (V_0 == System.IntPtr.Zero)
            {
                throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_HandleIsNotInitialized"));
            }
            else
            {
                V_1 = GCHandle.InternalGet(V_0);
                V_0 = this.m_handle;
                if (V_0 == System.IntPtr.Zero)
                {
                    throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_HandleIsNotInitialized"));
                }
                else
                {
                    GCHandle.InternalCompareExchange(V_0, @value, V_1, false);
                    GC.KeepAlive(this);                    
                }
            }
}
protected virtual ~WeakReference()
{
//.maxstack  4
//.locals init (native int V_0)
//.try
//{
//IL_0000:  ldarg.0
//IL_0001:  volatile.
//IL_0003:  ldfld      native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_0008:  stloc.0
//IL_0009:  ldloc.0
//IL_000a:  ldsfld     native int System.IntPtr::Zero
//IL_000f:  call       bool System.IntPtr::op_Inequality(native int,
//native int)
//IL_0014:  brfalse.s  IL_0035
//IL_0016:  ldloc.0
//IL_0017:  ldarg.0
//IL_0018:  ldflda     native int modreq(System.Runtime.CompilerServices.IsVolatile) System.WeakReference::m_handle
//IL_001d:  ldsfld     native int System.IntPtr::Zero
//IL_0022:  ldloc.0
//IL_0023:  call       native int System.Threading.Interlocked::CompareExchange(native int&,
//native int,
//native int)
//IL_0028:  call       bool System.IntPtr::op_Equality(native int,
//native int)
//IL_002d:  brfalse.s  IL_0035
//IL_002f:  ldloc.0
//IL_0030:  call       void System.Runtime.InteropServices.GCHandle::InternalFree(native int)
//IL_0035:  leave.s    IL_003e
//}
//finally
//{
//IL_0037:  ldarg.0
//IL_0038:  call       instance void System.Object::Finalize()
//IL_003d:  endfinally
//}
//IL_003e:  ret
            System.IntPtr V_0;
            try
            {
                V_0 = this.m_handle;
                if (V_0 != System.IntPtr.Zero)
                {

                    if (V_0 == System.Threading.Interlocked.CompareExchange(ref this.m_handle, System.IntPtr.Zero, V_0))
                    {
                        GCHandle.InternalFree(V_0);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            finally
            {
                base();
            }
}
public new virtual void GetObjectData(System.Runtime.Serialization.SerializationInfo info,System.Runtime.Serialization.StreamingContext context)
{
//.maxstack  8
//IL_0000:  ldarg.1
//IL_0001:  brtrue.s   IL_000e
//IL_0003:  ldstr      "info"
//IL_0008:  newobj     instance void System.ArgumentNullException::.ctor(string)
//IL_000d:  throw
//IL_000e:  ldarg.1
//IL_000f:  ldstr      "TrackedObject"
//IL_0014:  ldarg.0
//IL_0015:  callvirt   instance object System.WeakReference::get_Target()
//IL_001a:  ldtoken    System.Object
//IL_001f:  call       class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0024:  callvirt   instance void System.Runtime.Serialization.SerializationInfo::AddValue(string,
//object,
//class System.Type)
//IL_0029:  ldarg.1
//IL_002a:  ldstr      "TrackResurrection"
//IL_002f:  ldarg.0
//IL_0030:  ldfld      bool System.WeakReference::m_IsLongReference
//IL_0035:  callvirt   instance void System.Runtime.Serialization.SerializationInfo::AddValue(string,
//bool)
//IL_003a:  ret
            if (info == null)
            {
                throw new System.ArgumentNullException("info");
            }
            else
            {
                info.AddValue("TrackedObject", this.Target, typeof(object));
                info.AddValue("TrackResurrection",this.m_IsLongReference);
            }
}
}
}

posted @ 2010-08-28 21:22  Aegis  阅读(459)  评论(0编辑  收藏  举报