14 using System.Diagnostics;
16 using System.Runtime.InteropServices;
17 using Microsoft.VisualStudio;
18 using Microsoft.VisualStudio.Shell.Interop;
20 namespace SiliconStudio.Paradox.VisualStudio.CodeGenerator
29 private IVsGeneratorProgress codeGeneratorProgress;
30 private string codeFileNameSpace = String.Empty;
31 private string codeFilePath = String.Empty;
33 #region IVsSingleFileGenerator Members
41 int IVsSingleFileGenerator.DefaultExtension(out
string pbstrDefaultExtension)
45 pbstrDefaultExtension = GetDefaultExtension();
46 return VSConstants.S_OK;
50 Trace.WriteLine(
"The call to GetDefaultExtension() has failed: ");
51 Trace.WriteLine(e.ToString());
52 pbstrDefaultExtension = string.Empty;
53 return VSConstants.E_FAIL;
68 int IVsSingleFileGenerator.Generate(
string wszInputFilePath,
string bstrInputFileContents,
string wszDefaultNamespace, IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
70 if (bstrInputFileContents == null)
72 throw new ArgumentNullException(bstrInputFileContents);
75 codeFilePath = wszInputFilePath;
76 codeFileNameSpace = wszDefaultNamespace;
77 codeGeneratorProgress = pGenerateProgress;
79 byte[] bytes = GenerateCode(wszInputFilePath, bstrInputFileContents);
84 rgbOutputFileContents = null;
88 return VSConstants.E_FAIL;
97 int outputLength = bytes.Length;
98 rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(outputLength);
99 Marshal.Copy(bytes, 0, rgbOutputFileContents[0], outputLength);
100 pcbOutput = (uint)outputLength;
101 return VSConstants.S_OK;
110 protected string FileNameSpace
114 return codeFileNameSpace;
121 protected string InputFilePath
132 internal IVsGeneratorProgress CodeGeneratorProgress
136 return codeGeneratorProgress;
144 protected abstract string GetDefaultExtension();
151 protected abstract byte[] GenerateCode(
string inputFileName,
string inputFileContent);
160 protected virtual void GeneratorError(uint level,
string message, uint line, uint column)
162 IVsGeneratorProgress progress = CodeGeneratorProgress;
163 if (progress != null)
165 progress.GeneratorError(0, level, message, line, column);
176 protected virtual void GeneratorWarning(uint level,
string message, uint line, uint column)
178 IVsGeneratorProgress progress = CodeGeneratorProgress;
179 if (progress != null)
181 progress.GeneratorError(1, level, message, line, column);
virtual void GeneratorWarning(uint level, string message, uint line, uint column)
Method that will communicate a warning via the shell callback mechanism
virtual void GeneratorError(uint level, string message, uint line, uint column)
Method that will communicate an error via the shell callback mechanism
A managed wrapper for VS's concept of an IVsSingleFileGenerator which is a custom tool invoked at des...