New test.
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / ExpressionUtil / ParameterExpressionFingerprint.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc.ExpressionUtil {\r
14     using System;\r
15     using System.Linq.Expressions;\r
16 \r
17     // ParameterExpression fingerprint class\r
18     // Specifically, instances of this type represent the model parameter\r
19     internal sealed class ParameterExpressionFingerprint : ExpressionFingerprint {\r
20 \r
21         private ParameterExpressionFingerprint(ParameterExpression expression)\r
22             : base(expression) {\r
23         }\r
24 \r
25         public static ParameterExpressionFingerprint Create(ParameterExpression expression, ParserContext parserContext) {\r
26             if (expression == parserContext.ModelParameter) {\r
27                 return new ParameterExpressionFingerprint(expression);\r
28             }\r
29             else {\r
30                 // degenerate case - uncaptured parameter expression passed into the system\r
31                 return null;\r
32             }\r
33         }\r
34 \r
35         public override Expression ToExpression(ParserContext parserContext) {\r
36             // The only time an instance of this class exists is if it represents the actual model parameter,\r
37             // so just return it directly.\r
38             return parserContext.ModelParameter;\r
39         }\r
40 \r
41     }\r
42 }\r