This documentation is archived and is not being maintained.

CodeSnippetTypeMember Class

Updated: March 2009

Represents a member of a type using a literal code fragment.

Namespace:  System.CodeDom
Assembly:  System (in System.dll)

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CodeSnippetTypeMember _
	Inherits CodeTypeMember
'Usage
Dim instance As CodeSnippetTypeMember

CodeSnippetTypeMember can represent a member of a type using a literal code fragment that is included directly in the source without modification. This code can be included in the type declaration.

A CodeSnippetTypeMember stores a section of code, exactly in its original format, as a string. The CodeDOM does not translate literal code fragments. Literal code fragments are stored and output in their original format. CodeDOM objects that contain literal code are provided so developers can encapsulate code that is already in the target language.

The Text property contains the literal code for the type member.

The following example demonstrates the use of the CodeSnippetTypeMember class to store literal code in a string format. This code example is part of a larger example provided for the GenerateCodeFromMember method.

    Shared Sub GenCodeFromMember(ByVal provider As CodeDomProvider, ByVal options As CodeGeneratorOptions) 
        options.BracingStyle = "C" 
        Dim method1 As New CodeMemberMethod()
        method1.Name = "ReturnString"
        method1.Attributes = MemberAttributes.Public
        method1.ReturnType = New CodeTypeReference("System.String")
        method1.Parameters.Add(New CodeParameterDeclarationExpression("System.String", "text"))
        method1.Statements.Add(New CodeMethodReturnStatement(New CodeArgumentReferenceExpression("text")))
        Dim sw As New StringWriter()
        provider.GenerateCodeFromMember(method1, sw, options)
        snippetMethod = New CodeSnippetTypeMember(sw.ToString())

    End Sub 'GenCodeFromMember
End Class 'Program 

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeTypeMember
      System.CodeDom.CodeSnippetTypeMember

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Date

History

Reason

March 2009

Replaced code example.

Customer feedback.

Show: