CodeDefaultValueExpression CodeDefaultValueExpression CodeDefaultValueExpression CodeDefaultValueExpression Class

定義

表示參考預設值。Represents a reference to a default value.

public ref class CodeDefaultValueExpression : System::CodeDom::CodeExpression
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeDefaultValueExpression : System.CodeDom.CodeExpression
type CodeDefaultValueExpression = class
    inherit CodeExpression
Public Class CodeDefaultValueExpression
Inherits CodeExpression
繼承
CodeDefaultValueExpressionCodeDefaultValueExpressionCodeDefaultValueExpressionCodeDefaultValueExpression
屬性

範例

下列程式碼範例示範CodeDefaultValueExpression如何使用來建立十進位和整數參數的預設值。The following code example shows the use of the CodeDefaultValueExpression to create default values for decimal and integer parameters. 這個範例是針對CodeTypeParameter類別提供之較大範例的一部分。This example is part of a larger example provided for the CodeTypeParameter class.

printMethod.Statements.Add(ConsoleWriteLineStatement(
    new CodeDefaultValueExpression(new CodeTypeReference("T"))));
printMethod.Statements.Add(ConsoleWriteLineStatement(
    new CodeDefaultValueExpression(new CodeTypeReference("S"))));
printMethod.Statements.Add(ConsoleWriteLineStatement _
    (New CodeDefaultValueExpression(New CodeTypeReference("T"))))
printMethod.Statements.Add(ConsoleWriteLineStatement _
    (New CodeDefaultValueExpression(New CodeTypeReference("S"))))

備註

CodeDefaultValueExpression可以用來代表預設值的參考。A CodeDefaultValueExpression can be used to represent a reference to a default value.

Type屬性會指定實數值型別的參考。The Type property specifies the reference to the value type. CodeDefaultValueExpression類別是用來產生以泛型為基礎的程式碼。The CodeDefaultValueExpression class is used in the generation of generics-based code. 如需泛型的詳細資訊, 請參閱.NET Framework 類別庫中的泛型For more information on generics, see Generics in the .NET Framework Class Library. 本節提供下列程式碼步驟, 進一步描述CodeDefaultValueExpression類別的使用方式, 以將新的預設值加入至程式碼圖形。The following code steps are provided in this section to further describe the use of the CodeDefaultValueExpression class to add a new default value to a code graph.

第1部分中的程式碼是針對CodeTypeParameter類別提供之較大範例的一部分。The code in part 1 is part of a larger example provided for the CodeTypeParameter class. 這段程式碼會在透過C#程式碼產生器執行時C# , 導致第2部分出現的程式碼。This code, when run through the C# code generator, results in the C# code that appears in part 2. 當第3部分的語句中呼叫此程式碼時, 結果會是第4部分中所顯示的輸出。When this code is called in the statement in part 3, the result is the output shown in part 4.

// Part 1: Code to create a generic Print method.  
            CodeMemberMethod printMethod = new CodeMemberMethod();  
            CodeTypeParameter sType = new CodeTypeParameter("S");  
            sType.HasConstructorConstraint = true;  
            CodeTypeParameter tType = new CodeTypeParameter("T");  
            sType.HasConstructorConstraint = true;  
  
            printMethod.Name = "Print";  
            printMethod.TypeParameters.Add(sType);  
            printMethod.TypeParameters.Add(tType);  
            printMethod.Statements.Add(ConsoleWriteLineStatement(  
                new CodeDefaultValueExpression(new CodeTypeReference("T"))));  
            printMethod.Statements.Add(ConsoleWriteLineStatement(  
                new CodeDefaultValueExpression(new CodeTypeReference("S"))));  
// Part 2: Code generated by code in part 1.  
public virtual void Print<S, T>()  
            where S : new()  
         {  
            Console.WriteLine(default(T));  
            Console.WriteLine(default(S));  
        }  
// Part 3: Call to the generated method.  
dict.Print<System.Decimal, int>();  
// Part 4: Output of the generated method.  
0  
0  
  

建構函式

CodeDefaultValueExpression() CodeDefaultValueExpression() CodeDefaultValueExpression() CodeDefaultValueExpression()

初始化 CodeDefaultValueExpression 類別的新執行個體。Initializes a new instance of the CodeDefaultValueExpression class.

CodeDefaultValueExpression(CodeTypeReference) CodeDefaultValueExpression(CodeTypeReference) CodeDefaultValueExpression(CodeTypeReference) CodeDefaultValueExpression(CodeTypeReference)

使用指定的程式碼型別參考,初始化 CodeDefaultValueExpression 類別的新執行個體。Initializes a new instance of the CodeDefaultValueExpression class using the specified code type reference.

屬性

Type Type Type Type

取得或設定預設值的資料型別參考。Gets or sets the data type reference for a default value.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於