本文整理汇总了C#中System.Reflection.PropertyInfo.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.GetHashCode方法的具体用法?C# PropertyInfo.GetHashCode怎么用?C# PropertyInfo.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCachedSetPropertyHandlerDelegate
GetCachedSetPropertyHandlerDelegate(Type type, PropertyInfo propertyInfo)
{
int intCachedKey = propertyInfo.GetHashCode();//type.ToString() + "|P|" + propertyInfo.Name;
if (_propertySetDelegates.ContainsKey(intCachedKey))
return (SetHandler)_propertySetDelegates[intCachedKey];
SetHandler returnValue = CreateSetHandler(type, propertyInfo);
lock (_propertySetDelegates)
{
_propertySetDelegates[intCachedKey] = returnValue;
}
return returnValue;
}
示例2: ImplementStubProperty
/// <summary>
/// Implement a property with getter/setter that relies on a private backup field.
/// This is useful only to provide a temporary implementation of abstract properties that would be generated in a second time (this does not
/// provide more than auto implemented properties available in C# 3.0 and later.
/// </summary>
/// <param name="tB">The <see cref="TypeBuilder"/> for the new type.</param>
/// <param name="property">The property to implement.</param>
/// <param name="isVirtual">Defaults to false: the method is sealed. True to keep the method virtual. </param>
/// <returns>The <see cref="PropertyBuilder"/> to enable, for instance, creation of custom attributes on the property.</returns>
public static PropertyBuilder ImplementStubProperty( TypeBuilder tB, PropertyInfo property, bool isVirtual = false )
{
if( tB == null ) throw new ArgumentNullException( "tB" );
if( property == null ) throw new ArgumentNullException( "property" );
FieldBuilder backField = tB.DefineField( "_" + property.Name + property.GetHashCode(), property.PropertyType, FieldAttributes.Private );
MethodInfo getMethod = property.GetMethod;
MethodBuilder mGet = null;
if( getMethod != null )
{
MethodAttributes mA = getMethod.Attributes & ~(MethodAttributes.Abstract | MethodAttributes.VtableLayoutMask);
if( isVirtual ) mA |= MethodAttributes.Virtual;
mGet = tB.DefineMethod( getMethod.Name, mA, property.PropertyType, Type.EmptyTypes );
ILGenerator g = mGet.GetILGenerator();
g.LdArg( 0 );
g.Emit( OpCodes.Ldfld, backField );
g.Emit( OpCodes.Ret );
}
MethodInfo setMethod = property.SetMethod;
MethodBuilder mSet = null;
if( setMethod != null )
{
MethodAttributes mA = setMethod.Attributes & ~(MethodAttributes.Abstract | MethodAttributes.VtableLayoutMask);
if( isVirtual ) mA |= MethodAttributes.Virtual;
mSet = tB.DefineMethod( setMethod.Name, mA, typeof( void ), new[] { property.PropertyType } );
ILGenerator g = mSet.GetILGenerator();
g.LdArg( 0 );
g.LdArg( 1 );
g.Emit( OpCodes.Stfld, backField );
g.Emit( OpCodes.Ret );
}
PropertyBuilder p = tB.DefineProperty( property.Name, property.Attributes, property.PropertyType, Type.EmptyTypes );
if( mGet != null ) p.SetGetMethod( mGet );
if( mSet != null ) p.SetSetMethod( mSet );
return p;
}