当前位置: 首页>>代码示例>>C#>>正文


C# System.GetHashCode方法代码示例

本文整理汇总了C#中System.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetHashCode方法的具体用法?C# System.GetHashCode怎么用?C# System.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System的用法示例。


在下文中一共展示了System.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Track

        /// <summary>
        /// Starts tracking the provided Popup.
        /// </summary>
        /// <param name="popup">The Popup to be tracked.</param>
        public static void Track(System.Windows.Controls.Primitives.Popup popup)
        {
            if (popup == null)
                throw new ArgumentNullException("popup");

            if (!s_popups.ContainsKey(popup.GetHashCode()))
                s_popups.Add(popup.GetHashCode(), new WeakReference(popup));
        }
开发者ID:mparsin,项目名称:Elements,代码行数:12,代码来源:PopupTracker.cs

示例2: Invoke

        public static object Invoke(System.Windows.Forms.Control obj, string methodName, params object[] paramValues)
        {
            Delegate del = null;
            DateTime now  = DateTime.Now;
            TimeSpan ts = now - lastCleanTime;
            if(ts.TotalHours>5)
            {
                delLookup.Clear();
                lastCleanTime = now;
            }
            string delKey = obj.GetType().Name+"."+methodName+obj.GetHashCode().ToString() + obj.ToString();
            if(delLookup.ContainsKey(delKey))
            {
                del =(Delegate) delLookup[delKey];
            }
            else
            {
                string key = obj.GetType().Name + "." + methodName;
                Type tp;
                if (methodLookup.Contains(key))
                {
                    tp = (Type)methodLookup[key];
                }
                else
                {
                    Type objType = obj.GetType();
                    object[] signatures = new object[paramValues.Length + 1];
                    signatures[0] = methodName;
                    Array.Copy(paramValues, 0, signatures, 1, paramValues.Length);
                    MemberInfo[] mInfo = objType.FindMembers(MemberTypes.Method, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, methodFilter, signatures);
                    if (mInfo.Length != 1) return null;
                    MethodInfo methInfo = (MethodInfo)mInfo[0];
                    Type[] paramList = new Type[methInfo.GetParameters().Length];
                    ParameterInfo[] paramInfos = methInfo.GetParameters();
                    int n = 0;
                    foreach (ParameterInfo pi in paramInfos)
                    {
                        paramList[n++] = pi.ParameterType;
                    }
                    TypeBuilder typeB = builder.DefineType("Del_" +
                        obj.GetType().Name + "_" + methodName,
                        TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed,
                        typeof(MulticastDelegate), PackingSize.Unspecified);
                    ConstructorBuilder conB = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName
                        | MethodAttributes.RTSpecialName, CallingConventions.Standard,
                        new Type[] { typeof(object), typeof(IntPtr) });
                    conB.SetImplementationFlags(MethodImplAttributes.Runtime);
                    MethodBuilder mb = typeB.DefineMethod("Invoke",
                        MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig,
                        methInfo.ReturnType, paramList);
                    mb.SetImplementationFlags(MethodImplAttributes.Runtime);
                    tp = typeB.CreateType();
                    methodLookup.Add(key, tp);
                }
                del = MulticastDelegate.CreateDelegate(tp, obj, methodName);
                delLookup.Add(delKey, del);
            }

            return obj.Invoke(del, paramValues);
        }
开发者ID:baidang201,项目名称:ProductExcel,代码行数:60,代码来源:SafeInvokeHelper.cs

