RazorTemplateEngine.GenerateCode Method

Definition

Overloads

GenerateCode(TextReader, String, String, String, Nullable<CancellationToken>)
GenerateCode(ITextBuffer, String, String, String, Nullable<CancellationToken>)

Parses the template specified by the TextBuffer, generates code for it, and returns the constructed code.

GenerateCode(TextReader, String, String, String)
GenerateCode(Stream, String, String, String)

Parses the contents specified by the inputStream and returns the generated code.

GenerateCode(ITextBuffer, String, String, String)
GenerateCode(TextReader, Nullable<CancellationToken>)
GenerateCode(ITextBuffer, Nullable<CancellationToken>)
GenerateCode(TextReader)
GenerateCode(ITextBuffer)

GenerateCode(TextReader, String, String, String, Nullable<CancellationToken>)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(System::IO::TextReader ^ input, System::String ^ className, System::String ^ rootNamespace, System::String ^ sourceFileName, Nullable<System::Threading::CancellationToken> cancelToken);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (System.IO.TextReader input, string className, string rootNamespace, string sourceFileName, System.Threading.CancellationToken? cancelToken);
member this.GenerateCode : System.IO.TextReader * string * string * string * Nullable<System.Threading.CancellationToken> -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As TextReader, className As String, rootNamespace As String, sourceFileName As String, cancelToken As Nullable(Of CancellationToken)) As GeneratorResults

Parameters

input
TextReader
className
String
rootNamespace
String
sourceFileName
String

Returns

Applies to

GenerateCode(ITextBuffer, String, String, String, Nullable<CancellationToken>)

Parses the template specified by the TextBuffer, generates code for it, and returns the constructed code.

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(Microsoft::AspNetCore::Razor::Text::ITextBuffer ^ input, System::String ^ className, System::String ^ rootNamespace, System::String ^ sourceFileName, Nullable<System::Threading::CancellationToken> cancelToken);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (Microsoft.AspNetCore.Razor.Text.ITextBuffer input, string className, string rootNamespace, string sourceFileName, System.Threading.CancellationToken? cancelToken);
member this.GenerateCode : Microsoft.AspNetCore.Razor.Text.ITextBuffer * string * string * string * Nullable<System.Threading.CancellationToken> -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As ITextBuffer, className As String, rootNamespace As String, sourceFileName As String, cancelToken As Nullable(Of CancellationToken)) As GeneratorResults

Parameters

input
ITextBuffer

The input text to parse.

className
String

The name of the generated class, overriding whatever is specified in the Host. The default value (defined in the Host) can be used by providing null for this argument.

rootNamespace
String

The namespace in which the generated class will reside, overriding whatever is specified in the Host. The default value (defined in the Host) can be used by providing null for this argument.

sourceFileName
String

The file name to use in line pragmas, usually the original Razor file, overriding whatever is specified in the Host. The default value (defined in the Host) can be used by providing null for this argument.

cancelToken
Nullable<CancellationToken>

A token used to cancel the parser.

Returns

The resulting parse tree AND generated code.

Remarks

The cancel token provided can be used to cancel the parse. However, please note that the parse occurs _synchronously_, on the callers thread. This parameter is provided so that if the caller is in a background thread with a CancellationToken, it can pass it along to the parser.

The className, rootNamespace and sourceFileName parameters are optional and override the default specified by the Host. For example, the WebPageRazorHost in System.Web.WebPages.Razor configures the Class Name, Root Namespace and Source File Name based on the virtual path of the page being compiled. However, the built-in RazorEngineHost class uses constant defaults, so the caller will likely want to change them using these parameters.

Applies to

GenerateCode(TextReader, String, String, String)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(System::IO::TextReader ^ input, System::String ^ className, System::String ^ rootNamespace, System::String ^ sourceFileName);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (System.IO.TextReader input, string className, string rootNamespace, string sourceFileName);
member this.GenerateCode : System.IO.TextReader * string * string * string -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As TextReader, className As String, rootNamespace As String, sourceFileName As String) As GeneratorResults

