Esempio n. 1
0
 /// <summary>
 /// Checks whether this object is equal to the given object.
 /// </summary>
 /// <param name="otherReference">
 /// The reference in question.
 /// </param>
 /// <returns>
 /// True, if the given object references the same object as this
 /// object. False, otherwise.
 /// </returns>
 public bool Equals(WeakReference <T> otherReference)
 {
     if (otherReference == null)
     {
         return(false);
     }
     else
     {
         return(m_Handle.Equals(otherReference.m_Handle));
     }
 }
Esempio n. 2
0
 public void Equals_Object_ReturnsExpected(GCHandle handle, object other, bool expected)
 {
     try
     {
         Assert.Equal(expected, handle.Equals(other));
         if (other is GCHandle otherHandle)
         {
             Assert.Equal(expected, handle.Equals(otherHandle));
             Assert.Equal(expected, handle == otherHandle);
             Assert.Equal(!expected, handle != otherHandle);
         }
     }
     finally
     {
         handle.Free();
         if (other is GCHandle otherHandle && !expected)
         {
             otherHandle.Free();
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 指定した System.Runtime.InteropServices.GCHandle オブジェクトが、現在の System.Runtime.InteropServices.GCHandle オブジェクトと等しいかどうかを判断します
        /// </summary>
        /// <param name="obj">現在の System.Runtime.InteropServices.GCHandle オブジェクトと比較する System.Runtime.InteropServices.GCHandle オブジェクト</param>
        /// <returns></returns>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
#endif
        public override bool Equals(object?obj)
        {
            return(handle.Equals(obj));
        }
Esempio n. 4
0
    public bool RunTest()
    {
        Object   o   = new Object();
        GCHandle gc  = GCHandle.Alloc(o);
        GCHandle gc2 = GCHandle.Alloc(o);
        GCHandle gc3 = gc;

        if (gc.Equals(null))
        {
            Console.WriteLine("Equals null failed");
            return(false);
        }

        if (gc.Equals(new Object()))
        {
            Console.WriteLine("Equals new Object failed");
            return(false);
        }

        if (gc.Equals(gc2))
        {
            Console.WriteLine("Equals GCHandle 1 failed");
            return(false);
        }

        if (!gc.Equals(gc3))
        {
            Console.WriteLine("Equals GCHandle 2 failed");
            return(false);
        }


        if (gc == gc2)
        {
            Console.WriteLine("== GCHandle 1 failed");
            return(false);
        }

        if (!(gc == gc3))
        {
            Console.WriteLine("== GCHandle 2 failed");
            return(false);
        }

        if (gc.GetHashCode() == gc2.GetHashCode())
        {
            Console.WriteLine("GetHashCode 1 failed");
            return(false);
        }

        if (gc.GetHashCode() != gc3.GetHashCode())
        {
            Console.WriteLine("GetHashCode 2 failed");
            return(false);
        }


        if (!(gc != gc2))
        {
            Console.WriteLine("!= GCHandle 1 failed");
            return(false);
        }

        if (gc != gc3)
        {
            Console.WriteLine("!= GCHandle 2 failed");
            return(false);
        }

        return(true);
    }
 public override bool Equals(object obj)
 {
     return(obj != null && _handle.Equals(((WeakReference <T>)obj)._handle));
 }