Freigeben über


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)

Syntax

'Declaration
Function Generate ( _
    wszInputFilePath As String, _
    bstrInputFileContents As String, _
    wszDefaultNamespace As String, _
    <OutAttribute> rgbOutputFileContents As IntPtr(), _
    <OutAttribute> ByRef pcbOutput As UInteger, _
    pGenerateProgress As IVsGeneratorProgress _
) As Integer
'Usage
Dim instance As IVsSingleFileGenerator
Dim wszInputFilePath As String
Dim bstrInputFileContents As String
Dim wszDefaultNamespace As String
Dim rgbOutputFileContents As IntPtr()
Dim pcbOutput As UInteger
Dim pGenerateProgress As IVsGeneratorProgress
Dim returnValue As Integer

returnValue = instance.Generate(wszInputFilePath, _
    bstrInputFileContents, wszDefaultNamespace, _
    rgbOutputFileContents, pcbOutput, _
    pGenerateProgress)
int Generate(
    string wszInputFilePath,
    string bstrInputFileContents,
    string wszDefaultNamespace,
    IntPtr[] rgbOutputFileContents,
    out uint pcbOutput,
    IVsGeneratorProgress pGenerateProgress
)
int Generate(
    [InAttribute] String^ wszInputFilePath, 
    [InAttribute] String^ bstrInputFileContents, 
    [InAttribute] String^ wszDefaultNamespace, 
    [OutAttribute] array<IntPtr>^ rgbOutputFileContents, 
    [OutAttribute] unsigned int% pcbOutput, 
    [InAttribute] IVsGeneratorProgress^ pGenerateProgress
)
abstract Generate : 
        wszInputFilePath:string * 
        bstrInputFileContents:string * 
        wszDefaultNamespace:string * 
        rgbOutputFileContents:IntPtr[] byref * 
        pcbOutput:uint32 byref * 
        pGenerateProgress:IVsGeneratorProgress -> int 
function Generate(
    wszInputFilePath : String, 
    bstrInputFileContents : String, 
    wszDefaultNamespace : String, 
    rgbOutputFileContents : IntPtr[], 
    pcbOutput : uint, 
    pGenerateProgress : IVsGeneratorProgress
) : int

Parameters

  • wszInputFilePath
    Type: System.String
    [in] The full path of the input file. May be nulla null reference (Nothing in Visual Basic) in future releases of Visual Studio, so generators should not rely on this value.
  • bstrInputFileContents
    Type: System.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
    Type: System.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 nulla 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
    Type: array<System.IntPtr[]
    [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
    Type: System.UInt32%
    [out] Returns the count of bytes in the rgbOutputFileContent array.

Return Value

Type: System.Int32
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.

.NET Framework Security

See Also

Reference

IVsSingleFileGenerator Interface

IVsSingleFileGenerator Members

Microsoft.VisualStudio.Shell.Interop Namespace