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     // IndexExpression fingerprint class
12     // Represents certain forms of array access or indexer property access
13 
14     [SuppressMessage("Microsoft.Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals", Justification = "Overrides AddToHashCodeCombiner() instead.")]
15     internal sealed class IndexExpressionFingerprint : ExpressionFingerprint
16     {
IndexExpressionFingerprint(ExpressionType nodeType, Type type, PropertyInfo indexer)17         public IndexExpressionFingerprint(ExpressionType nodeType, Type type, PropertyInfo indexer)
18             : base(nodeType, type)
19         {
20             // Other properties on IndexExpression (like the argument count) are simply derived
21             // from Type and Indexer, so they're not necessary for inclusion in the fingerprint.
22 
23             Indexer = indexer;
24         }
25 
26         // http://msdn.microsoft.com/en-us/library/system.linq.expressions.indexexpression.indexer.aspx
27         public PropertyInfo Indexer { get; private set; }
28 
Equals(object obj)29         public override bool Equals(object obj)
30         {
31             IndexExpressionFingerprint other = obj as IndexExpressionFingerprint;
32             return (other != null)
33                    && Equals(this.Indexer, other.Indexer)
34                    && this.Equals(other);
35         }
36 
AddToHashCodeCombiner(HashCodeCombiner combiner)37         internal override void AddToHashCodeCombiner(HashCodeCombiner combiner)
38         {
39             combiner.AddObject(Indexer);
40             base.AddToHashCodeCombiner(combiner);
41         }
42     }
43 }
44