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


C# PropertyBuilder.SetSetMethod方法代码示例

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


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

示例1: PropertyEmitter

		public PropertyEmitter(TypeBuilder owner, string name, Type propertyType, FieldBuilder propertyChangedField) {
			this.owner = owner;
			this.propertyChangedField = propertyChangedField;
			fieldBuilder = owner.DefineField(String.Format("<{0}>", name), propertyType, FieldAttributes.Private);
			getterBuilder = owner.DefineMethod(String.Format("get_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, propertyType, Type.EmptyTypes);
			ILGenerator getterIl = getterBuilder.GetILGenerator();
			getterIl.Emit(OpCodes.Ldarg_0);
			getterIl.Emit(OpCodes.Ldfld, fieldBuilder);
			getterIl.Emit(OpCodes.Ret);
			setterBuilder = owner.DefineMethod(String.Format("set_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, typeof(void), new[] {propertyType});
			ILGenerator setterIl = setterBuilder.GetILGenerator();
			setterIl.Emit(OpCodes.Ldarg_0);
			setterIl.Emit(OpCodes.Ldarg_1);
			setterIl.Emit(OpCodes.Stfld, fieldBuilder);
			if (propertyChangedField != null) {
				setterIl.Emit(OpCodes.Ldarg_0);
				setterIl.Emit(OpCodes.Dup);
				setterIl.Emit(OpCodes.Ldfld, propertyChangedField);
				setterIl.Emit(OpCodes.Ldstr, name);
				setterIl.Emit(OpCodes.Call, proxyBase_NotifyPropertyChanged);
			}
			setterIl.Emit(OpCodes.Ret);
			propertyBuilder = owner.DefineProperty(name, PropertyAttributes.None, propertyType, null);
			propertyBuilder.SetGetMethod(getterBuilder);
			propertyBuilder.SetSetMethod(setterBuilder);
		}
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:26,代码来源:PropertyEmitter.cs

示例2: BuildSetter

        private void BuildSetter(TypeBuilder typeBuilder, PropertyInfo contractProperty, PropertyBuilder builder)
        {
            var setMethod = contractProperty.GetSetMethod();

            if (null != setMethod)
            {
                var setMethodBuilder = new ProxyMethodImplementationStrategy().BuildMethodProxy(typeBuilder, setMethod);
                builder.SetSetMethod(setMethodBuilder);
            }
        }
开发者ID:fkalseth,项目名称:tinyaop,代码行数:10,代码来源:ProxyPropertyImplementationStrategy.cs

示例3: AddSetter

 private void AddSetter(System.Reflection.Emit.TypeBuilder typeBuilder, PropertyBuilder propertyBuilder)
 {
     MethodBuilder propertySetter = typeBuilder.DefineMethod("set_" + _propertyInfo.Name,
                          MethodAttributes.Public |
                         MethodAttributes.SpecialName |
                         MethodAttributes.HideBySig,
                         null, new Type[] { _propertyInfo.PropertyType });
     var propertySetterIl = propertySetter.GetILGenerator();
     propertySetterIl.Emit(OpCodes.Ldarg_0);
     propertySetterIl.Emit(OpCodes.Ldfld, _aggregate);
     propertySetterIl.Emit(OpCodes.Ldarg_1);
     MethodInfo setter = _propertyInfo.GetAccessors().First(accessor => accessor.ReturnType == typeof(void));
     propertySetterIl.Emit(OpCodes.Callvirt, setter);
     propertySetterIl.Emit(OpCodes.Ret);
     propertyBuilder.SetSetMethod(propertySetter);
 }
开发者ID:RichieYang,项目名称:NHateoas,代码行数:16,代码来源:AggregatedPropertyVisitor.cs

示例4: CreateSetMethod

        /// <summary>
        /// Creates the set method.
        /// </summary>
        /// <param name="typeBuilder">The type builder.</param>
        /// <param name="prop">The prop.</param>
        /// <param name="fieldBuilder">The field builder.</param>
        /// <param name="propBuilder">The prop builder.</param>
        private static void CreateSetMethod(TypeBuilder typeBuilder, PropertyInfo prop, FieldInfo fieldBuilder, PropertyBuilder propBuilder)
        {
            var setMethodBuilder = typeBuilder.DefineMethod(
                "set_" + prop.Name,
                GetSetAttributes,
                null,
                new[] { prop.PropertyType });

            var setIl = setMethodBuilder.GetILGenerator();
            setIl.Emit(OpCodes.Ldarg_0);
            setIl.Emit(OpCodes.Ldarg_1);
            setIl.Emit(OpCodes.Stfld, fieldBuilder);
            setIl.Emit(OpCodes.Ret);

            propBuilder.SetSetMethod(setMethodBuilder);
        }
开发者ID:petxo,项目名称:HermEsb,代码行数:23,代码来源:DynamicPropertyBuilder.cs

示例5: EmitCollectionProperty

        private void EmitCollectionProperty(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, PropertyInfo baseProperty, NavigationProperty navProperty)
        {
            const MethodAttributes methodAttributes = MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual;
            MethodInfo baseSetter = baseProperty.GetSetMethod(true); ;
            MethodAttributes methodAccess = baseSetter.Attributes & MethodAttributes.MemberAccessMask;
            
            string cannotSetException = System.Data.Entity.Strings.EntityProxyTypeInfo_CannotSetEntityCollectionProperty(propertyBuilder.Name, typeBuilder.Name);
            MethodBuilder setterBuilder = typeBuilder.DefineMethod("set_" + baseProperty.Name, methodAccess | methodAttributes, null, new Type[] { baseProperty.PropertyType });
            ILGenerator generator = setterBuilder.GetILGenerator();
            Label instanceEqual = generator.DefineLabel();
            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Call, _getRelationshipManager);
            generator.Emit(OpCodes.Ldstr, navProperty.RelationshipType.FullName);
            generator.Emit(OpCodes.Ldstr, navProperty.ToEndMember.Name);
            generator.Emit(OpCodes.Callvirt, s_GetRelatedEnd);
            generator.Emit(OpCodes.Beq_S, instanceEqual);
            generator.Emit(OpCodes.Ldstr, cannotSetException);
            generator.Emit(OpCodes.Newobj, s_InvalidOperationConstructor);
            generator.Emit(OpCodes.Throw);
            generator.MarkLabel(instanceEqual);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Call, baseProperty.GetSetMethod(true));
            generator.Emit(OpCodes.Ret);
            propertyBuilder.SetSetMethod(setterBuilder);

            _collectionProperties.Add(new KeyValuePair<NavigationProperty, PropertyInfo>(navProperty, baseProperty));
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:29,代码来源:EntityProxyFactory.cs

示例6: EmitReferenceProperty

        private void EmitReferenceProperty(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, PropertyInfo baseProperty, NavigationProperty navProperty)
        {
            const MethodAttributes methodAttributes = MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual;
            MethodInfo baseSetter = baseProperty.GetSetMethod(true); ;
            MethodAttributes methodAccess = baseSetter.Attributes & MethodAttributes.MemberAccessMask;

            MethodInfo specificGetRelatedReference = s_GetRelatedReference.MakeGenericMethod(baseProperty.PropertyType);
            MethodInfo specificEntityReferenceSetValue = typeof(EntityReference<>).MakeGenericType(baseProperty.PropertyType).GetMethod("set_Value"); ;

            MethodBuilder setterBuilder = typeBuilder.DefineMethod("set_" + baseProperty.Name, methodAccess | methodAttributes, null, new Type[] { baseProperty.PropertyType });
            ILGenerator generator = setterBuilder.GetILGenerator();
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Callvirt, _getRelationshipManager);
            generator.Emit(OpCodes.Ldstr, navProperty.RelationshipType.FullName);
            generator.Emit(OpCodes.Ldstr, navProperty.ToEndMember.Name);
            generator.Emit(OpCodes.Callvirt, specificGetRelatedReference);
            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Callvirt, specificEntityReferenceSetValue);
            generator.Emit(OpCodes.Ret);
            propertyBuilder.SetSetMethod(setterBuilder);

            _referenceProperties.Add(new KeyValuePair<NavigationProperty,PropertyInfo>(navProperty, baseProperty));
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:23,代码来源:EntityProxyFactory.cs

示例7: EmitScalarSetter


//.........这里部分代码省略.........
                    //     // perform set operation
                    // }
                    
                    Type propertyType = baseProperty.PropertyType;

                    if (propertyType == typeof(int) ||         // signed integer types
                        propertyType == typeof(short) ||
                        propertyType == typeof(Int64) ||
                        propertyType == typeof(bool) ||        // boolean
                        propertyType == typeof(byte) ||         
                        propertyType == typeof(UInt32) ||
                        propertyType == typeof(UInt64)||
                        propertyType == typeof(float) ||
                        propertyType == typeof(double) ||
                        propertyType.IsEnum)
                    {
                        generator.Emit(OpCodes.Ldarg_0);
                        generator.Emit(OpCodes.Call, baseGetter);
                        generator.Emit(OpCodes.Ldarg_1);
                        generator.Emit(OpCodes.Beq_S, endOfMethod);
                    }
                    else if (propertyType == typeof(byte[]))
                    {
                        // Byte arrays must be compared by value
                        generator.Emit(OpCodes.Ldsfld, _compareByteArraysField);
                        generator.Emit(OpCodes.Ldarg_0);
                        generator.Emit(OpCodes.Call, baseGetter);
                        generator.Emit(OpCodes.Ldarg_1);
                        generator.Emit(OpCodes.Callvirt, s_Func_object_object_bool_Invoke);
                        generator.Emit(OpCodes.Brtrue_S, endOfMethod);
                    }
                    else
                    {
                        // Get the specific type's inequality method if it exists
                        MethodInfo op_inequality = propertyType.GetMethod("op_Inequality", new Type[] { propertyType, propertyType });
                        if (op_inequality != null)
                        {
                            generator.Emit(OpCodes.Ldarg_0);
                            generator.Emit(OpCodes.Call, baseGetter);
                            generator.Emit(OpCodes.Ldarg_1);
                            generator.Emit(OpCodes.Call, op_inequality);
                            generator.Emit(OpCodes.Brfalse_S, endOfMethod);
                        }
                        else
                        {
                            // Use object inequality
                            generator.Emit(OpCodes.Ldarg_0);
                            generator.Emit(OpCodes.Call, baseGetter);
                            if (propertyType.IsValueType)
                            {
                                generator.Emit(OpCodes.Box, propertyType);
                            }
                            generator.Emit(OpCodes.Ldarg_1);
                            if (propertyType.IsValueType)
                            {
                                generator.Emit(OpCodes.Box, propertyType);
                            }
                            generator.Emit(OpCodes.Call, s_ObjectEquals);
                            generator.Emit(OpCodes.Brtrue_S, endOfMethod);
                        }
                    }
                }
            }

            // Creates code like this:
            //
            // try
            // {
            //     MemberChanging(propertyName);
            //     base.Property_set(value);
            //     MemberChanged(propertyName);
            // }
            // finally
            // {
            //     _resetFKSetterFlagField(this);
            // }
            //
            // Note that the try/finally ensures that even if an exception causes
            // the setting of the property to be aborted, we still clear the flag that
            // indicates that we are in a property setter.

            generator.BeginExceptionBlock();
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldstr, baseProperty.Name);
            generator.Emit(OpCodes.Call, _entityMemberChanging);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Call, baseSetter);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldstr, baseProperty.Name);
            generator.Emit(OpCodes.Call, _entityMemberChanged);
            generator.BeginFinallyBlock();
            generator.Emit(OpCodes.Ldsfld, _resetFKSetterFlagField);
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Callvirt, s_Action_Invoke);
            generator.EndExceptionBlock();
            generator.MarkLabel(endOfMethod);
            generator.Emit(OpCodes.Ret);
            propertyBuilder.SetSetMethod(setterBuilder);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:EntityProxyFactory.cs

