Exemplo n.º 1
0
 public override void Emit(IEasyMember member, ILGenerator gen)
 {
     if (this._reference != null)
     {
         ArgumentsUtil.EmitLoadOwnerAndReference(this._reference, gen);
     }
     else if (this._expression != null)
     {
         this._expression.Emit(member, gen);
     }
     else if (member.ReturnType != typeof(void))
     {
         OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, member.ReturnType);
     }
     gen.Emit(OpCodes.Ret);
 }
Exemplo n.º 2
0
		private void EmitByRef(ILGenerator gen)
		{
			var elementType = type.GetElementType();
			if (IsPrimitiveOrClass(elementType))
			{
				OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, elementType);
				OpCodeUtil.EmitStoreIndirectOpCodeForType(gen, elementType);
			}
			else if (elementType.GetTypeInfo().IsGenericParameter || elementType.GetTypeInfo().IsValueType)
			{
				gen.Emit(OpCodes.Initobj, elementType);
			}
			else
			{
				throw new ProxyGenerationException("Can't emit default value for reference of type " + elementType);
			}
		}
Exemplo n.º 3
0
        public void Emit(IMemberEmitter member, ILGenerator gen)
        {
            if (reference != null)
            {
                ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);
            }
            else if (expression != null)
            {
                expression.Emit(member, gen);
            }
            else
            {
                if (member.ReturnType != typeof(void))
                {
                    OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, member.ReturnType);
                }
            }

            gen.Emit(OpCodes.Ret);
        }
Exemplo n.º 4
0
 public override void Emit(IMemberEmitter member, ILGenerator gen)
 {
     // TODO: check if this can be simplified by using more of OpCodeUtil and other existing types
     if (IsPrimitiveOrClass(type))
     {
         OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(gen, type);
     }
     else if (type.IsValueType || type.IsGenericParameter)
     {
         // TODO: handle decimal explicitly
         var local = gen.DeclareLocal(type);
         gen.Emit(OpCodes.Ldloca_S, local);
         gen.Emit(OpCodes.Initobj, type);
         gen.Emit(OpCodes.Ldloc, local);
     }
     else if (type.IsByRef)
     {
         EmitByRef(gen);
     }
     else
     {
         throw new ProxyGenerationException("Can't emit default value for type " + type);
     }
 }