DefaultExpression 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表型別的預設值或空運算式。
public ref class DefaultExpression sealed : System::Linq::Expressions::Expression
public sealed class DefaultExpression : System.Linq.Expressions.Expression
type DefaultExpression = class
inherit Expression
Public NotInheritable Class DefaultExpression
Inherits Expression
- 繼承
範例
以下程式碼範例展示了如何利用該 Default 方法建立代表給定型別預設值的表達式。
// Add the following directive to your file:
// using System.Linq.Expressions;
// This expression represents the default value of a type
// (0 for integer, null for a string, etc.)
Expression defaultExpr = Expression.Default(
typeof(byte)
);
// Print out the expression.
Console.WriteLine(defaultExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
Expression.Lambda<Func<byte>>(defaultExpr).Compile()());
// This code example produces the following output:
//
// default(Byte)
// 0
' Add the following directive to your file:
' Imports System.Linq.Expressions
' This expression represents the default value of a type
' (0 for integer, null for a string, and so on).
Dim defaultExpr As Expression = Expression.Default(
GetType(Byte)
)
' Print the expression.
Console.WriteLine(defaultExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(
Expression.Lambda(Of Func(Of Byte))(defaultExpr).Compile()())
' This code example produces the following output:
'
' default(Byte)
' 0
屬性
| 名稱 | Description |
|---|---|
| CanReduce |
表示該節點可以簡化為更簡單的節點。 若此結果為真,則可呼叫 Reduce() 以產生約簡形式。 (繼承來源 Expression) |
| NodeType |
回傳此表達式的節點類型。 當覆寫此方法時,擴充節點應該會回傳 Extension 。 |
| Type |
取得此 Expression 表達式的靜態型態。 |
方法
| 名稱 | Description |
|---|---|
| Accept(ExpressionVisitor) |
針對此節點類型的特定訪問方法進行派遣。 例如,稱為 MethodCallExpressionVisitMethodCall(MethodCallExpression)。 (繼承來源 Expression) |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| Reduce() |
將此節點簡化為更簡單的表達式。 如果 CanReduce 回傳為真,則應回傳一個有效的表達式。 此方法可返回另一個必須被約簡的節點。 (繼承來源 Expression) |
| ReduceAndCheck() |
將此節點簡化為更簡單的表達式。 如果 CanReduce 回傳為真,則應回傳一個有效的表達式。 此方法可返回另一個必須被約簡的節點。 (繼承來源 Expression) |
| ReduceExtensions() |
將表達式簡化為已知節點型別(非擴充節點),或僅回傳已是已知型別的表達式。 (繼承來源 Expression) |
| ToString() |
回傳 的文字表示 Expression。 (繼承來源 Expression) |
| VisitChildren(ExpressionVisitor) |
將節點簡化,然後呼叫訪客代理處理簡化表達式。 若節點不可約,方法會拋出例外。 (繼承來源 Expression) |