/// <summary>
 /// Initializes a new instance of the <see cref="PlayAnimationInfo"/> class.
 /// </summary>
 /// <param name="storyboard">The storyboard.</param>
 /// <param name="animation">The animation.</param>
 /// <param name="target">The target.</param>
 public PlayAnimationInfo(Storyboard storyboard, RadAnimation animation, UIElement target)
 {
     this.storyboard     = storyboard;
     this.animation      = animation;
     this.target         = new WeakReference(target);
     this.animatedValues = new Dictionary <RadAnimation, object[]>();
     this.targetHashCode = target.GetHashCode();
 }
Ejemplo n.º 2
0
 private IDisposable RemoveInstanceConsumer(WeakReference consumerReference)
 {
     return(new DisposableAction(() =>
     {
         object @null;
         if (instanceConsumers.TryRemove(consumerReference, out @null))
         {
             log.InfoFormat("Removed instance subscription with hash {0}", consumerReference.GetHashCode());
         }
     }));
 }
Ejemplo n.º 3
0
            /// <summary>
            /// Returns a hash code for the specified object.
            /// </summary>
            /// <param name="obj">The <see cref="T:System.Object"></see> for which a hash code is to be returned.</param>
            /// <returns>A hash code for the specified object.</returns>
            /// <exception cref="T:System.ArgumentNullException">The type of obj is a reference type and obj is null.</exception>
            public int GetHashCode(object obj)
            {
                // Depending upon the path, the object that we are being passed could be
                // an object in reference form or dictionary form.  In reference form, it
                // is just a plain old T; in dictionary form, it would be a WeakReference<T>

                WeakReference <T> refT = obj as WeakReference <T>;

                return((refT != null)
                        ? (refT.GetHashCode())
                        : (obj.GetHashCode()));
            }
            int IEqualityComparer <object> .GetHashCode(object obj)
            {
                WeakReference wobj = obj as WeakReference;

                if (wobj != null)
                {
                    obj = wobj.Target;
                    if (obj == null)
                    {
                        // empty WeakReference slots are only equal to themselves
                        return(wobj.GetHashCode());
                    }
                }

                return(SRC.RuntimeHelpers.GetHashCode(obj));
            }
Ejemplo n.º 5
0
        public void TestWeakReferenceInHashSet()
        {
            var foo      = new Foo();
            var fooWeak1 = new WeakReference <Foo>(foo);
            var fooWeak2 = new WeakReference <Foo>(foo);

            Assert.AreNotEqual(fooWeak1, fooWeak2);
            Assert.AreNotEqual(fooWeak1.GetHashCode(), fooWeak2.GetHashCode());
            Assert.IsFalse(fooWeak1.Equals(fooWeak2));

            var set = new HashSet <WeakReference <Foo> >();

            set.Add(fooWeak1);
            set.Add(fooWeak2);

            Assert.AreEqual(2, set.Count);
        }
            public override bool Equals(object obj)
            {
                if (object.ReferenceEquals(obj, this))
                {
                    return(true);
                }
                if (obj == null)
                {
                    return(false);
                }

                WeakReference <T> weakOther = obj as WeakReference <T>;

                if (weakOther != null)
                {
                    return(this.GetHashCode() == weakOther.GetHashCode());
                }

                return(object.ReferenceEquals(this.Target, obj));
            }
Ejemplo n.º 7
0
 public int GetHashCode(WeakReference <T> obj)
 {
     //Debug.Log("GetHashCode");
     return(obj.GetHashCode());
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the hashcode
 /// </summary>
 public int GetHashCode(WeakReference <T> item)
 {
     // item.GetHashCode() returns a cached value from when the Target was referenced,
     // and was calculated using this.underlyingComparer.
     return(item.GetHashCode());
 }
Ejemplo n.º 9
0
 public Key(MethodDef method)
 {
     this.method = new WeakReference(method);
     this.hc     = method.GetHashCode();
 }
Ejemplo n.º 10
0
        public IDisposable AddInstanceSubscription(IConsumer consumer)
        {
            var consumerReference = new WeakReference(consumer);

            instanceConsumers.TryAdd(consumerReference, null);

            log.InfoFormat("Added instance subscription for consumer of type {0}, hash {1}", consumer.GetType(), consumerReference.GetHashCode());

            CreateBindings(GetSupportedMessageTypes(consumer));

            // TODO: queue bindings are not removed, no problem unless we start adding too many instance subscriptions
            return(RemoveInstanceConsumer(consumerReference));
        }
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 /// <returns>
 /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 /// </returns>
 public override int GetHashCode()
 {
     return(_listenerWeakRef.GetHashCode());
 }
Ejemplo n.º 12
0
 public override int GetHashCode()
 {
     return(weak.GetHashCode());
 }
Ejemplo n.º 13
0
        //    if (o == this)
        //        return true;
        //    var key = (o as WeakReference<T>);
        //    if (key == null)
        //        return false;
        //    T item = Item;
        //    if (item == null)
        //        return false;
        //    return ((_hashCode == key._hashCode) && (object.Equals(item, key.Item)));

        public override int GetHashCode()
        {
            return(_wrapped.GetHashCode());
        }
Ejemplo n.º 14
0
 protected bool Equals(WeakEventHandler other)
 {
     return(Equals(_weakReference.GetHashCode(), other._weakReference));
 }