Partilhar via


IVsSingleFileGenerator.Generate Method

Definition

Executes the transformation and returns the newly generated output file, whenever a custom tool is loaded, or the input file is saved.

public:
 int Generate(System::String ^ wszInputFilePath, System::String ^ bstrInputFileContents, System::String ^ wszDefaultNamespace, cli::array <IntPtr> ^ rgbOutputFileContents, [Runtime::InteropServices::Out] System::UInt32 % pcbOutput, Microsoft::VisualStudio::Shell::Interop::IVsGeneratorProgress ^ pGenerateProgress);
public int Generate (string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, Microsoft.VisualStudio.Shell.Interop.IVsGeneratorProgress pGenerateProgress);
abstract member Generate : string * string * string * nativeint[] * uint32 * Microsoft.VisualStudio.Shell.Interop.IVsGeneratorProgress -> int
Public Function Generate (wszInputFilePath As String, bstrInputFileContents As String, wszDefaultNamespace As String, rgbOutputFileContents As IntPtr(), ByRef pcbOutput As UInteger, pGenerateProgress As IVsGeneratorProgress) As Integer

Parameters

wszInputFilePath
String

[in] The full path of the input file. May be null in future releases of Visual Studio, so generators should not rely on this value.

bstrInputFileContents
String

[in] The contents of the input file. This is either a UNICODE BSTR (if the input file is text) or a binary BSTR (if the input file is binary). If the input file is a text file, the project system automatically converts the BSTR to UNICODE.

wszDefaultNamespace
String

[in] This parameter is meaningful only for custom tools that generate code. It represents the namespace into which the generated code will be placed. If the parameter is not null and not empty, the custom tool can use the following syntax to enclose the generated code. ' Visual Basic Namespace [default namespace]

        ... End Namespace

        // Visual C#

        namespace [default namespace] { ... }
rgbOutputFileContents

IntPtr[]

nativeint[]

[out] Returns an array of bytes to be written to the generated file. You must include UNICODE or UTF-8 signature bytes in the returned byte array, as this is a raw stream. The memory for rgbOutputFileContents must be allocated using the .NET Framework call, System.Runtime.InteropServices.AllocCoTaskMem, or the equivalent Win32 system call, CoTaskMemAlloc. The project system is responsible for freeing this memory.

pcbOutput
UInt32

[out] Returns the count of bytes in the rgbOutputFileContent array.

pGenerateProgress
IVsGeneratorProgress

[in] A reference to the IVsGeneratorProgress interface through which the generator can report its progress to the project system.

Returns

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From vsshell.idl:

HRESULT IVsSingleFileGenerator::Generate(  
   [in] LPCOLESTR wszInputFilePath,  
   [in] BSTR bstrInputFileContents,  
   [in] LPCOLESTR wszDefaultNamespace,  
   [out] BYTE** rgbOutputFileContents,  
   [out] ULONG* pcbOutput,  
   [in] IVsGeneratorProgress* pGenerateProgress  
);  

For performance reasons, the project system reuses a single instantiation of a custom tool to handle multiple file transformations. Therefore, a custom tool should be designed to handle multiple calls to Generate during its lifetime.

The project system interprets the return value of Generate independently of errors reported through IVsGeneratorProgress. That is, if errors are reported through IVsGeneratorProgress, this method must still return FAILED for the overall generation process to fail.

Applies to