Files
reswcodegen/RESW File Code Generator/ReswCodeGen.CustomTool/ReswFileCodeGenerator.cs
T

52 lines
1.7 KiB
C#
Raw Normal View History

2012-11-06 23:37:40 +01:00
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell.Interop;
namespace ChristianHelle.DeveloperTools.CodeGenerators.Resw.CustomTool
2012-11-06 23:37:40 +01:00
{
[Guid("98983F6D-BC77-46AC-BA5A-8D9E8763F0D2")]
[ComVisible(true)]
public class ReswFileCodeGenerator : IVsSingleFileGenerator
{
#region IVsSingleFileGenerator Members
public int DefaultExtension(out string pbstrDefaultExtension)
{
pbstrDefaultExtension = ".cs";
return 0;
}
public int Generate(string wszInputFilePath,
string bstrInputFileContents,
string wszDefaultNamespace,
IntPtr[] rgbOutputFileContents,
out uint pcbOutput,
IVsGeneratorProgress pGenerateProgress)
{
try
{
var factory = new CodeGeneratorFactory();
var codeGenerator = factory.Create(wszDefaultNamespace, bstrInputFileContents);
var code = codeGenerator.GenerateCode();
var data = Encoding.UTF8.GetBytes(code);
rgbOutputFileContents[0] = Marshal.AllocCoTaskMem(data.Length);
Marshal.Copy(data, 0, rgbOutputFileContents[0], data.Length);
pcbOutput = (uint)data.Length;
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Unable to generate code");
throw;
}
return 0;
}
#endregion
}
}