1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
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.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
17 using System.Diagnostics;
20 namespace Microsoft.Scripting.Ast {
22 namespace System.Linq.Expressions {
25 /// Represents the default value of a type or an empty expression.
28 [DebuggerTypeProxy(typeof(Expression.DefaultExpressionProxy))]
30 public sealed class DefaultExpression : Expression {
31 private readonly Type _type;
33 internal DefaultExpression(Type type) {
38 /// Gets the static type of the expression that this <see cref="Expression" /> represents.
40 /// <returns>The <see cref="Type"/> that represents the static type of the expression.</returns>
41 public sealed override Type Type {
46 /// Returns the node type of this Expression. Extension nodes should return
47 /// ExpressionType.Extension when overriding this method.
49 /// <returns>The <see cref="ExpressionType"/> of the expression.</returns>
50 public sealed override ExpressionType NodeType {
51 get { return ExpressionType.Default; }
55 /// Dispatches to the specific visit method for this node type.
57 protected internal override Expression Accept(ExpressionVisitor visitor) {
58 return visitor.VisitDefault(this);
62 public partial class Expression {
64 /// Creates an empty expression that has <see cref="System.Void"/> type.
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"/>.
70 public static DefaultExpression Empty() {
71 return new DefaultExpression(typeof(void));
75 /// Creates a <see cref="DefaultExpression"/> that has the <see cref="P:Expression.Type"/> property set to the specified type.
77 /// <param name="type">A <see cref="System.Type"/> to set the <see cref="P:Expression.Type"/> property equal to.</param>
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.
82 public static DefaultExpression Default(Type type) {
83 if (type == typeof(void)) {
86 return new DefaultExpression(type);