示例8: SetAccessors

 private static void SetAccessors(PropertyBuilder property, IEnumerable<RppMethodInfo> methods)
 {
     string propertyName = property.Name;
     foreach (RppMethodInfo method in methods)
     {
         if (method.Name == RppMethodInfo.GetGetterAccessorName(propertyName))
         {
             property.SetGetMethod((MethodBuilder) method.Native);
         }
         else if (method.Name == RppMethodInfo.GetSetterAccessorName(propertyName))
         {
             property.SetSetMethod((MethodBuilder) method.Native);
         }
     }
 }
开发者ID:dubik,项目名称:csharprpp,代码行数:15,代码来源:RType.cs

示例9: AddSetter

 private void AddSetter(System.Reflection.Emit.TypeBuilder typeBuilder, FieldBuilder fieldBuilder, PropertyBuilder propertyBuilder)
 {
     MethodBuilder propertySetter = typeBuilder.DefineMethod("set_" + _propertyName,
                          MethodAttributes.Public |
                         MethodAttributes.SpecialName |
                         MethodAttributes.HideBySig,
                         null, new Type[] { _propertyType });
     var propertySetterIl = propertySetter.GetILGenerator();
     propertySetterIl.Emit(OpCodes.Ldarg_0);
     propertySetterIl.Emit(OpCodes.Ldarg_1);
     propertySetterIl.Emit(OpCodes.Stfld, fieldBuilder);
     propertySetterIl.Emit(OpCodes.Ret);
     propertyBuilder.SetSetMethod(propertySetter);
 }
开发者ID:RichieYang,项目名称:NHateoas,代码行数:14,代码来源:PropertyVisitor.cs

示例10: DefineBuilders

		protected void DefineBuilders (MemberKind kind, ParametersCompiled parameters)
		{
			PropertyBuilder = Parent.TypeBuilder.DefineProperty (
				GetFullName (MemberName), PropertyAttributes.None,
#if !BOOTSTRAP_BASIC	// Requires trunk version mscorlib
				IsStatic ? 0 : CallingConventions.HasThis,
#endif
				MemberType.GetMetaInfo (), null, null,
				parameters.GetMetaInfo (), null, null);

			PropertySpec spec;
			if (kind == MemberKind.Indexer)
				spec = new IndexerSpec (Parent.Definition, this, MemberType, parameters, PropertyBuilder, ModFlags);
			else
				spec = new PropertySpec (kind, Parent.Definition, this, MemberType, PropertyBuilder, ModFlags);

			if (Get != null) {
				spec.Get = Get.Spec;

				var method = Get.Spec.GetMetaInfo () as MethodBuilder;
				if (method != null) {
					PropertyBuilder.SetGetMethod (method);
					Parent.MemberCache.AddMember (this, method.Name, Get.Spec);
				}
			} else {
				CheckMissingAccessor (kind, parameters, true);
			}

			if (Set != null) {
				spec.Set = Set.Spec;

				var method = Set.Spec.GetMetaInfo () as MethodBuilder;
				if (method != null) {
					PropertyBuilder.SetSetMethod (method);
					Parent.MemberCache.AddMember (this, method.Name, Set.Spec);
				}
			} else {
				CheckMissingAccessor (kind, parameters, false);
			}

			Parent.MemberCache.AddMember (this, PropertyBuilder.Name, spec);
		}
