GetHashCode() public method

public GetHashCode ( ) : int
return int
Beispiel #1
0
 public static void AssertEqualsHashCode(Object o, Object o2)
 {
     if (o.Equals(o2)) {
     if (!o2.Equals(o)) {
       Assert.Fail(
       String.Empty + o + " equals " + o2 + " but not vice versa");
     }
     // Test for the guarantee that equal objects
     // must have equal hash codes
     if (o2.GetHashCode() != o.GetHashCode()) {
       // Don't use Assert.AreEqual directly because it has
       // quite a lot of overhead
       Assert.Fail(
       String.Empty + o + " and " + o2 + " don't have equal hash codes");
     }
       } else {
     if (o2.Equals(o)) {
       Assert.Fail(String.Empty + o + " does not equal " + o2 +
     " but not vice versa");
     }
     // At least check that GetHashCode doesn't throw
     try {
      o.GetHashCode();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
     }
     try {
      o2.GetHashCode();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
     }
       }
 }
Beispiel #2
0
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;

                object currentEnum = property.GetValue(propertyTarget);

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "propertyLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.EnumPropertyDisplayAttribute)attribute).propertyName + ":";

                this.comboBox.Visible      = true;
                this.comboBox.Location     = new System.Drawing.Point(35, height + 24);
                this.comboBox.Name         = "comboBox_" + propertyTarget.GetHashCode();
                this.comboBox.Size         = new System.Drawing.Size(192, 20);
                this.comboBox.SelectedItem = null;
                this.comboBox.Items.Clear();

                Array enumList = System.Enum.GetValues(property.PropertyType);

                foreach (var item in enumList)
                {
                    this.comboBox.Items.Add(item);
                }
                this.comboBox.SelectedItem = currentEnum;

                return(height + 50);
            }
 bool HashCodesMatchEquals(System.Object obj1, System.Object obj2)
 {
     if (obj1.Equals(obj2))
     {
         return(obj1.GetHashCode() == obj2.GetHashCode());
     }
     return(obj1.GetHashCode() != obj2.GetHashCode());
 }
Beispiel #4
0
 public void removeListeners(Object context)
 {
     if(contextBinder.ContainsKey(context.GetHashCode())){
         contextBinder[context.GetHashCode()].ForEach((listener) => {
             foreach(Object key in customListeners.Keys){
                 if (customListeners[key].Contains(listener)) {
                     customListeners[key].Remove(listener);
                 }
             }
         });
         contextBinder.Remove(context.GetHashCode());
     }
 }
Beispiel #5
0
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;
                this.min            = ((RayTracerNet.NumberPropertyDisplayAttribute)attribute).min;
                this.max            = ((RayTracerNet.NumberPropertyDisplayAttribute)attribute).max;

                object value = property.GetValue(propertyTarget);

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "propertyLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.NumberPropertyDisplayAttribute)attribute).propertyName + ":";

                if (this.min > double.MinValue && this.max < double.MaxValue)
                {
                    this.propertyTrackBar.Visible  = true;
                    this.propertyTrackBar.Location = new System.Drawing.Point(35, height + 24);
                    this.propertyTrackBar.Name     = "propertyTrackBar_" + propertyTarget.GetHashCode();
                    int v = 0;
                    if (property.PropertyType == typeof(System.Double))
                    {
                        double dbvalue = (double)value;
                        v = (int)((dbvalue - this.min) / (this.max - this.min) * 5000.0);
                    }
                    else if (property.PropertyType == typeof(System.Single))
                    {
                        float flvalue = (float)value;
                        v = (int)((flvalue - this.min) / (this.max - this.min) * 5000.0);
                    }
                    else if (property.PropertyType == typeof(System.Int32))
                    {
                        int intvalue = (int)value;
                        v = (int)(((double)intvalue - this.min) / (this.max - this.min) * 5000.0);
                    }
                    this.propertyTrackBar.Value = v;
                }
                else
                {
                    this.propertyTextBox.Visible  = true;
                    this.propertyTextBox.Location = new System.Drawing.Point(35, height + 24);
                    this.propertyTextBox.Name     = "propertyTextBox_" + propertyTarget.GetHashCode();
                    this.propertyTextBox.Size     = new System.Drawing.Size(104, 21);
                    this.propertyTextBox.Text     = value.ToString();
                }

                return(height + 50);
            }
Beispiel #6
0
        public override bool Equals(Object o) 
        {
            int hashPropio = GetHashCode();
            int hashParametro = o.GetHashCode();

            return hashPropio == hashParametro;
        }
