mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-11 18:51:41 +00:00
This commit is contained in:
parent
ccf8622017
commit
3bc586864b
1 changed files with 12 additions and 13 deletions
|
|
@ -11,31 +11,30 @@ namespace Cosmos.VS.XSharp {
|
|||
|
||||
// This is the custom tool used to compile .XS files to .CS files in VS
|
||||
public class FileGenerator : IVsSingleFileGenerator {
|
||||
public int DefaultExtension(out string pbstrDefaultExtension) {
|
||||
pbstrDefaultExtension = ".cs";
|
||||
public int DefaultExtension(out string aDefaultExt) {
|
||||
aDefaultExt = ".cs";
|
||||
return VSConstants.S_OK;
|
||||
}
|
||||
|
||||
public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, IntPtr[] rgbOutputFileContents,
|
||||
out uint pcbOutput, IVsGeneratorProgress pGenerateProgress) {
|
||||
var xGeneratedCode = DoGenerate(wszInputFilePath, bstrInputFileContents, wszDefaultNamespace);
|
||||
public int Generate(string aInputFilePath, string aInputFileContents, string aDefaultNamespace, IntPtr[] aOutputFileContents, out uint oPcbOutput, IVsGeneratorProgress aGenerateProgress) {
|
||||
var xGeneratedCode = DoGenerate(aInputFilePath, aInputFileContents, aDefaultNamespace);
|
||||
var xBytes = Encoding.UTF8.GetBytes(xGeneratedCode);
|
||||
|
||||
if (xBytes.Length > 0) {
|
||||
rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(xBytes.Length);
|
||||
Marshal.Copy(xBytes, 0, rgbOutputFileContents[0], xBytes.Length);
|
||||
pcbOutput = (uint)xBytes.Length;
|
||||
aOutputFileContents[0] = Marshal.AllocCoTaskMem(xBytes.Length);
|
||||
Marshal.Copy(xBytes, 0, aOutputFileContents[0], xBytes.Length);
|
||||
oPcbOutput = (uint)xBytes.Length;
|
||||
} else {
|
||||
rgbOutputFileContents[0] = IntPtr.Zero;
|
||||
pcbOutput = 0;
|
||||
aOutputFileContents[0] = IntPtr.Zero;
|
||||
oPcbOutput = 0;
|
||||
}
|
||||
return VSConstants.S_OK;
|
||||
}
|
||||
|
||||
private static string DoGenerate(string inputFileName, string inputFileContents, string defaultNamespace) {
|
||||
using (var xInput = new StringReader(inputFileContents)) {
|
||||
private static string DoGenerate(string aInputFileName, string aInputFileContents, string aDefaultNamespace) {
|
||||
using (var xInput = new StringReader(aInputFileContents)) {
|
||||
using (var xOut = new StringWriter()) {
|
||||
Cosmos.Compiler.XSharp.Generator.Execute(xInput, inputFileName, xOut, defaultNamespace);
|
||||
Cosmos.Compiler.XSharp.Generator.Execute(xInput, aInputFileName, xOut, aDefaultNamespace);
|
||||
return xOut.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue