private void GenerateCreateGetFieldIL(FieldInfo fieldInfo, ILGenerator generator)
 {
     if (!fieldInfo.IsStatic)
     {
         ILGeneratorExtensions.PushInstance(generator, fieldInfo.DeclaringType);
     }
     generator.Emit(OpCodes.Ldfld, fieldInfo);
     ILGeneratorExtensions.BoxIfNeeded(generator, fieldInfo.FieldType);
     ILGeneratorExtensions.Return(generator);
 }
 internal static void GenerateCreateSetFieldIL(FieldInfo fieldInfo, ILGenerator generator)
 {
     if (!fieldInfo.IsStatic)
     {
         ILGeneratorExtensions.PushInstance(generator, fieldInfo.DeclaringType);
     }
     generator.Emit(OpCodes.Ldarg_1);
     ILGeneratorExtensions.UnboxIfNeeded(generator, fieldInfo.FieldType);
     generator.Emit(OpCodes.Stfld, fieldInfo);
     ILGeneratorExtensions.Return(generator);
 }
        internal static void GenerateCreateSetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)
        {
            MethodInfo setMethod = propertyInfo.GetSetMethod(true);

            if (!setMethod.IsStatic)
            {
                ILGeneratorExtensions.PushInstance(generator, propertyInfo.DeclaringType);
            }
            generator.Emit(OpCodes.Ldarg_1);
            ILGeneratorExtensions.UnboxIfNeeded(generator, propertyInfo.PropertyType);
            ILGeneratorExtensions.CallMethod(generator, setMethod);
            ILGeneratorExtensions.Return(generator);
        }
        private void GenerateCreateGetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)
        {
            MethodInfo getMethod = propertyInfo.GetGetMethod(true);

            if (getMethod == null)
            {
                throw new ArgumentException(StringUtils.FormatWith("Property '{0}' does not have a getter.", (IFormatProvider)CultureInfo.InvariantCulture, (object)propertyInfo.Name));
            }
            if (!getMethod.IsStatic)
            {
                ILGeneratorExtensions.PushInstance(generator, propertyInfo.DeclaringType);
            }
            ILGeneratorExtensions.CallMethod(generator, getMethod);
            ILGeneratorExtensions.BoxIfNeeded(generator, propertyInfo.PropertyType);
            ILGeneratorExtensions.Return(generator);
        }
 private void GenerateCreateDefaultConstructorIL(Type type, ILGenerator generator)
 {
     if (TypeExtensions.IsValueType(type))
     {
         generator.DeclareLocal(type);
         generator.Emit(OpCodes.Ldloc_0);
         generator.Emit(OpCodes.Box, type);
     }
     else
     {
         ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, (Binder)null, ReflectionUtils.EmptyTypes, (ParameterModifier[])null);
         if (constructor == null)
         {
             throw new ArgumentException(StringUtils.FormatWith("Could not get constructor for {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)type));
         }
         generator.Emit(OpCodes.Newobj, constructor);
     }
     ILGeneratorExtensions.Return(generator);
 }
        private void GenerateCreateMethodCallIL(MethodBase method, ILGenerator generator)
        {
            ParameterInfo[] parameters = method.GetParameters();
            Label           label      = generator.DefineLabel();

            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Ldlen);
            generator.Emit(OpCodes.Ldc_I4, parameters.Length);
            generator.Emit(OpCodes.Beq, label);
            generator.Emit(OpCodes.Newobj, typeof(TargetParameterCountException).GetConstructor(ReflectionUtils.EmptyTypes));
            generator.Emit(OpCodes.Throw);
            generator.MarkLabel(label);
            if (!method.IsConstructor && !method.IsStatic)
            {
                ILGeneratorExtensions.PushInstance(generator, method.DeclaringType);
            }
            for (int index = 0; index < parameters.Length; ++index)
            {
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Ldc_I4, index);
                generator.Emit(OpCodes.Ldelem_Ref);
                ILGeneratorExtensions.UnboxIfNeeded(generator, parameters[index].ParameterType);
            }
            if (method.IsConstructor)
            {
                generator.Emit(OpCodes.Newobj, (ConstructorInfo)method);
            }
            else if (method.IsFinal || !method.IsVirtual)
            {
                ILGeneratorExtensions.CallMethod(generator, (MethodInfo)method);
            }
            Type type = method.IsConstructor ? method.DeclaringType : ((MethodInfo)method).ReturnType;

            if (type != typeof(void))
            {
                ILGeneratorExtensions.BoxIfNeeded(generator, type);
            }
            else
            {
                generator.Emit(OpCodes.Ldnull);
            }
            ILGeneratorExtensions.Return(generator);
        }