コード例 #1
0
 public static Expression CastTo(this Expression expresion, DebugType castTo)
 {
     // No need to cast
     if (expresion.GetStaticType() == castTo)
     {
         return(expresion);
     }
     if (expresion is PrimitiveExpression)
     {
         object val = ((PrimitiveExpression)expresion).Value;
         if (val != null && val.GetType().FullName == castTo.FullName)
         {
             return(expresion);
         }
     }
     return(new CastExpression()
     {
         Expression = expresion.Clone().Parenthesize(), Type = castTo.GetTypeReference()
     });
 }
コード例 #2
0
        public static IndexerExpression AppendIndexer(this Expression expression, params int[] indices)
        {
            var args = new List <Expression>();

            foreach (int index in indices)
            {
                args.Add(new PrimitiveExpression(index));
            }
            IndexerExpression indexerExpr = expression.Clone().Indexer(args);

            DebugType staticType = expression.GetStaticType();

            if (staticType != null && staticType.IsArray)
            {
                indexerExpr.SetStaticType((DebugType)staticType.GetElementType());
            }
            if (staticType != null && staticType.FullNameWithoutGenericArguments == typeof(List <>).FullName)
            {
                indexerExpr.SetStaticType((DebugType)staticType.GetGenericArguments()[0]);
            }
            return(indexerExpr);
        }