This topic has not yet been rated - Rate this topic

IVsSingleFileGenerator.Generate Method

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

Namespace: Microsoft.VisualStudio.Shell.Interop
Assembly: Microsoft.VisualStudio.Shell.Interop (in microsoft.visualstudio.shell.interop.dll)

int Generate (
	[InAttribute] string wszInputFilePath,
	[InAttribute] string bstrInputFileContents,
	[InAttribute] string wszDefaultNamespace,
	[OutAttribute] IntPtr[] rgbOutputFileContents,
	out uint pcbOutput,
	[InAttribute] IVsGeneratorProgress pGenerateProgress
)
int Generate (
	/** @attribute InAttribute() */ String wszInputFilePath, 
	/** @attribute InAttribute() */ String bstrInputFileContents, 
	/** @attribute InAttribute() */ String wszDefaultNamespace, 
	/** @attribute OutAttribute() */ IntPtr[] rgbOutputFileContents, 
	/** @attribute OutAttribute() */ /** @ref */ UInt32 pcbOutput, 
	/** @attribute InAttribute() */ IVsGeneratorProgress pGenerateProgress
)
JScript does not support passing value-type arguments by reference.

Parameters

wszInputFilePath

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

bstrInputFileContents

[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

[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 a null reference (Nothing in Visual Basic) 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

[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

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

pGenerateProgress

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

Return Value

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

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.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