本文整理汇总了C#中System.Type.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetHashCode方法的具体用法?C# Type.GetHashCode怎么用?C# Type.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEntity2Info
/// <summary>
/// Get the <see cref="EntityInfo"/> object from the cache.
/// </summary>
/// If the <paramref name="type"/> has no <see cref="EntityInfo"/> then it will add the and return the <see cref="EntityInfo"/>.
/// <param name="type"></param>
/// <returns></returns>
public static SimpleAccess.Core.Entity.EntityInfo<OracleSqlBuilder, OracleParameter> GetEntity2Info(Type type)
{
Core.Entity.EntityInfo<OracleSqlBuilder, OracleParameter> entityInfo = null;
if (Entity2Infos.TryGetValue(type.GetHashCode(), out entityInfo))
return entityInfo;
entityInfo = new Core.Entity.EntityInfo<OracleSqlBuilder, OracleParameter>(type);
Entity2Infos.Add(type.GetHashCode(), entityInfo);
return entityInfo;
}
示例2: GetEntityInfo
public static EntityInfo GetEntityInfo(Type type)
{
EntityInfo entityInfo = null;
if (EntityInfos.TryGetValue(type.GetHashCode(), out entityInfo))
return entityInfo;
entityInfo = new EntityInfo(type);
EntityInfos.Add(type.GetHashCode(), entityInfo);
return entityInfo;
}
示例3: GetDiscriminatingTypeForCached
/// <summary>
/// Retrieves type discriminators from cache to avoid calling Type.IsDefined(),
/// which needs to be called very often (walking the hierarchy) and is quite
/// expensive per call.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private static Type GetDiscriminatingTypeForCached(Type type)
{
lock (DiscriminatorCacheSyncRoot)
{
if (DiscriminatorDictionary.Contains(type.GetHashCode()))
return (Type)(DiscriminatorDictionary[type.GetHashCode()]);
else
{
Type result = GetDiscriminatingTypeForInternal(type);
DiscriminatorDictionary.Add(type.GetHashCode(), result);
return result;
}
}
}
示例4:
internal TypeReflector this[Type type]
{
get
{
int index = type.GetHashCode() % this.table.Length;
for (TypeReflector reflector = this.table[index]; reflector != null; reflector = reflector.next)
{
if (reflector.type == type)
{
return reflector;
}
}
return null;
}
set
{
if (++this.count >= this.threshold)
{
this.Rehash();
}
int index = (int) (value.hashCode % this.table.Length);
value.next = this.table[index];
this.table[index] = value;
}
}
示例5: CompareTypes
static void CompareTypes(Type firstType, Type secondType)
{
var firstHashCode = firstType.GetHashCode();
var secondHashCode = secondType.GetHashCode();
Console.WriteLine("{0} != {1} ?", firstHashCode, secondHashCode);
Assert.That(firstHashCode, Is.Not.EqualTo(secondHashCode));
}
示例6: GetProperty
public static ExtendProperty GetProperty(Type ownerType, string propertyName)
{
int propertyKey = ownerType.GetHashCode() ^ propertyName.GetHashCode();
var property = ExtendPropertysProvider.Get(propertyKey);
property.OwnerType = ownerType;
return property;
}
示例7: SpecializationKey
public SpecializationKey(Type entityType, FileType fileType)
{
FileType = fileType;
SpecializationType = entityType;
hash = entityType.GetHashCode() ^ fileType.GetHashCode();
}
示例8: ProxyCacheEntry
public ProxyCacheEntry(Type baseType, Type[] interfaces)
{
if (baseType == null)
{
throw new ArgumentNullException("baseType");
}
BaseType = baseType;
Interfaces = interfaces;
if (interfaces == null || interfaces.Length == 0)
{
hashCode = baseType.GetHashCode();
return;
}
// duplicated type exclusion
Dictionary<Type, object> set = new Dictionary<Type, object>(interfaces.Length + 1);
set[baseType] = null;
foreach (Type type in interfaces)
{
if (type != null)
set[type] = null;
}
hashCode = 0;
foreach (Type type in set.Keys)
{
hashCode ^= type.GetHashCode();
}
}
示例9: FromName
public static DependencyProperty FromName(string propertyName, Type ownerType)
{
if (propertyName == null)
{
throw new ArgumentNullException("propertyName");
}
if (ownerType == null)
{
throw new ArgumentNullException("ownerType");
}
DependencyProperty property = null;
while ((property == null) && (ownerType != null))
{
RuntimeHelpers.RunClassConstructor(ownerType.TypeHandle);
int key = propertyName.GetHashCode() ^ ownerType.GetHashCode();
lock (((ICollection) dependencyProperties).SyncRoot)
{
if (dependencyProperties.ContainsKey(key))
{
property = dependencyProperties[key];
}
}
ownerType = ownerType.BaseType;
}
return property;
}
示例10: Generate
public static string Generate(Type type)
{
const string format = "{0}::{1}-{2}#{3}";
if (type == null)
throw new ArgumentNullException("type");
var hashCode = type.GetHashCode();
var attributes =
type.GetMembers().SelectMany(x => x.GetCustomAttributes(true)).Concat(type.GetCustomAttributes(true));
var nonPublicMembers = type.GetMembers(BindingFlags.NonPublic | BindingFlags.Instance);
var statics = type.GetMembers(BindingFlags.Static | BindingFlags.Public);
var items = type.GetMembers().Concat(attributes).Concat(nonPublicMembers).Concat(statics).ToArray();
var typeCode = items.First().GetHashCode();
typeCode = items.Skip(1).Aggregate(typeCode, (current, item) => current ^ item.GetHashCode());
var asmDate = File.GetLastWriteTime(type.Assembly.Location);
return String.Format(format, hashCode.ToString("X"), typeCode, items.Count(),
asmDate.Ticks.ToString("X"));
}
示例11: ReflectedType
public ReflectedType(Type type)
{
UnderlyingType = type;
TypeName = type.GetFriendlyName();
FullTypeName = type.FullName;
var interfaceType = Reflector.GetInterface(type);
if (interfaceType != null)
{
InterfaceType = interfaceType;
InterfaceTypeName = interfaceType.FullName;
}
IsArray = type.IsArray;
IsList = Reflector.IsList(type);
IsDictionary = Reflector.IsDictionary(type);
IsSimpleList = Reflector.IsSimpleList(type);
IsDataEntity = Reflector.IsDataEntity(type) || (!Reflector.IsSimpleType(type) && !IsArray && !IsList && !IsDictionary);
Type elementType;
IsDataEntityList = Reflector.IsDataEntityList(type, out elementType);
ElementType = elementType;
if (IsDataEntityList)
{
IsPolymorphicList = elementType != null && elementType.IsAbstract && (!elementType.IsInterface || !Reflector.IsDataEntity(elementType));
IsListInterface = type.GetGenericTypeDefinition() == typeof(IList<>);
}
IsSimpleType = Reflector.IsSimpleType(type);
IsNullableType = Reflector.IsNullableType(type);
IsMarkerInterface = Reflector.IsMarkerInterface(type);
HashCode = type.GetHashCode();
IsGenericType = type.IsGenericType;
IsInterface = type.IsInterface;
IsAnonymous = Reflector.IsAnonymousType(type);
IsEmitted = Reflector.IsEmitted(type);
}
示例12: ReflectedType
internal ReflectedType(Type type)
{
TypeName = type.Name;
FullTypeName = type.FullName;
var interfaceType = Reflector.ExtractInterface(type);
if (interfaceType != null)
{
InterfaceTypeName = interfaceType.FullName;
}
IsArray = type.IsArray;
IsSimpleList = Reflector.IsSimpleList(type);
IsDataEntity = Reflector.IsDataEntity(type);
Type elementType;
IsDataEntityList = Reflector.IsDataEntityList(type, out elementType);
ElementType = elementType;
if (IsDataEntityList)
{
IsListInterface = type.GetGenericTypeDefinition() == typeof(IList<>);
}
IsSimpleType = Reflector.IsSimpleType(type);
IsList = Reflector.IsList(type);
IsDictionary = Reflector.IsDictionary(type);
IsNullableType = Reflector.IsNullableType(type);
IsMarkerInterface = Reflector.IsMarkerInterface(type);
HashCode = type.GetHashCode();
IsGenericType = type.IsGenericType;
IsInterface = type.IsInterface;
IsAnonymous = Reflector.IsAnonymousType(type);
}
示例13: TableReaderSignature
public TableReaderSignature(Type tableType, IList<string> columns)
{
this.tableType = tableType;
this.columns = columns;
hash = tableType.GetHashCode();
foreach (var column in columns)
hash ^= column.GetHashCode();
}
示例14: GetSerializer
public static XmlSerializer GetSerializer(Type t)
{
int type_hash = t.GetHashCode();
if (!serializer_dict.ContainsKey(type_hash))
serializer_dict.Add(type_hash, new XmlSerializer(t));
return serializer_dict[type_hash];
}
示例15: GetSerializer
public static XmlSerializer GetSerializer(Type t)
{
var typeHash = t.GetHashCode();
if (!SerializerDict.ContainsKey(typeHash))
SerializerDict.Add(typeHash, new XmlSerializer(t));
return SerializerDict[typeHash];
}