Facilitate the merge
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Ast / DefaultExpression.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Microsoft Public License. A 
6  * copy of the license can be found in the License.html file at the root of this distribution. If 
7  * you cannot locate the  Microsoft Public License, please send an email to 
8  * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
9  * by the terms of the Microsoft Public License.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 using System;
17 using System.Diagnostics;
18
19 #if CLR2
20 namespace Microsoft.Scripting.Ast {
21 #else
22 namespace System.Linq.Expressions {
23 #endif
24     /// <summary>
25     /// Represents the default value of a type or an empty expression.
26     /// </summary>
27 #if !SILVERLIGHT
28     [DebuggerTypeProxy(typeof(Expression.DefaultExpressionProxy))]
29 #endif
30     public sealed class DefaultExpression : Expression {
31         private readonly Type _type;
32
33         internal DefaultExpression(Type type) {
34             _type = type;
35         }
36
37         /// <summary>
38         /// Gets the static type of the expression that this <see cref="Expression" /> represents.
39         /// </summary>
40         /// <returns>The <see cref="Type"/> that represents the static type of the expression.</returns>
41         public sealed override Type Type {
42             get { return _type; }
43         }
44
45         /// <summary>
46         /// Returns the node type of this Expression. Extension nodes should return
47         /// ExpressionType.Extension when overriding this method.
48         /// </summary>
49         /// <returns>The <see cref="ExpressionType"/> of the expression.</returns>
50         public sealed override ExpressionType NodeType {
51             get { return ExpressionType.Default; }
52         }
53
54         /// <summary>
55         /// Dispatches to the specific visit method for this node type.
56         /// </summary>
57         protected internal override Expression Accept(ExpressionVisitor visitor) {
58             return visitor.VisitDefault(this);
59         }
60     }
61
62     public partial class Expression {
63         /// <summary>
64         /// Creates an empty expression that has <see cref="System.Void"/> type.
65         /// </summary>
66         /// <returns>
67         /// A <see cref="DefaultExpression"/> that has the <see cref="P:Expression.NodeType"/> property equal to 
68         /// <see cref="F:ExpressionType.Default"/> and the <see cref="P:Expression.Type"/> property set to <see cref="System.Void"/>.
69         /// </returns>
70         public static DefaultExpression Empty() {
71             return new DefaultExpression(typeof(void));
72         }
73
74         /// <summary>
75         /// Creates a <see cref="DefaultExpression"/> that has the <see cref="P:Expression.Type"/> property set to the specified type.
76         /// </summary>
77         /// <param name="type">A <see cref="System.Type"/> to set the <see cref="P:Expression.Type"/> property equal to.</param>
78         /// <returns>
79         /// A <see cref="DefaultExpression"/> that has the <see cref="P:Expression.NodeType"/> property equal to 
80         /// <see cref="F:ExpressionType.Default"/> and the <see cref="P:Expression.Type"/> property set to the specified type.
81         /// </returns>
82         public static DefaultExpression Default(Type type) {
83             if (type == typeof(void)) {
84                 return Empty();
85             }
86             return new DefaultExpression(type);
87         }
88     }
89 }