1 #pragma warning disable 659 // overrides AddToHashCodeCombiner instead
\r
3 /* ****************************************************************************
\r
5 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
7 * This software is subject to the Microsoft Public License (Ms-PL).
\r
8 * A copy of the license can be found in the license.htm file included
\r
9 * in this distribution.
\r
11 * You must not remove this notice, or any other, from this software.
\r
13 * ***************************************************************************/
\r
15 namespace System.Web.Mvc.ExpressionUtil {
\r
17 using System.Diagnostics.CodeAnalysis;
\r
18 using System.Linq.Expressions;
\r
19 using System.Reflection;
\r
21 // UnaryExpression fingerprint class
\r
22 // The most common appearance of a UnaryExpression is a cast or other conversion operator
\r
23 [SuppressMessage("Microsoft.Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals",
\r
24 Justification = "Overrides AddToHashCodeCombiner() instead.")]
\r
25 internal sealed class UnaryExpressionFingerprint : ExpressionFingerprint {
\r
27 private UnaryExpressionFingerprint(UnaryExpression expression)
\r
28 : base(expression) {
\r
29 // don't care about UnaryExpression.IsLifted / IsLiftedToNull since they're not necessary to uniquely describe the expression
\r
31 Method = expression.Method;
\r
34 public MethodInfo Method {
\r
39 public ExpressionFingerprint Operand {
\r
44 internal override void AddToHashCodeCombiner(HashCodeCombiner combiner) {
\r
45 base.AddToHashCodeCombiner(combiner);
\r
47 combiner.AddObject(Method);
\r
48 combiner.AddFingerprint(Operand);
\r
51 public static UnaryExpressionFingerprint Create(UnaryExpression expression, ParserContext parserContext) {
\r
52 ExpressionFingerprint operand = Create(expression.Operand, parserContext);
\r
53 if (operand == null && expression.Operand != null) {
\r
54 // couldn't convert the operand, so bail
\r
58 return new UnaryExpressionFingerprint(expression) {
\r
63 public override bool Equals(object obj) {
\r
64 UnaryExpressionFingerprint other = obj as UnaryExpressionFingerprint;
\r
65 if (other == null) {
\r
69 return (this.Method == other.Method
\r
70 && Object.Equals(this.Operand, other.Operand)
\r
71 && base.Equals(other));
\r
74 public override Expression ToExpression(ParserContext parserContext) {
\r
75 Expression operandExpr = ToExpression(Operand, parserContext);
\r
77 // in .NET 3.5 SP1, Expression.MakeUnary() throws if NodeType is UnaryPlus, so special-case
\r
78 if (NodeType == ExpressionType.UnaryPlus) {
\r
79 return Expression.UnaryPlus(operandExpr, Method);
\r
82 return Expression.MakeUnary(NodeType, operandExpr, Type, Method);
\r