示例3: Main

	static int Main ()
	{
		var v1 = new { Name = "Scott", Age = 21 };
		var v2 = new { Age = 20, Name = "Sam" };
		var v3 = new { Name = Null (), Age = 33 };
		
		if (v1.GetType () == v2.GetType ())
			return 1;
			
		if (v1.Equals (v2))
			return 2;
			
		if (v1.GetType () != v3.GetType ())
			return 3;
			
		if (!v1.Equals (v1))
			return 4;
					
		if (v1.GetHashCode () != v1.GetHashCode ())
			return 5;
		
		Console.WriteLine (v1);
		Console.WriteLine (v3);
		
		if (v1.ToString () != "{ Name = Scott, Age = 21 }")
			return 6;
			
		if (v3.ToString () != "{ Name = , Age = 33 }")
			return 7;

		var v4 = new {};

		if (v4.ToString () != "{ }")
			return 8;

		var v5 = new { Foo = "Bar" };
		var v6 = new { Foo = Null () };

		if (v5.ToString () != "{ Foo = Bar }")
			return 9;

		if (v6.ToString () != "{ Foo =  }")
			return 10;

		return 0;
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:46,代码来源:gtest-anontype-05.cs

示例4: Add

 public void Add(System.Action action, string message="")
 {
     if(action != null)
     {
         int hash = action.GetHashCode();
         if(!queue.Exists(x=>x.GetHashCode()==hash))
         {
             queue.Add(new stateAction(action, message));
         }
     }
 }
开发者ID:cdeeg,项目名称:ChickenTikkaMassacre,代码行数:11,代码来源:GUIStateChanger.cs

示例5: getConcreteHash

        protected override int getConcreteHash()
        {
            var anonomousType = new
            {
                f1 = Quality,
                f2 = this.Requirements != null ? string.Join(string.Empty, this.Requirements.Select(r => string.Concat(r.Name, r.Value)).ToArray()) : string.Empty,
                f3 = Color,
                f4 = Socket
            };

            return anonomousType.GetHashCode();
        }
开发者ID:sebflex,项目名称:build-optimizer,代码行数:12,代码来源:Gem.cs

示例6: AddAnimEvent

    /// <summary>
    /// 注册无参事件
    /// </summary>
    /// <param name="clip">动画片</param>
    /// <param name="time">事件</param>
    /// <param name="onAnimEvent">回调</param>
    public void AddAnimEvent(AnimationClip clip, float time, System.Action onAnimEvent)
    {
        AnimationEvent animEvent = new AnimationEvent();
        //固定一个事件方法,就不需要对每个事件都写一个
        animEvent.functionName = "OnAnimEvent";
        animEvent.time = time;
        animEvent.messageOptions = SendMessageOptions.RequireReceiver;
        //用hash码记录是哪一个回调函数,还没想到更好的方法
        animEvent.intParameter = onAnimEvent.GetHashCode();

        if (!onAnimEventDic.ContainsKey(animEvent.intParameter))
        {
            onAnimEventDic.Add(animEvent.intParameter, onAnimEvent);
        }

        clip.AddEvent(animEvent);
    }
开发者ID:zs9024,项目名称:Jungle,代码行数:23,代码来源:AnimEvent.cs

示例7: AutoPrefix

 /// <summary>
 /// 对 本结点(xNode) 的 Namespace 注册
 /// </summary>
 /// <param name="xNode">含有或继承有命名空间的结点</param>
 /// <param name="xNameSpaceManager">命名空间管理器</param>
 /// <returns>返回该 Namespace 的 prefix</returns>
 public static string AutoPrefix(System.Xml.XmlNode xNode, System.Xml.XmlNamespaceManager xNameSpaceManager)
 {
     string xPrefix;
     if (xNode.NamespaceURI == string.Empty)
     {
         return string.Empty;
     }
     else
     {
         xPrefix = xNameSpaceManager.LookupPrefix(xNode.NamespaceURI);
         if (xPrefix == null || xPrefix == string.Empty)
         {
             xPrefix = "x" + xNode.GetHashCode().ToString();
             xNameSpaceManager.AddNamespace(xPrefix, xNode.NamespaceURI);
         }
         return xPrefix + (xPrefix.Length > 0 ? ":" : "");
     }
 }
开发者ID:hijushen,项目名称:WindowDemo,代码行数:24,代码来源:XmlHelper.cs

示例8: ProxyCacheEntry

		public ProxyCacheEntry(System.Type baseType, System.Type[] interfaces)
		{
			if (baseType == null)
			{
				throw new ArgumentNullException("baseType");
			}
			BaseType = baseType;
			Interfaces = interfaces ?? new System.Type[0];

			if (Interfaces.Length == 0)
			{
				hashCode = baseType.GetHashCode();
				return;
			}

			// duplicated type exclusion
			var set = new HashSet<System.Type>(Interfaces) { baseType };
			hashCode = 59;
			foreach (System.Type type in set)
			{
				hashCode ^= type.GetHashCode();
			}
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:23,代码来源:ProxyCacheEntry.cs

示例9: Intern

		// @Override
		public override System.String Intern(System.String s)
		{
			int h = s.GetHashCode();
			// In the future, it may be worth augmenting the string hash
			// if the lower bits need better distribution.
			int slot = h & (cache.Length - 1);
			
			Entry first = this.cache[slot];
			Entry nextToLast = null;
			
			int chainLength = 0;
			
			for (Entry e = first; e != null; e = e.next)
			{
                if (e.hash == h && (ReferenceEquals(e.str, s) || String.CompareOrdinal(e.str, s) == 0))
				{
					// if (e.str == s || (e.hash == h && e.str.compareTo(s)==0)) {
					return e.str;
				}
				
				chainLength++;
				if (e.next != null)
				{
					nextToLast = e;
				}
			}
			
			// insertion-order cache: add new entry at head
			s = String.Intern(s);
			this.cache[slot] = new Entry(s, h, first);
			if (chainLength >= maxChainLength)
			{
				// prune last entry
				nextToLast.next = null;
			}
			return s;
		}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:38,代码来源:SimpleStringInterner.cs

示例10: unscheduleAllForTarget

		/** 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);
		}
开发者ID:BigWoodGames,项目名称:cocos2d-unity,代码行数:27,代码来源:CCScheduler.cs

示例11: unscheduleUpdateForTarget

		/** Unschedules the update selector for a given target
		 @since v0.99.3
		 */
		public void unscheduleUpdateForTarget(System.Object target){
			if(target == null)
				return;
			tHashUpdateEntry element = hashForUpdates.HASH_FIND_INT (target.GetHashCode());
			if (element != null) {
				if(updateHashLocked)
					element.entry.obj.markedForDeletion = true;
				else
					removeUpdatesFromHash(element.entry);
			}
		}
开发者ID:BigWoodGames,项目名称:cocos2d-unity,代码行数:14,代码来源:CCScheduler.cs

示例12: scheduleUpdate

		/** 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);
		}
开发者ID:BigWoodGames,项目名称:cocos2d-unity,代码行数:27,代码来源:CCScheduler.cs

示例13: appendIn

		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);
		}
开发者ID:BigWoodGames,项目名称:cocos2d-unity,代码行数:20,代码来源:CCScheduler.cs

示例14: CreateObject_GetHashCode_SameAsRealAnonymousObject

        public void CreateObject_GetHashCode_SameAsRealAnonymousObject()
        {
            var objA = AnonymousTypeUtils.CreateObject(new Dictionary<string, object>
            {
                { "a", 1 },
                { "b", "test" },
                { "c", new DateTime(2014, 1, 1) },
            });
            var objB = new {
                a = 1,
                b = "test",
                c = new DateTime(2014, 1, 1)
            };

            Assert.AreNotSame(objA, objB);
            Assert.AreEqual(objA.GetHashCode(), objB.GetHashCode());
        }
开发者ID:edvineshagh,项目名称:LatticeUtils,代码行数:17,代码来源:TestAnonymousTypeUtils.cs

示例15: AddDateTime

 /// <summary>
 /// Adds the date time.
 /// </summary>
 /// <param name="dt">The dt.</param>
 public void AddDateTime(System.DateTime dt)
 {
     AddInt(dt.GetHashCode());
 }
开发者ID:BclEx,项目名称:AdamsyncEx,代码行数:8,代码来源:HashCodeCombiner.cs


注:本文中的System.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。