/// <summary>
        /// Called by Visual Studio when it needs to generate or
        /// regenerate the code file from your the custom tool
        /// input file.
        /// </summary>
        /// <param name="wszInputFilePath"></param>
        /// <param name="bstrInputFileContents"></param>
        /// <param name="wszDefaultNamespace"></param>
        /// <param name="rgbOutputFileContents"></param>
        /// <param name="pcbOutput"></param>
        /// <param name="pGenerateProgress"></param>
        /// <returns></returns>
        int IVsSingleFileGenerator.Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            GenerationEventArgs gea = new GenerationEventArgs(
                bstrInputFileContents,
                wszInputFilePath,
                wszDefaultNamespace,
                new ServiceProvider(Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider)
                .GetService(typeof(ProjectItem)) as ProjectItem);

            if (OnGenerateCode != null)
            {
                OnGenerateCode(this, gea);
            }

            if (gea.OutputFileExtension.StartsWith("."))
            {
                this.FileExtension = gea.OutputFileExtension;
            }
            else
            {
                this.FileExtension = "." + gea.OutputFileExtension;
            }

            GenerationProgressFacade progressFacade =
                new GenerationProgressFacade(pGenerateProgress);

            foreach (GenerationWarning warning in gea.Warnings)
            {
                progressFacade.GenerateWarning(
                    warning.Message,
                    warning.LineNumber,
                    warning.ColumnNumber);
            }

            foreach (GenerationError error in gea.Errors)
            {
                progressFacade.GenerateError(
                    error.Message,
                    error.LineNumber,
                    error.ColumnNumber);
            }

            byte[] bytes = gea.GetOutputCodeBytes();

            int outputLength = bytes.Length;

            rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
            Marshal.Copy(bytes, 0, rgbOutputFileContents[0], outputLength);
            pcbOutput = (uint)outputLength;

            if (gea.FailOnError && gea.Errors.Count > 0)
            {
                return(VSConstants.E_FAIL);
            }
            else
            {
                return(VSConstants.S_OK);
            }
        }
        /// <summary>
        /// Called by Visual Studio when it needs to generate or 
        /// regenerate the code file from your the custom tool
        /// input file.
        /// </summary>
        /// <param name="wszInputFilePath"></param>
        /// <param name="bstrInputFileContents"></param>
        /// <param name="wszDefaultNamespace"></param>
        /// <param name="rgbOutputFileContents"></param>
        /// <param name="pcbOutput"></param>
        /// <param name="pGenerateProgress"></param>
        /// <returns></returns>
        int IVsSingleFileGenerator.Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            GenerationEventArgs gea = new GenerationEventArgs(
                bstrInputFileContents,
                wszInputFilePath,
                wszDefaultNamespace,
                new ServiceProvider(Site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider)
                    .GetService(typeof(ProjectItem)) as ProjectItem);

            if (OnGenerateCode != null)
            {
                OnGenerateCode(this, gea);
            }

            if (gea.OutputFileExtension.StartsWith("."))
            {
                this.FileExtension = gea.OutputFileExtension;
            }
            else
            {
                this.FileExtension = "." + gea.OutputFileExtension;
            }

            GenerationProgressFacade progressFacade =
                new GenerationProgressFacade(pGenerateProgress);

            foreach (GenerationWarning warning in gea.Warnings)
            {
                progressFacade.GenerateWarning(
                    warning.Message,
                    warning.LineNumber,
                    warning.ColumnNumber);
            }

            foreach (GenerationError error in gea.Errors)
            {
                progressFacade.GenerateError(
                    error.Message,
                    error.LineNumber,
                    error.ColumnNumber);
            }

            byte[] bytes = gea.GetOutputCodeBytes();

            int outputLength = bytes.Length;
            rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
            Marshal.Copy(bytes, 0, rgbOutputFileContents[0], outputLength);
            pcbOutput = (uint)outputLength;

            if (gea.FailOnError && gea.Errors.Count > 0)
            {
                return VSConstants.E_FAIL;
            }
            else
            {
                return VSConstants.S_OK;
            }
        }