Editar

Compartir a través de


CodeDefaultValueExpression Class

Definition

Represents a reference to a default value.

public ref class CodeDefaultValueExpression : System::CodeDom::CodeExpression
public class CodeDefaultValueExpression : System.CodeDom.CodeExpression
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeDefaultValueExpression : System.CodeDom.CodeExpression
type CodeDefaultValueExpression = class
    inherit CodeExpression
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeDefaultValueExpression = class
    inherit CodeExpression
Public Class CodeDefaultValueExpression
Inherits CodeExpression
Inheritance
CodeDefaultValueExpression
Attributes

Examples

The following code example shows the use of the CodeDefaultValueExpression to create default values for decimal and integer parameters. 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"))))

Remarks

A CodeDefaultValueExpression can be used to represent a reference to a default value.

The Type property specifies the reference to the value type. The CodeDefaultValueExpression class is used in the generation of generics-based code. For more information on generics, see Generics in the .NET Framework Class Library. 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.

The code in part 1 is part of a larger example provided for the CodeTypeParameter class. This code, when run through the C# code generator, results in the C# code that appears in part 2. 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  

Constructors

CodeDefaultValueExpression()

Initializes a new instance of the CodeDefaultValueExpression class.

CodeDefaultValueExpression(CodeTypeReference)

Initializes a new instance of the CodeDefaultValueExpression class using the specified code type reference.

Properties

Type

Gets or sets the data type reference for a default value.

UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to