src/Misc/EFTools/EntityDesign/VisualStudio/SingleFileGenerator/BaseCodeGenerator.cs
/// <summary>
///     main method that the VS shell calls to do the generation
/// </summary>
/// <param name="wszInputFilePath">path to the input file</param>
/// <param name="bstrInputFileContents">contents of the input file as a string (shell handles UTF-8 to Unicode &amp; those types of conversions)</param>
/// <param name="wszDefaultNamespace">default namespace for the generated code file</param>
/// <param name="rgbOutputFileContents">byte-array of output file contents</param>
/// <param name="pcbOutput">count of bytes in the output byte-array</param>
/// <param name="pGenerateProgress">interface to send progress updates to the shell</param>
/// <returns>A status code.</returns>
main method that the VS shell calls to do the generation
main method that the VS shell calls to do the generation
public int Generate(
            string wszInputFilePath,
            string bstrInputFileContents,
            string wszDefaultNamespace,
            IntPtr[] rgbOutputFileContents,
            out uint pcbOutput,
            IVsGeneratorProgress pGenerateProgress)
        {
            if (bstrInputFileContents == null)
            {
                throw new ArgumentNullException(bstrInputFileContents);
            }
            _codeGeneratorProgress = pGenerateProgress;
            var generatedCode = GenerateCode(wszInputFilePath, bstrInputFileContents, wszDefaultNamespace);
            if (generatedCode == null)
            {
                rgbOutputFileContents[0] = IntPtr.Zero;
                pcbOutput = 0;
            }
            else
            {
                var outputLength = generatedCode.Length;
                rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
                Marshal.Copy(generatedCode, 0, rgbOutputFileContents[0], outputLength);
                pcbOutput = (uint)outputLength;
            }
            return VSConstants.S_OK;
        }
public int Generate ( string wszInputFilePath , string bstrInputFileContents , string wszDefaultNamespace , IntPtr [ ] rgbOutputFileContents , out uint pcbOutput , IVsGeneratorProgress pGenerateProgress ) { if ( bstrInputFileContents == null ) { throw new ArgumentNullException ( bstrInputFileContents ) ; } _codeGeneratorProgress = pGenerateProgress ; var generatedCode = GenerateCode ( wszInputFilePath , bstrInputFileContents , wszDefaultNamespace ) ; if ( generatedCode == null ) { rgbOutputFileContents [ 0 ] = IntPtr . Zero ; pcbOutput = 0 ; } else { var outputLength = generatedCode . Length ; rgbOutputFileContents [ 0 ] = Marshal . AllocCoTaskMem ( outputLength ) ; Marshal . Copy ( generatedCode , 0 , rgbOutputFileContents [ 0 ] , outputLength ) ; pcbOutput = ( uint ) outputLength ; } return VSConstants . S_OK ; }
main method that the VS shell calls to do the generation
main method that the VS shell calls to do the generation
// generated code can be null here if there was a valid exception from XmlReader (not valid byte order marker) // The contract between IVsSingleFileGenerator implementors and consumers is that  // any output returned from IVsSingleFileGenerator.Generate() is returned through   // memory allocated via CoTaskMemAlloc(). Therefore, we have to convert the  // byte[] array returned from GenerateCode() into an unmanaged blob.  
A status code.
A status code .
wszInputFilePath
string
path to the input file
path to the input file
bstrInputFileContents
string
contents of the input file as a string (shell handles UTF-8 to Unicode & those types of conversions)
contents of the input file as a string ( shell handles UTF - 8 to Unicode & those types of conversions )
wszDefaultNamespace
string
default namespace for the generated code file
default namespace for the generated code file
rgbOutputFileContents
IntPtr[]
byte-array of output file contents
byte - array of output file contents
uint
out
pGenerateProgress
IVsGeneratorProgress
interface to send progress updates to the shell
interface to send progress updates to the shell
pcbOutput
count of bytes in the output byte-array
count of bytes in the output byte - array