Beispiel #7
0
        /// <summary>
        /// 释放对象
        /// </summary>
        /// <returns></returns>
        public bool GiveBackObject(System.Object obj)
        {
            lock (this)
            {
                if (obj == null)
                {
                    return(false);
                }
                if (m_UsingIndexArray == null || m_FreeIndexArray == null || m_ItemTable == null)
                {
                    return(false);
                }
                if (m_bSupportRecycle == true)
                {
                    IRecycleable recycleable = (IRecycleable)obj;
                    if (recycleable != null)
                    {
                        recycleable.Clear();
                    }
                }
                Int32 nHashCode = obj.GetHashCode();
                if (m_UsingIndexArray.Contains(nHashCode) == false)
                {
                    return(false);
                }

                m_UsingIndexArray.Remove(nHashCode);
                m_FreeIndexArray.Add(nHashCode);
                return(true);
            }
        }
Beispiel #8
0
        private bool ExtendPool()
        {
            lock (this)
            {
                if (Count() >= m_nCapacity)
                {
                    return(false);
                }

                System.Object newObject = null;
                try
                {
                    newObject = System.Activator.CreateInstance(m_ObjectType, m_objDefaultCreateParam);
                }
                catch (System.Exception ex)
                {
                    BTDebug.Exception(ex);
                    return(false);
                }

                Int32 nHashCode = newObject.GetHashCode();
                m_ItemTable.Add(nHashCode, newObject);
                m_FreeIndexArray.Add(nHashCode);
                return(true);
            }
        }
        private static void checkEqualsAndHashCodeMethods(Object lhs, Object rhs,
                                                          bool expectedResult)
        {
            if ((lhs == null) && (rhs == null))
            {
                assertTrue(
                    "Your check is dubious...why would you expect null != null?",
                    expectedResult);
                return;
            }

            if ((lhs == null) || (rhs == null))
            {
                assertFalse(
                    "Your check is dubious...why would you expect an object "
                    + "to be equal to null?", expectedResult);
            }

            if (lhs != null)
            {
                assertEquals(expectedResult, lhs.Equals(rhs));
            }
            if (rhs != null)
            {
                assertEquals(expectedResult, rhs.Equals(lhs));
            }

            if (expectedResult)
            {
                var hashMessage =
                    "hashCode() values for equal objects should be the same";
                assertTrue(hashMessage, lhs.GetHashCode() == rhs.GetHashCode());
            }
        }
Beispiel #10
0
		/// <summary>
		/// Calls Verify() with the object and it's type.
		/// </summary>
		/// <param name="verifiableObject">Object to verify</param>
		public static void Verify(Object verifiableObject) 
		{
			if ( !_verifiedObjects.Contains( verifiableObject.GetHashCode() ) )
			{
				verify(verifiableObject, verifiableObject.GetType());
			}
		}
        void appendIn(utList <tListEntry> list, System.Object target, bool paused)
        {
            tListEntry listEntry = new tListEntry();

            listEntry.target            = target;
            listEntry.paused            = paused;
            listEntry.markedForDeletion = false;
            MethodInfo method = target.GetType().GetMethod(updateSelector);

            listEntry.impMethod = (TICK_IMP)Delegate.CreateDelegate(typeof(TICK_IMP), target, method);

            utNode <tListEntry> listElement = new utNode <tListEntry> ();

            listElement.next = listElement.prev = null;
            listElement.obj  = listEntry;

            list.DL_APPEND(listElement);

            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            hashForUpdates.HASH_ADD_INT(target.GetHashCode(), hashElement);
        }
 public static void Log_Debug(this System.Object obj, string message)
 {
     if (KabinKraziness.Instance != null && KabinKraziness.Instance.debugging)
     {
         Debug.Log(obj.GetType().FullName + "[" + obj.GetHashCode().ToString("X") + "][" + Time.time.ToString("0.00") + "]: " + message);
     }
 }
        /** Unschedules all selectors and blocks for a given target.
         * This also includes the "update" selector.
         * @since v0.99.3
         */
        public void unscheduleAllForTarget(System.Object target)
        {
            // explicit nil handling
            if (target == null)
            {
                return;
            }

            // Custom Selectors
            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element != null)
            {
                if (element.timers.Contains(element.currentTimer) && !element.currentTimerSalvaged)
                {
                    element.currentTimerSalvaged = true;
                }
                element.timers.Clear();
                if (currentTarget == element)
                {
                    currentTargetSalvaged = true;
                }
                else
                {
                    removeHashElement(element);
                }
            }

            // Update Selector
            unscheduleUpdateForTarget(target);
        }
Beispiel #14
0
        public override bool Equals(Object obj)
        {
            if (obj.GetHashCode() == (Int32)key_)
                return true;

            return false;
        }
