Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TypeAs handling.

  • Loading branch information...
commit b5fa54cdbdb5e4eacf3cffd0dbb7eb0a92eb899d 1 parent b310e53
@drunkcod authored
View
8 Source/Core/ExpressionFormatter.cs
@@ -42,6 +42,7 @@ public class ExpressionFormatter : IFormatter<Expression>
case ExpressionType.Conditional: return FormatConditional(expression);
case ExpressionType.Convert: return FormatConvert(expression);
case ExpressionType.TypeIs: return FormatTypeIs(expression);
+ case ExpressionType.TypeAs: return FormatTypeAs(expression);
case ExpressionType.Invoke: return FormatInvoke(expression);
default:
@@ -120,7 +121,12 @@ public class ExpressionFormatter : IFormatter<Expression>
return string.Format("{0} is {1}", Format(typeIs.Expression), FormatType(typeIs.TypeOperand));
}
- string FormatLambda(Expression expression) { return FormatLambda((LambdaExpression)expression); }
+ string FormatTypeAs(Expression expression) { return FormatTypeAs((UnaryExpression)expression); }
+ string FormatTypeAs(UnaryExpression typeAs) {
+ return string.Format("({0} as {1})", Format(typeAs.Operand), FormatType(typeAs.Type));
+ }
+
+ string FormatLambda(Expression expression) { return FormatLambda((LambdaExpression)expression); }
string FormatLambda(LambdaExpression lambda) {
var parameters = lambda.Parameters;
return string.Format("{0} => {1}",
View
5 Specs/Cone.Specs/ExpressionFormatterSpec.cs
@@ -195,6 +195,11 @@ public void type_test()
VerifyFormat(() => getAnswer(), "getAnswer()");
}
+ public void as_expression() {
+ var items = new List<object[]>{ new[] { "Hello" } };
+ VerifyFormat(() => (items[0][0] as string), "(items[0][0] as string)");
+ }
+
[Context("nested expressions")]
public class NestedExpressions
{
Please sign in to comment.
Something went wrong with that request. Please try again.