1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. 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 Apache License, Version 2.0, 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 Apache License, Version 2.0.
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.
27 [DebuggerTypeProxy(typeof(Expression.DefaultExpressionProxy))]
28 public sealed class DefaultExpression : Expression {
29 private readonly Type _type;
31 internal DefaultExpression(Type type) {
36 /// Gets the static type of the expression that this <see cref="Expression" /> represents.
38 /// <returns>The <see cref="Type"/> that represents the static type of the expression.</returns>
39 public sealed override Type Type {
44 /// Returns the node type of this Expression. Extension nodes should return
45 /// ExpressionType.Extension when overriding this method.
47 /// <returns>The <see cref="ExpressionType"/> of the expression.</returns>
48 public sealed override ExpressionType NodeType {
49 get { return ExpressionType.Default; }
53 /// Dispatches to the specific visit method for this node type.
55 protected internal override Expression Accept(ExpressionVisitor visitor) {
56 return visitor.VisitDefault(this);
60 public partial class Expression {
62 /// Creates an empty expression that has <see cref="System.Void"/> type.
65 /// A <see cref="DefaultExpression"/> that has the <see cref="P:Expression.NodeType"/> property equal to
66 /// <see cref="F:ExpressionType.Default"/> and the <see cref="P:Expression.Type"/> property set to <see cref="System.Void"/>.
68 public static DefaultExpression Empty() {
69 return new DefaultExpression(typeof(void));
73 /// Creates a <see cref="DefaultExpression"/> that has the <see cref="P:Expression.Type"/> property set to the specified type.
75 /// <param name="type">A <see cref="System.Type"/> to set the <see cref="P:Expression.Type"/> property equal to.</param>
77 /// A <see cref="DefaultExpression"/> that has the <see cref="P:Expression.NodeType"/> property equal to
78 /// <see cref="F:ExpressionType.Default"/> and the <see cref="P:Expression.Type"/> property set to the specified type.
80 public static DefaultExpression Default(Type type) {
81 if (type == typeof(void)) {
84 return new DefaultExpression(type);