Beispiel #15
0
 /// <summary>
 /// Does a quick and simple combination of the Hash Codes of two Objects
 /// </summary>
 /// <param name="x">First Object</param>
 /// <param name="y">Second Object</param>
 /// <returns></returns>
 public static int CombineHashCodes(Object x, Object y)
 {
     int hash = 17;
     hash = hash * 31 + x.GetHashCode();
     hash = hash * 31 + y.GetHashCode();
     return hash;
 }
        /** Schedules the 'update' selector for a given target with a given priority.
         * The 'update' selector will be called every frame.
         * The lower the priority, the earlier it is called.
         * @since v0.99.3
         */
        public void scheduleUpdate(System.Object target, int priority, bool paused)
        {
            tHashUpdateEntry hashElement = hashForUpdates.HASH_FIND_INT(target.GetHashCode());

            if (hashElement != null)
            {
                if (CCDebug.COCOS2D_DEBUG >= 1)
                {
                    NSUtils.Assert(hashElement.entry.obj.markedForDeletion, "CCScheduler: You can't re-schedule an 'update' selector'. Unschedule it first");
                }

                // TODO : check if priority has changed!
                hashElement.entry.obj.markedForDeletion = false;
                return;
            }


            // most of the updates are going to be 0, that's way there
            // is an special list for updates with priority 0
            if (priority == 0)
            {
                appendIn(updates0, target, paused);
            }
            else if (priority < 0)
            {
                priorityIn(updatesNeg, target, priority, paused);
            }
            else             // priority > 0
            {
                priorityIn(updatesPos, target, priority, paused);
            }
        }