开发者ID:afaerber,项目名称:mono,代码行数:42,代码来源:property.cs

示例11: EmitProperty


//.........这里部分代码省略.........
            MethodInfo setMethod,
            string invokeSet,
            Type[] setParamTypes,
            TypeBuilder typeBuilder,
            MethodBuilder getMethodBuilder,
            Type callSite,
            Type contextType,
            Type tConvertFuncType,
            Type invokeGetFuncType,
            PropertyBuilder tMp,
            Type invokeSetFuncType, bool defaultImp)
        {
            if (indexParamTypes == null) {
                throw new ArgumentNullException("indexParamTypes");
            }
            var tIlGen = getMethodBuilder.GetILGenerator();

            var tConvertCallsiteField = callSite.GetFieldEvenIfGeneric(convertGet);
            var tReturnLocal = tIlGen.DeclareLocal(tGetReturnType);

            using (tIlGen.EmitBranchTrue(gen => gen.Emit(OpCodes.Ldsfld, tConvertCallsiteField))) {
                tIlGen.EmitDynamicConvertBinder(CSharpBinderFlags.None, tGetReturnType, contextType);
                tIlGen.EmitCallsiteCreate(tConvertFuncType);
                tIlGen.Emit(OpCodes.Stsfld, tConvertCallsiteField);
            }

            var tInvokeGetCallsiteField = callSite.GetFieldEvenIfGeneric(invokeGet);

            using (tIlGen.EmitBranchTrue(gen => gen.Emit(OpCodes.Ldsfld, tInvokeGetCallsiteField))) {
                tIlGen.EmitDynamicGetBinder(CSharpBinderFlags.None, name, contextType, indexParamTypes);
                tIlGen.EmitCallsiteCreate(invokeGetFuncType);
                tIlGen.Emit(OpCodes.Stsfld, tInvokeGetCallsiteField);
            }

            tIlGen.Emit(OpCodes.Ldsfld, tConvertCallsiteField);
            tIlGen.Emit(OpCodes.Ldfld, tConvertCallsiteField.FieldType.GetFieldEvenIfGeneric("Target"));
            tIlGen.Emit(OpCodes.Ldsfld, tConvertCallsiteField);
            tIlGen.Emit(OpCodes.Ldsfld, tInvokeGetCallsiteField);
            tIlGen.Emit(OpCodes.Ldfld, tInvokeGetCallsiteField.FieldType.GetFieldEvenIfGeneric("Target"));
            tIlGen.Emit(OpCodes.Ldsfld, tInvokeGetCallsiteField);
            tIlGen.Emit(OpCodes.Ldarg_0);
            tIlGen.Emit(OpCodes.Call, typeof (ActLikeProxy).GetProperty("Original").GetGetMethod());
            for (var i = 1; i <= indexParamTypes.Length; i++) {
                tIlGen.EmitLoadArgument(i);
            }
            tIlGen.EmitCallInvokeFunc(invokeGetFuncType);
            tIlGen.EmitCallInvokeFunc(tConvertFuncType);
            tIlGen.EmitStoreLocation(tReturnLocal.LocalIndex);
            var tReturnLabel = tIlGen.DefineLabel();
            tIlGen.Emit(OpCodes.Br_S, tReturnLabel);
            tIlGen.MarkLabel(tReturnLabel);
            tIlGen.EmitLoadLocation(tReturnLocal.LocalIndex);
            tIlGen.Emit(OpCodes.Ret);
            tMp.SetGetMethod(getMethodBuilder);

            if (setMethod != null) {
                MethodAttributes tPublicPrivate = MethodAttributes.Public;
                var tPrefixedSet = setMethod.Name;
                if (!defaultImp) {
                    tPublicPrivate = MethodAttributes.Private;
                    tPrefixedSet = String.Format("{0}.{1}", info.DeclaringType.FullName, tPrefixedSet);
                }

                var tSetMethodBuilder = typeBuilder.DefineMethod(tPrefixedSet,
                    tPublicPrivate | MethodAttributes.SpecialName |
                        MethodAttributes.HideBySig | MethodAttributes.Virtual |
                            MethodAttributes.Final | MethodAttributes.NewSlot,
                    null,
                    setParamTypes);

                if (!defaultImp) {
                    typeBuilder.DefineMethodOverride(tSetMethodBuilder, info.GetSetMethod());
                }

                foreach (var tParam in info.GetSetMethod().GetParameters()) {
                    tSetMethodBuilder.DefineParameter(tParam.Position + 1, AttributesForParam(tParam), tParam.Name);
                }

                tIlGen = tSetMethodBuilder.GetILGenerator();
                var tSetCallsiteField = callSite.GetFieldEvenIfGeneric(invokeSet);

                using (tIlGen.EmitBranchTrue(gen => gen.Emit(OpCodes.Ldsfld, tSetCallsiteField))) {
                    tIlGen.EmitDynamicSetBinder(CSharpBinderFlags.None, name, contextType, setParamTypes);
                    tIlGen.EmitCallsiteCreate(invokeSetFuncType);
                    tIlGen.Emit(OpCodes.Stsfld, tSetCallsiteField);
                }
                tIlGen.Emit(OpCodes.Ldsfld, tSetCallsiteField);
                tIlGen.Emit(OpCodes.Ldfld, tSetCallsiteField.FieldType.GetFieldEvenIfGeneric("Target"));
                tIlGen.Emit(OpCodes.Ldsfld, tSetCallsiteField);
                tIlGen.Emit(OpCodes.Ldarg_0);
                tIlGen.Emit(OpCodes.Call, typeof (ActLikeProxy).GetProperty("Original").GetGetMethod());
                for (var i = 1; i <= setParamTypes.Length; i++) {
                    tIlGen.EmitLoadArgument(i);
                }
                tIlGen.EmitCallInvokeFunc(invokeSetFuncType);
                tIlGen.Emit(OpCodes.Pop);
                tIlGen.Emit(OpCodes.Ret);
                tMp.SetSetMethod(tSetMethodBuilder);
            }
        }
