示例#1
0
 public void EmitLoadDefaultValue(Type type)
 {
     if (type == typeof(void))
     {
         return;
     }
     if (!type.IsValueType)
     {
         Il.Ldnull();
     }
     else
     {
         using (var temp = DeclareLocal(type))
         {
             Il.Ldloca(temp);
             Il.Initobj(type);
             Il.Ldloc(temp);
         }
     }
 }
示例#2
0
 public bool EmitNullChecking(Type type, GroboIL.Label objIsNullLabel)
 {
     if (!type.IsValueType)
     {
         Il.Dup();                   // stack: [obj, obj]
         Il.Brfalse(objIsNullLabel); // if(obj == null) goto returnDefaultValue; stack: [obj]
         return(true);
     }
     if (type.IsNullable())
     {
         using (var temp = DeclareLocal(type.MakeByRefType()))
         {
             Il.Stloc(temp);
             Il.Ldnull();
             Il.Ldloc(temp);
             EmitHasValueAccess(type);
             Il.Brfalse(objIsNullLabel);
             Il.Pop();
             Il.Ldloc(temp);
         }
         return(true);
     }
     return(false);
 }