Beispiel #17
0
 public HashCodeHelper Add(Object obj)
 {
     unchecked
     {
         Hash = Hash * 31 + obj.GetHashCode();
     }
     return this;
 }
        void priorityIn(utList <tListEntry> list, System.Object target, int priority, bool paused)
        {
            tListEntry listEntry = new tListEntry();

            listEntry.target   = target;
            listEntry.priority = priority;
            listEntry.paused   = paused;
            MethodInfo method = target.GetType().GetMethod(updateSelector);

            listEntry.impMethod         = (TICK_IMP)Delegate.CreateDelegate(typeof(TICK_IMP), target, method);
            listEntry.markedForDeletion = false;

            utNode <tListEntry> listElement = new utNode <tListEntry> ();

            listElement.next = listElement.prev = null;
            listElement.obj  = listEntry;


            if (list.head == null)
            {
                list.DL_APPEND(listElement);
            }
            else
            {
                bool added = false;
                for (utNode <tListEntry> elem = list.head; elem != null; elem = elem.next)
                {
                    if (priority < elem.obj.priority)
                    {
                        if (elem == list.head)
                        {
                            list.DL_PREPEND(listElement);
                        }
                        else
                        {
                            listElement.next = elem;
                            listElement.prev = elem.prev;

                            elem.prev.next = listElement;
                            elem.prev      = listElement;
                        }
                        added = true;
                        break;
                    }
                }

                if (!added)
                {
                    list.DL_APPEND(listElement);
                }
            }
            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            hashForUpdates.HASH_ADD_INT(target.GetHashCode(), hashElement);
        }
        /// <summary> Tests a CacheEntry[] for indication of "insane" cache usage.
        /// <p/>
        /// NOTE:FieldCache CreationPlaceholder objects are ignored.
        /// (:TODO: is this a bad idea? are we masking a real problem?)
        /// <p/>
        /// </summary>
        public Insanity[] Check(params CacheEntry[] cacheEntries)
        {
            if (null == cacheEntries || 0 == cacheEntries.Length)
            {
                return(new Insanity[0]);
            }

            if (null != ramCalc)
            {
                for (int i = 0; i < cacheEntries.Length; i++)
                {
                    cacheEntries[i].EstimateSize(ramCalc);
                }
            }

            // the indirect mapping lets MapOfSet dedup identical valIds for us
            //
            // maps the (valId) identityhashCode of cache values to
            // sets of CacheEntry instances
            MapOfSets <int, CacheEntry> valIdToItems = new MapOfSets <int, CacheEntry>(new Dictionary <int, HashSet <CacheEntry> >(17));
            // maps ReaderField keys to Sets of ValueIds
            MapOfSets <ReaderField, int> readerFieldToValIds = new MapOfSets <ReaderField, int>(new Dictionary <ReaderField, HashSet <int> >(17));
            //

            // any keys that we know result in more then one valId
            HashSet <ReaderField> valMismatchKeys = new HashSet <ReaderField>();

            // iterate over all the cacheEntries to get the mappings we'll need
            for (int i = 0; i < cacheEntries.Length; i++)
            {
                CacheEntry    item = cacheEntries[i];
                System.Object val  = item.Value;

                if (val.GetType().IsGenericType&&
                    val.GetType().GetGenericTypeDefinition() == typeof(Lazy <>))
                {
                    continue;
                }

                ReaderField rf = new ReaderField(item.ReaderKey, item.FieldName);

                System.Int32 valId = val.GetHashCode();

                // indirect mapping, so the MapOfSet will dedup identical valIds for us
                valIdToItems.Put(valId, item);
                if (1 < readerFieldToValIds.Put(rf, valId))
                {
                    valMismatchKeys.Add(rf);
                }
            }

            List <Insanity> insanity = new List <Insanity>(valMismatchKeys.Count * 3);

            insanity.AddRange(CheckValueMismatch(valIdToItems, readerFieldToValIds, valMismatchKeys));
            insanity.AddRange(CheckSubreaders(valIdToItems, readerFieldToValIds));

            return(insanity.ToArray());
        }
        public void scheduleBlockForKey(string key, System.Object owner, float interval, uint repeat, float delay, bool paused, TICK_IMP block)
        {
            NSUtils.Assert(block != null, "Argument block must be non-nil");
            NSUtils.Assert(owner != null, "Argument owner must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(owner.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = owner;
                hashForTimers.HASH_ADD_INT(owner.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a block with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerBlock && key == ((CCTimerBlock)timer).key)
                    {
                        CCDebug.Log("CCScheduler#scheduleBlock. Block already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }

            CCTimerBlock timerBlock = new CCTimerBlock(owner, interval, key, block, repeat, delay);

            element.timers.Add(timerBlock);
        }
Beispiel #21
0
 // Notifies a handler that an object has been unmarshaled.
 public void UnmarshaledObject(Object obj, ObjRef or)
 {
     if (obj.GetType() != typeof(AppDomain))
         Trace.WriteLine(string.Format("Tangra Addins: Unmarshaled instance of {0} ({1} HashCode:{2})", or.TypeInfo != null ? or.TypeInfo.TypeName : obj.GetType().ToString(), or.URI != null ? or.URI.ToString() : "N/A", obj.GetHashCode().ToString()));
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
Beispiel #22
0
 internal void UnregisterEventListener(Enum pEvent, Object pListenerParent)
 {
     if (mEventDictionnary.ContainsKey(pEvent))
     {
         EventListener eventListener = mEventDictionnary[pEvent].FirstOrDefault((currentEventListener) => { return currentEventListener.ListenerHashCode == pListenerParent.GetHashCode(); });
         mEventDictionnary[pEvent].Remove(eventListener);
         UnregisterEventListener(eventListener);
     }
 }
Beispiel #23
0
 // Notifies a handler that an object has been disconnected.
 public void DisconnectedObject(Object obj)
 {
     if (obj.GetType() != typeof(AppDomain))
         Trace.WriteLine(string.Format("Tangra Addins: Disconnected instance of {0} (HashCode:{1})", obj.GetType().ToString(), obj.GetHashCode().ToString()));
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
        /** The scheduled method will be called every 'interval' seconds.
         * If paused is YES, then it won't be called until it is resumed.
         * If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
         * If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         * repeat lets the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
         * delay is the amount of time the action will wait before it'll start
         *
         * @since v0.99.3, repeat and delay added in v1.1
         */
        public void schedule(TICK_IMP selector, System.Object target, float interval, uint repeat, bool paused, float delay = 0)
        {
            NSUtils.Assert(selector != null, "Argument selector must be non-nil");
            NSUtils.Assert(target != null, "Argument target must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = target;
                hashForTimers.HASH_ADD_INT(target.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a selector with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector)
                    {
                        CCDebug.Log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }
            CCTimerTargetSelector timerSelector = new CCTimerTargetSelector(target, selector, interval, repeat, delay);

            element.timers.Add(timerSelector);
        }
Beispiel #25
0
 public override int GetHashCode()
 {
     unchecked
     {
         int r = _objref == null ? 0 : _objref.GetHashCode();
         r = r * 397 + _ulong_value1.GetHashCode();
         r = r * 397 + _flags;
         return(r);
     }
 }
Beispiel #26
0
 public void FreeObject(System.Object obj)
 {
     lock (this)
     {
         int key = obj.GetHashCode();
         if (_listObjects.ContainsKey(key))
         {
             PoolItem item = (PoolItem)_listObjects[key];
             item.Using = false;
             _listUsingIndex.Remove(key);
             _listFreeIndex.Add(key);
         }
         else
         {
             //throw new InvalidOperationException("试图归还一个非法的资源!ID:" + obj.GetHashCode() + obj);
             Debug.LogWarning("试图归还一个非法的资源!ID:" + key + obj + obj.GetHashCode());
         }
     }
 }
Beispiel #27
0
        public static void HashCode(ref int hash, System.Object obj)
        {
            if (obj == null)
            {
                return;
            }
            int hashValue = obj.GetHashCode();

            HashCode(ref hash, hashValue);
        }
Beispiel #28
0
        private static int GetHashCode(Object Instance,IntPtr l)
        {
            // get method arguments

                  // call method
                  Int32 methodRetVar = Instance.GetHashCode();

                  LuaApi.lua_pushnumber(l,methodRetVar);
                  return 1;
        }
        public int GetHashCode(Object obj) {
            if (obj == null) return 0;

            IStructuralEquatable seObj = obj as IStructuralEquatable;

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

            return obj.GetHashCode();
        }
        public int GetHashCode(Object obj) {
            if (obj==null) {
                throw new ArgumentNullException("obj");
            }

            String s = obj as String;
            if (s==null) {
                return obj.GetHashCode();
            }

            return m_text.GetCaseInsensitiveHashCode(s);
        }
 public override bool Equals(Object o)
 {
     if (o == null)
     {
         return false;
     }
     if (this.GetType() == o.GetType())
     {
         return o.GetHashCode() == this.GetHashCode();
     }
     return false;
 }
Beispiel #32
0
        public Object Get(Object key)
        {
            int hash = key.GetHashCode();
            int lookup = GetLookup(key, hash);

            if (lookup != -1)
            {
                return objectValueTable[lookup];
            }

            return null;
        }
Beispiel #33
0
 // Notifies a handler that an object has been disconnected.
 public void DisconnectedObject(Object obj)
 {
     if (obj.GetType() != typeof(AppDomain))
     {
         if (TraceSwitchAppDomainTracking.Enabled)
             Trace.WriteLine(string.Format("OccuRec: Disconnected instance of {0} (HashCode:{1})", obj.GetType().ToString(), obj.GetHashCode().ToString()));
     }
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
        /** Pauses the target.
         * All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed.
         * If the target is not present, nothing happens.
         * @since v0.99.3
         */
        public void pauseTarget(System.Object target)
        {
            NSUtils.Assert(target != null, "target must be non nil");

            // Custom selectors
            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element != null)
            {
                element.paused = true;
            }

            // Update selector
            tHashUpdateEntry elementUpdate = hashForUpdates.HASH_FIND_INT(target.GetHashCode());

            if (elementUpdate != null)
            {
                NSUtils.Assert(elementUpdate.entry != null, "pauseTarget: unknown error");
                elementUpdate.entry.obj.paused = true;
            }
        }
Beispiel #35
0
 // Notifies a handler that an object has been marshaled.
 public void MarshaledObject(Object obj, ObjRef or)
 {
     if (obj.GetType() != typeof(AppDomain))
     {
         if (TraceSwitchAppDomainTracking.Enabled)
             Trace.WriteLine(string.Format("OccuRec: Marshaled instance of {0} ({1} HashCode:{2})", or.TypeInfo != null ? or.TypeInfo.TypeName : obj.GetType().ToString(), or.URI != null ? or.URI.ToString() : "N/A", obj.GetHashCode().ToString()));
     }
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
        public void unscheduleBlockForKey(string key, System.Object target)
        {
            // explicity handle nil arguments when removing an object
            if (target == null && key == null)
            {
                return;
            }

            NSUtils.Assert(target != null, "Target MUST not be nil");
            NSUtils.Assert(key != null, "key MUST not be NULL");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element != null)
            {
                for (int i = 0; i < element.timers.Count; i++)
                {
                    CCTimer timer = element.timers[i];


                    if (timer is CCTimerBlock && key == ((CCTimerBlock)timer).key)
                    {
                        if (timer == element.currentTimer && !element.currentTimerSalvaged)
                        {
                            element.currentTimerSalvaged = true;
                        }

                        element.timers.RemoveAt(i);

                        // update timerIndex in case we are in tick:, looping over the actions
                        if (element.timerIndex >= i)
                        {
                            element.timerIndex--;
                        }

                        if (element.timers.Count == 0)
                        {
                            if (currentTarget == element)
                            {
                                currentTargetSalvaged = true;
                            }
                            else
                            {
                                removeHashElement(element);
                            }
                        }
                        return;
                    }
                }
            }
            // Not Found
            //	NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString);
        }
        /** Returns whether or not the target is paused
         * @since v1.0.0
         */
        public bool isTargetPaused(System.Object target)
        {
            NSUtils.Assert(target != null, "target must be non nil");

            // Custom selectors
            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element != null)
            {
                return(element.paused);
            }

            // We should check update selectors if target does not have custom selectors
            tHashUpdateEntry elementUpdate = hashForUpdates.HASH_FIND_INT(target.GetHashCode());

            if (elementUpdate != null)
            {
                return(elementUpdate.entry.obj.paused);
            }

            return(false);             // should never get here
        }
Beispiel #38
0
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;

                bool currentValue = (bool)property.GetValue(propertyTarget);

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "propertyLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.SwitchPropertyDisplayAttribute)attribute).propertyName + ":";

                this.propertyCheckBox.Visible  = true;
                this.propertyCheckBox.Location = new System.Drawing.Point(35, height + 24);
                this.propertyCheckBox.Name     = "checkBox_" + propertyTarget.GetHashCode();
                this.propertyCheckBox.Size     = new System.Drawing.Size(192, 20);
                this.propertyCheckBox.Text     = ((RayTracerNet.SwitchPropertyDisplayAttribute)attribute).propertyName;
                this.propertyCheckBox.Checked  = currentValue;

                return(height + 50);
            }
Beispiel #39
0
        static void Main(string[] args)
        {
            //System.Object
            //TODAS as classes e structs herdam de Object
            //Tipo: class e struct (e ...)
            //Membro: campo, propriedade, método, evento (e ...)

            //Tipo nome;
            //nome = new Tipo();
            //new cria uma instância da classe (objeto) Object
            //Object é reference type

            Object o = new Object();

            Console.WriteLine(o.ToString());
            //representação String do objeto
            //Namespace.Tipo

            Console.WriteLine(o.GetHashCode());
            //representação numérica do objeto
            //SE hashcodes de dois objetos são diferentes,
            //os objetos SÃO diferentes
            //SE os hashcodes forem iguais PODE SER que os
            //objetos sejam iguais

            Console.WriteLine(o.GetType().Name);
            //retorna o Type de um objeto
            //esse type será usado em Reflection,
            //entre outras coisas

            Object p = new Object();

            Console.WriteLine(o.Equals(p));
            //Equals compara dois objetos

            //o = p = null;

            //Não podemos acessar membros de null
            //não há objeto onde buscar esses membros
            //Console.WriteLine(o.Equals(p));

            //Equals, ToString, GetHashCode e GetType são
            //métodos de INSTÂNCIA

            Console.WriteLine(Object.Equals(o, p));
            Console.WriteLine(Object.ReferenceEquals(o, p));
            //Equals e ReferenceEquals são métodos static

            Console.ReadKey();
        }
        private static void testCall()
        {
            Console.WriteLine(); // Вызов статического метода
            Object o = new Object();
            o.GetHashCode(); // Вызов виртуального экземплярного метода
            o.GetType(); // Вызов невиртуального экземплярного метода

            Point p = new Point(3, 4);
            // Компилятор C# вставит здесь инструкцию callvirt,
            // но JIT-компилятор оптимизирует этот вызов и сгенерирует код
            // для невиртуального вызова ToString,
            // поскольку p имеет тип Point, являющийся запечатанным
            Console.WriteLine(p.ToString());
        }
Beispiel #41
0
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;
                //this.resourceType = attribute.resourceType;
                object currentRes = property.GetValue(propertyTarget);

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "propertyLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.ResourcePropertyDisplayAttribute)attribute).propertyName + ":";

                this.comboBox.Visible      = true;
                this.comboBox.Location     = new System.Drawing.Point(35, height + 24);
                this.comboBox.Name         = "comboBox_" + propertyTarget.GetHashCode();
                this.comboBox.Size         = new System.Drawing.Size(192, 20);
                this.comboBox.SelectedItem = null;
                this.comboBox.Items.Clear();

                List <ResourceObject> resourceObjects = RayTracerNet.RayTracer.GetInstance().GetScene().resourceList;

                if (resourceObjects != null)
                {
                    foreach (var resource in resourceObjects)
                    {
                        //if (resource.GetType() == property.PropertyType)
                        if (property.PropertyType.IsInstanceOfType(resource))
                        {
                            this.comboBox.Items.Add(resource);
                        }
                    }
                }
                this.comboBox.SelectedItem = currentRes;

                return(height + 50);
            }
Beispiel #42
0
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;

                object currentValue = property.GetValue(propertyTarget);

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "propertyLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.TextPropertyDisplayAttribute)attribute).propertyName + ":" + currentValue.ToString();

                return(height + 30);
            }
Beispiel #43
0
    // TODO: maybe use StringBuilder better
    public override int GetHashCode()
    {
        string str = id.ToString();

        if (src != null)
        {
            str += "@#$%^&*" + src.GetHashCode().ToString();
        }

        if (target != null)
        {
            str += "@#$%^&*" + target.GetHashCode().ToString();
        }
        return(str.GetHashCode());
    }
Beispiel #44
0
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;

                RayTracerNet.Color color = (RayTracerNet.Color)property.GetValue(propertyTarget);

                System.Drawing.Color syscolor = color.ToSystemColor();

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "propertyLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.ColorPropertyDisplayAttribute)attribute).propertyName + ":";

                this.propertyButton.Visible   = true;
                this.propertyButton.Location  = new System.Drawing.Point(35, height + 24);
                this.propertyButton.Name      = "propertyButton_" + propertyTarget.GetHashCode();
                this.propertyButton.Size      = new System.Drawing.Size(192, 20);
                this.propertyButton.Text      = syscolor.Name;
                this.propertyButton.ForeColor = syscolor;

                return(height + 50);
            }
        void removeUpdatesFromHash(utNode <tListEntry> entry)
        {
            tHashUpdateEntry element = hashForUpdates.HASH_FIND_INT(entry.obj.target.GetHashCode());

            if (element != null)
            {
                // list entry
                element.list.DL_DELETE(element.entry);
                element.entry = null;

                // hash entry
                System.Object target = element.target;
                hashForUpdates.HASH_DEL(target.GetHashCode());
            }
        }
Beispiel #46
0
 /// <summary>
 /// 获取事件ID
 /// 此事件ID数据实例级别,可以通过<b>实例+事件类型调用</b>
 /// </summary>
 /// <param name="instance">实例</param>
 /// <param name="eventType">事件类型(触发类型)</param>
 /// <param name="istoeventtype">在类型为null值,是否转成 通过事件类型触发</param>
 /// <returns></returns>
 public static int GetEventID(System.Object instance, EventType eventType, bool istoeventtype = false)
 {
     if (instance == null && istoeventtype)
     {
         return(GetEventID(eventType));
     }
     else if (instance == null)
     {
         return(-1);
     }
     else
     {
         return(instance.GetHashCode() * (int)eventType);
     }
 }
Beispiel #47
0
        /// <since> 1.5
        /// </since>
        public static int hashCode(System.Object[] a)
        {
            if (a == null)
            {
                return(0);
            }
            int hash = 1;

            for (int i = 0; i < a.Length; i++)
            {
                System.Object e = a[i];
                hash = 31 * hash + (e == null ? 0 : e.GetHashCode());
            }
            return(hash);
        }
        /** Unshedules a selector for a given target.
         * If you want to unschedule the "update", use unscheudleUpdateForTarget.
         * @since v0.99.3
         */
        public void unscheduleSelector(TICK_IMP selector, System.Object target)
        {
            if (target == null && selector == null)
            {
                return;
            }

            NSUtils.Assert(target != null, "Target MUST not be nil");
            NSUtils.Assert(selector != null, "Selector MUST not be NULL");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element != null)
            {
                int timersCount = element.timers.Count;
                for (int i = 0; i < timersCount; i++)
                {
                    CCTimer timer = element.timers[i];
                    if (timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector)
                    {
                        if (timer == element.currentTimer && !element.currentTimerSalvaged)
                        {
                            element.currentTimerSalvaged = true;
                        }
                        element.timers.RemoveAt(i);
                        if (element.timerIndex >= i)
                        {
                            element.timerIndex--;
                        }
                        if (element.timers.Count == 0)
                        {
                            if (currentTarget == element)
                            {
                                currentTargetSalvaged = true;
                            }
                            else
                            {
                                removeHashElement(element);
                            }
                        }
                        return;
                    }
                }
            }

            // Not Found
            //	NSLog(@"CCScheduler#unscheduleSelector:forTarget: selector not found: %@", selString);
        }
	// Implement the IHashCodeProvider interface.
	public int GetHashCode(Object obj)
			{
				String str = (obj as String);
				if(str != null)
				{
					return info.ToLower(str).GetHashCode();
				}
				else if(obj != null)
				{
					return obj.GetHashCode();
				}
				else
				{
					throw new ArgumentNullException("obj");
				}
			}
        static StackObject *GetHashCode_2(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object instance_of_this_method = (System.Object) typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetHashCode();

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method;
            return(__ret + 1);
        }
        /// <include file='doc\CaseInsensitiveHashCodeProvider.uex' path='docs/doc[@for="CaseInsensitiveHashCodeProvider.GetHashCode"]/*' />
        public int GetHashCode(Object obj) {
            if (obj==null) {
                throw new ArgumentNullException("obj");
            }

            String s = obj as String;
            if (s==null) {
                return obj.GetHashCode();
            }

            if (s.IsFastSort()) {
                return TextInfo.GetDefaultCaseInsensitiveHashCode(s);
            } else {
                return m_text.GetCaseInsensitiveHashCode(s);
            }
        }
