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(castTo.GetTypeReference(), expresion.Parenthesize(), CastType.Cast)); }
public static IndexerExpression AppendIndexer(this Expression expression, params int[] indices) { IndexerExpression indexerExpr = new IndexerExpression(Parenthesize(expression), new List <Expression>()); foreach (int index in indices) { indexerExpr.Indexes.Add(new PrimitiveExpression(index)); } 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); }