Parameters

input
TextReader
className
String
rootNamespace
String
sourceFileName
String

Returns

Applies to

GenerateCode(Stream, String, String, String)

Parses the contents specified by the inputStream and returns the generated code.

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(System::IO::Stream ^ inputStream, System::String ^ className, System::String ^ rootNamespace, System::String ^ sourceFileName);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (System.IO.Stream inputStream, string className, string rootNamespace, string sourceFileName);
member this.GenerateCode : System.IO.Stream * string * string * string -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (inputStream As Stream, className As String, rootNamespace As String, sourceFileName As String) As GeneratorResults

Parameters

inputStream
Stream

A Stream that represents the contents to be parsed.

className
String

The name of the generated class. When null, defaults to DefaultClassName (Host.DefaultClassName).

rootNamespace
String

The namespace in which the generated class will reside. When null, defaults to DefaultNamespace (Host.DefaultNamespace).

sourceFileName
String

The file name to use in line pragmas, usually the original Razor file.

Returns

A GeneratorResults that represents the results of parsing the content.

Remarks

This overload calculates the checksum of the contents of inputStream prior to code generation. The checksum is used for producing the #pragma checksum line pragma required for debugging.

Applies to

GenerateCode(ITextBuffer, String, String, String)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(Microsoft::AspNetCore::Razor::Text::ITextBuffer ^ input, System::String ^ className, System::String ^ rootNamespace, System::String ^ sourceFileName);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (Microsoft.AspNetCore.Razor.Text.ITextBuffer input, string className, string rootNamespace, string sourceFileName);
member this.GenerateCode : Microsoft.AspNetCore.Razor.Text.ITextBuffer * string * string * string -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As ITextBuffer, className As String, rootNamespace As String, sourceFileName As String) As GeneratorResults

Parameters

input
ITextBuffer
className
String
rootNamespace
String
sourceFileName
String

Returns

Applies to

GenerateCode(TextReader, Nullable<CancellationToken>)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(System::IO::TextReader ^ input, Nullable<System::Threading::CancellationToken> cancelToken);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (System.IO.TextReader input, System.Threading.CancellationToken? cancelToken);
member this.GenerateCode : System.IO.TextReader * Nullable<System.Threading.CancellationToken> -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As TextReader, cancelToken As Nullable(Of CancellationToken)) As GeneratorResults

Parameters

input
TextReader

Returns

Applies to

GenerateCode(ITextBuffer, Nullable<CancellationToken>)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(Microsoft::AspNetCore::Razor::Text::ITextBuffer ^ input, Nullable<System::Threading::CancellationToken> cancelToken);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (Microsoft.AspNetCore.Razor.Text.ITextBuffer input, System.Threading.CancellationToken? cancelToken);
member this.GenerateCode : Microsoft.AspNetCore.Razor.Text.ITextBuffer * Nullable<System.Threading.CancellationToken> -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As ITextBuffer, cancelToken As Nullable(Of CancellationToken)) As GeneratorResults

Parameters

input
ITextBuffer

Returns

Applies to

GenerateCode(TextReader)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(System::IO::TextReader ^ input);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (System.IO.TextReader input);
member this.GenerateCode : System.IO.TextReader -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As TextReader) As GeneratorResults

Parameters

input
TextReader

Returns

Applies to

GenerateCode(ITextBuffer)

public:
 Microsoft::AspNetCore::Razor::CodeGenerators::GeneratorResults ^ GenerateCode(Microsoft::AspNetCore::Razor::Text::ITextBuffer ^ input);
public Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults GenerateCode (Microsoft.AspNetCore.Razor.Text.ITextBuffer input);
member this.GenerateCode : Microsoft.AspNetCore.Razor.Text.ITextBuffer -> Microsoft.AspNetCore.Razor.CodeGenerators.GeneratorResults
Public Function GenerateCode (input As ITextBuffer) As GeneratorResults

Parameters

input
ITextBuffer

Returns

Applies to