开发者ID:virmitio,项目名称:coapp,代码行数:101,代码来源:BuildProxy.cs

示例12: DefinePropertySetter

        private void DefinePropertySetter(Entity c, Entity p, TypeBuilder t, bool forward, string propname, Type rettype, Type retelemtype, bool functional, PropertyBuilder property)
        {
            if (!functional) return;

            MethodBuilder method = t.DefineMethod("set_" + propname,
                MethodAttributes.Public | MethodAttributes.SpecialName,
                CallingConventions.HasThis,
                null, new Type[] { rettype } );
            property.SetSetMethod(method);

            ILGenerator il = method.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);

            il.Emit(OpCodes.Ldstr, p.Uri);
            il.Emit(OpCodes.Newobj, newentity);

            il.Emit(OpCodes.Ldarg_1);

            if (forward)
                il.Emit(OpCodes.Ldc_I4_1);
            else
                il.Emit(OpCodes.Ldc_I4_0);

            il.Emit(OpCodes.Call, anysetfuncvalue);
            il.Emit(OpCodes.Ret);
        }
开发者ID:JoshData,项目名称:semweb-dotnet,代码行数:27,代码来源:rdfbind.cs

示例13: CreatePropertySetMethod

        /// <summary>
        /// Creates the body of a property setter
        /// </summary>
        /// <param name="generatedTypeBuilder"></param>
        /// <param name="p"></param>
        /// <param name="property"></param>
        /// <param name="setDecl"></param>
        /// <param name="logicField"></param>
        private void CreatePropertySetMethod(TypeBuilderHelper generatedTypeBuilder, PropertyInfo p,
                                             PropertyBuilder property, MethodInfo setDecl, FieldInfo logicField)
        {
            //set getter name and parameter types
            var name = setDecl == null ? "set_" + p.Name : setDecl.Name;
            var parameterTypes = setDecl == null ? new[] { p.PropertyType }
                                                 : setDecl.GetParameters().Select(x => x.ParameterType).ToArray();

            //set attributes on setter
            var methodAttributes = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Virtual;

            //build setter method
            var setBuilder = generatedTypeBuilder.DefineMethod(name, methodAttributes, null, parameterTypes);

            //spit out IL
            setBuilder
                .Emitter
                .ldarg_0
                .ldfld(logicField)
                .ldstr(p.Name)
                .ldarg_1
                .callvirt(Reflect<LogicBase>.GetMethod(x=> x.SetProperty(string.Empty, string.Empty)).MakeGenericMethod(p.PropertyType))
                .nop
                .ret();

            //apply setter method to the property
            property.SetSetMethod(setBuilder);
        }
