This topic has not yet been rated - Rate this topic

CodeSnippetTypeMember Class

Updated: March 2009

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

Namespace:  System.CodeDom
Assembly:  System (in System.dll)
[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class CodeSnippetTypeMember : CodeTypeMember

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.

static void GenCodeFromMember(CodeDomProvider provider, CodeGeneratorOptions options)
{
    options.BracingStyle = "C";
    CodeMemberMethod method1 = 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")));
    StringWriter sw = new StringWriter();
    provider.GenerateCodeFromMember(method1, sw, options);
    snippetMethod = new CodeSnippetTypeMember(sw.ToString());
}
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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.