Beispiel #52
0
        public int Get(Object key, int defaultValue)
        {
            if (key == null)
            {
                throw new NoSuchElementException();
            }

            int hash = key.GetHashCode();
            int lookup = GetLookup(key, hash);

            if (lookup != -1)
            {
                return intValueTable[lookup];
            }

            return defaultValue;
        }
Beispiel #53
0
		/// <summary>
		/// Iterates through an object until it's at the root type.  
		/// Then it collects all the fields according to the BindingFlags and calls verify() on
		/// each field.
		/// </summary>
		/// <param name="verifiableObject">Object to verify.</param>
		/// <param name="currentType">Current Type.</param>
		private static void verify(Object verifiableObject, Type currentType)
		{
			if (isRootType(currentType)) 
			{
				return;
			}

			verify(verifiableObject, currentType.BaseType);

			FieldInfo[] fields = currentType.GetFields(_bindingFlags);
	
			foreach (FieldInfo field in fields)
			{
				verifyField(field, verifiableObject);
			}
			_verifiedObjects.Add( verifiableObject.GetHashCode() );
		}
        // The data structure consuming this will be responsible for dealing with null objects as keys.
        public int GetHashCode( Object obj )
        {
            String str = obj as String;

            if (str == null)
                return obj.GetHashCode();

            int iComma = str.IndexOf( ',' );
            if (iComma == -1)
                iComma = str.Length;

            int accumulator = 0;
            for (int i = 0; i < iComma; ++i)
            {
                accumulator = (accumulator << 7) ^ str[i] ^ (accumulator >> 25);
            }

            return accumulator;
        }
Beispiel #55
0
        /// <summary>Closes the given connection & removes from hash - to be called when there are 0 references to it </summary>
        private void  close(NuGenConnection c)
        {
            c.close();

            //remove from "connections"
            System.Collections.IEnumerator keys = new SupportClass.HashSetSupport(connections.Keys).GetEnumerator();
            bool removed = false;

            while (keys.MoveNext() && !removed)
            {
                System.Object key = keys.Current;
                System.Object val = connections[key];
                if (val.GetHashCode() == c.GetHashCode())
                {
                    connections.Remove(key);
                    numRefs.Remove(key);
                    removed = true;
                }
            }
        }
Beispiel #56
0
        static void Main(string[] args)
        {
            //declarar
            //Tipo nome;

            Object o;

            //inicializar
            //nome = new Tipo()

            o = new Object();

            Console.WriteLine(o.ToString());
            Console.WriteLine(o.GetHashCode());
            Console.WriteLine(o.GetType());

            o = null;

            Console.ReadKey();
        }
Beispiel #57
0
        // The data structure consuming this will be responsible for dealing with null objects as keys.
        public int GetHashCode(Object obj)
        {            
            if (obj == null) throw new ArgumentNullException("obj");
            Contract.EndContractBlock();
            
            String str = obj as String;

            if (str == null)
                return obj.GetHashCode();

            int iComma = str.IndexOf( ',' );
            if (iComma == -1)
                iComma = str.Length;

            int accumulator = 0;
            for (int i = 0; i < iComma; ++i)
            {
                accumulator = (accumulator << 7) ^ str[i] ^ (accumulator >> 25);
            }

            return accumulator;
        }
