This documentation is archived and is not being maintained.

CSharpCodeProvider.GenerateCodeFromMember Method

Generates code for the specified class member using the specified text writer and code generator options.

Namespace:  Microsoft.CSharp
Assembly:  System (in System.dll)

public override void GenerateCodeFromMember(
	CodeTypeMember member,
	TextWriter writer,
	CodeGeneratorOptions options


Type: System.CodeDom.CodeTypeMember
A CodeTypeMember to generate code for.
Type: System.IO.TextWriter
The TextWriter to write to.
Type: System.CodeDom.Compiler.CodeGeneratorOptions
The CodeGeneratorOptions to use when generating the code.

Members are generated differently depending on their context. For example, a method in an interface or a field in an enumeration is generated differently than a method or field on a class. This implementation generates code for a member in the class context.

The following code example shows the use of the GenerateCodeFromMember method to create a code fragment to be used in a CodeDOM graph. This code example is part of a larger example provided for the GenerateCodeFromMember method of the CodeDomProvider class.

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());

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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