1 // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
2 
3 using System.Diagnostics.CodeAnalysis;
4 using System.Linq.Expressions;
5 using System.Reflection;
6 
7 #pragma warning disable 659 // overrides AddToHashCodeCombiner instead
8 
9 namespace System.Web.Mvc.ExpressionUtil
10 {
11     // MethodCallExpression fingerprint class
12     // Expression of form xxx.Foo(...), xxx[...] (get_Item()), etc.
13 
14     [SuppressMessage("Microsoft.Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals", Justification = "Overrides AddToHashCodeCombiner() instead.")]
15     internal sealed class MethodCallExpressionFingerprint : ExpressionFingerprint
16     {
MethodCallExpressionFingerprint(ExpressionType nodeType, Type type, MethodInfo method)17         public MethodCallExpressionFingerprint(ExpressionType nodeType, Type type, MethodInfo method)
18             : base(nodeType, type)
19         {
20             // Other properties on MethodCallExpression (like the argument count) are simply derived
21             // from Type and Indexer, so they're not necessary for inclusion in the fingerprint.
22 
23             Method = method;
24         }
25 
26         // http://msdn.microsoft.com/en-us/library/system.linq.expressions.methodcallexpression.method.aspx
27         public MethodInfo Method { get; private set; }
28 
Equals(object obj)29         public override bool Equals(object obj)
30         {
31             MethodCallExpressionFingerprint other = obj as MethodCallExpressionFingerprint;
32             return (other != null)
33                    && Equals(this.Method, other.Method)
34                    && this.Equals(other);
35         }
36 
AddToHashCodeCombiner(HashCodeCombiner combiner)37         internal override void AddToHashCodeCombiner(HashCodeCombiner combiner)
38         {
39             combiner.AddObject(Method);
40             base.AddToHashCodeCombiner(combiner);
41         }
42     }
43 }
44