예제 #1
0
 private static Expression /*!*/ ConvertResult(Expression /*!*/ expression, Type /*!*/ resultType)
 {
     if (resultType.IsGenericType() && resultType.GetGenericTypeDefinition() == typeof(Union <,>))
     {
         var args = resultType.GetGenericArguments();
         var ctor = resultType.GetConstructor(args);
         if (args[0].IsAssignableFrom(expression.Type))
         {
             return(Ast.New(ctor, expression, AstUtils.Default(args[1])));
         }
         else
         {
             Debug.Assert(args[1].IsAssignableFrom(expression.Type));
             return(Ast.New(ctor, AstUtils.Default(args[0]), expression));
         }
     }
     else
     {
         return(AstUtils.Convert(expression, resultType));
     }
 }