开发者ID:pietervp,项目名称:MData,代码行数:36,代码来源:TypeCreator.cs

示例14: DefineBuilders

        protected void DefineBuilders(MemberKind kind, ParametersCompiled parameters)
        {
            // FIXME - PropertyAttributes.HasDefault ?

            PropertyBuilder = Parent.TypeBuilder.DefineProperty (
                GetFullName (MemberName), PropertyAttributes.None, MemberType.GetMetaInfo (), parameters.GetMetaInfo ());

            PropertySpec spec;
            if (kind == MemberKind.Indexer)
                spec = new IndexerSpec (Parent.Definition, this, MemberType, parameters, PropertyBuilder, ModFlags);
            else
                spec = new PropertySpec (kind, Parent.Definition, this, MemberType, PropertyBuilder, ModFlags);

            spec.Get = Get.Spec;
            spec.Set = Set.Spec;

            if (!Get.IsDummy) {
                PropertyBuilder.SetGetMethod (GetBuilder);
            }

            if (!Set.IsDummy) {
                PropertyBuilder.SetSetMethod (SetBuilder);
            }

            Parent.MemberCache.AddMember (this, Get.IsDummy ? Get.Name : GetBuilder.Name, Get.Spec);
            Parent.MemberCache.AddMember (this, Set.IsDummy ? Set.Name : SetBuilder.Name, Set.Spec);
            Parent.MemberCache.AddMember (this, PropertyBuilder.Name, spec);
        }
开发者ID:speier,项目名称:shake,代码行数:28,代码来源:property.cs

示例15: CreateSetMethod

        public MethodBuilder CreateSetMethod(TypeBuilder Class, PropertyBuilder Property, FieldBuilder Field, Boolean Public, System.Type ReturnType)
        {
            String methodName = "set_" + Property.Name;

            MethodBuilder setMethod = Class.DefineMethod(methodName,
                               BasePropertyMethodAttr,
                               null,
                               new Type[] { ReturnType });

            ILGenerator setIL = setMethod.GetILGenerator();

            setIL.Emit(OpCodes.Ldarg_0);
            setIL.Emit(OpCodes.Ldarg_1);
            setIL.Emit(OpCodes.Stfld, Field);
            setIL.Emit(OpCodes.Ret);

            Property.SetSetMethod(setMethod);

            return setMethod;
        }
开发者ID:MetalMynds,项目名称:FlatGlass,代码行数:20,代码来源:Strings.cs


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