private void ImplementProperty(TypeBuilder typeBuilder, PropertyInfo propertyInfo) { var propBuilder = typeBuilder.DefineProperty(propertyInfo.Name, PropertyAttributes.None, propertyInfo.PropertyType, new Type[0]); const MethodAttributes attributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final; var getMethodBuilder = typeBuilder.DefineMethod("get_" + propertyInfo.Name, attributes, CallingConventions.HasThis, propertyInfo.PropertyType, null); var ilGen = getMethodBuilder.GetILGenerator(); ilGen.DeclareLocal(propertyInfo.PropertyType); //ilGen.Emit(OpCodes.Nop); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, _fieldScopeBuilder); var genMethod = ResolveMethodInfo.MakeGenericMethod(propertyInfo.PropertyType); ilGen.EmitCall(OpCodes.Callvirt, genMethod, null); ilGen.Emit(OpCodes.Stloc_0); ilGen.Emit(OpCodes.Ldloc_0); ilGen.Emit(OpCodes.Ret); propBuilder.SetGetMethod(getMethodBuilder); }
private void ImplementProperty(TypeBuilder typeBuilder, PropertyInfo propertyInfo) { var propBuilder = typeBuilder.DefineProperty(propertyInfo.Name, PropertyAttributes.None, propertyInfo.PropertyType, new Type[0]); var getMethodBuilder = typeBuilder.DefineMethod(GetPropertyGetterName(propertyInfo), DefaultPropertyGetterAttributes, CallingConventions.HasThis, propertyInfo.PropertyType, null); var ilGen = getMethodBuilder.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Callvirt, _scopeProperty.GetMethod); ilGen.Emit(OpCodes.Callvirt, ResolveMethodInfo.MakeGenericMethod(propertyInfo.PropertyType)); ilGen.Emit(OpCodes.Ret); propBuilder.SetGetMethod(getMethodBuilder); }