- sample.zip
- Sample
- Debugging
- Dsl
- bin
- Debug
- GeneratedCode
- Dsl.csproj
- Dsl.csproj.user
- DslDefinition.dsl
- DslDefinition.dsl.diagram
- GeneratedCode
- obj
- Debug
- TempPE
- GeneratedCode.ConnectionBuilders.cs.dll
- GeneratedCode.Connectors.cs.dll
- GeneratedCode.HelpKeywordHelper.cs.dll
- GeneratedCode.MultiplicityValidation.cs.dll
- GeneratedCode.PropertiesGrid.cs.dll
- Properties
- PropertyTypeNameEditor.cs
- Resources
- ConnectorSourceSearch.cur
- ConnectorTargetSearch.cur
- ExampleConnectorToolBitmap.bmp
- ExampleShapeToolBitmap.bmp
- DslPackage
- Key.snk
- Sample.sln
- Sample.suo
|
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.OLE.Interop;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using System.Diagnostics;
using EnvDTE;
using System.IO;
namespace Company.Smpl
{
[Guid("D8760704-A993-40ee-89B9-FB77764D99AF")]
public class SmplGenerator : IVsSingleFileGenerator, IObjectWithSite
{
private ServiceProvider _serviceProvider;
private object _site;
public string GetDefaultExtension()
{
return ".txt";
}
public virtual void SetSite(object site)
{
_site = site;
_serviceProvider = null;
}
private ServiceProvider SiteServiceProvider
{
get
{
if (_serviceProvider == null)
{
Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider = _site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
_serviceProvider = new ServiceProvider(provider);
}
return _serviceProvider;
}
}
public virtual void GetSite(ref Guid riid, out IntPtr ppvSite)
{
if (_site == null)
{
throw new COMException("ObjectNotSited", -2147467259);
}
IntPtr ptr1 = Marshal.GetIUnknownForObject(_site);
IntPtr ptr2 = IntPtr.Zero;
Marshal.QueryInterface(ptr1, ref riid, out ptr2);
if (ptr2 == IntPtr.Zero)
{
throw new COMException("SiteInterfaceNotSupported", -2147467262);
}
ppvSite = ptr2;
}
public void Generate(
string inputFilePath,
string inputFileContents,
string defaultNamespace,
out System.IntPtr outputFileContents,
out int outputLength,
IVsGeneratorProgress generateProgress)
{
ProjectItem item = SiteServiceProvider.GetService(typeof(EnvDTE.ProjectItem)) as ProjectItem;
outputLength = 0;
byte[] bytes = null;
bytes = GenerateCode(inputFilePath, inputFileContents, item, out outputLength);
if (bytes == null)
{
outputFileContents = IntPtr.Zero;
outputLength = 0;
}
else
{
outputFileContents = Marshal.AllocCoTaskMem(outputLength);
Marshal.Copy(bytes, 0, outputFileContents, outputLength);
}
}
private byte[] GenerateCode(string inputFilePath, string inputFileContents, ProjectItem item, out int length)
{
using (MemoryStream ms = new MemoryStream())
{
using (StreamWriter writer = new StreamWriter(ms))
{
writer.WriteLine("This line was generated by our SmplGenerator.");
writer.Flush();
length = (int)ms.Length;
return ms.GetBuffer();
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here