CodeDefaultValueExpression Class
Assembly: System (in system.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ Public Class CodeDefaultValueExpression Inherits CodeExpression 'Usage Dim instance As CodeDefaultValueExpression
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ public class CodeDefaultValueExpression extends CodeExpression
SerializableAttribute ComVisibleAttribute(true) ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) public class CodeDefaultValueExpression extends CodeExpression
Not applicable.
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 (C# Programmers Reference). 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
System.CodeDom.CodeObject
System.CodeDom.CodeExpression
System.CodeDom.CodeDefaultValueExpression
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.