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


C# PropertyInfo.GetHashCode方法代码示例

本文整理汇总了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;
        }
开发者ID:priceLiu,项目名称:Enterprise.Company,代码行数:13,代码来源:DynamicMethodCompiler.cs

示例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;
        }
开发者ID:Invenietis,项目名称:ck-core,代码行数:47,代码来源:EmitHelper.cs


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