Beispiel #58
0
 public static void AssertEqualsHashCode(Object o, Object o2)
 {
     if (o.Equals(o2)) {
     if (!o2.Equals(o))
       Assert.Fail(
     String.Format(CultureInfo.InvariantCulture,
                   "{0} equals {1}, but not vice versa", o, o2));
     // Test for the guarantee that equal objects
     // must have equal hash codes
     if (o2.GetHashCode() != o.GetHashCode()) {
       // Don't use Assert.AreEqual directly because it has
       // quite a lot of overhead
       Assert.Fail(
     String.Format(CultureInfo.InvariantCulture,
                   "{0} and {1} don't have equal hash codes", o, o2));
     }
       } else {
     if (o2.Equals(o))
       Assert.Fail(
     String.Format(CultureInfo.InvariantCulture,
                   "{0} does not equal {1}, but not vice versa", o, o2));
       }
 }
Beispiel #59
0
 // Internal method to get the hash code for an Object.  This will call
 // GetHashCode() on each object if you haven't provided an IHashCodeProvider
 // instance.  Otherwise, it calls hcp.GetHashCode(obj).
 protected virtual int GetHash(Object key)
 {
     if (_keycomparer != null)
         return _keycomparer.GetHashCode(key);
     return key.GetHashCode();
 }
Beispiel #60
0
 public override bool Equals(Object obj)
 {
     if (obj == null || !(obj is ByteStore))
         return false;
     if (GetHashCode() != obj.GetHashCode())
         return false;
     byte[] b2 = ((ByteStore)obj).b;
     if (b2.Length != b.Length)
         return false;
     int len = b.Length;
     for (int k = 0; k < len; ++k) {
         if (b[k] != b2[k])
             return false;
     }
     return true;
 }