本文整理汇总了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));
}
示例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);
}
示例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;
}
示例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));
}
}
}
示例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();
}
示例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);
}
示例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 ? ":" : "");
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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());
}
示例15: AddDateTime
/// <summary>
/// Adds the date time.
/// </summary>
/// <param name="dt">The dt.</param>
public void AddDateTime(System.DateTime dt)
{
AddInt(dt.GetHashCode());
}