Skip to content

Instantly share code, notes, and snippets.

@sharwell
Created August 31, 2012 09:23
Show Gist options
  • Save sharwell/3550725 to your computer and use it in GitHub Desktop.
Save sharwell/3550725 to your computer and use it in GitHub Desktop.
MEF support for the Output Window in Visual Studio 2010: VsOutputWindowPaneAdapter
namespace JavaLanguageService.Panes
{
using System;
using System.Diagnostics.Contracts;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
internal sealed class VsOutputWindowPaneAdapter : IOutputWindowPane, IDisposable
{
private IVsOutputWindowPane _pane;
public VsOutputWindowPaneAdapter(IVsOutputWindowPane pane)
{
Contract.Requires<ArgumentNullException>(pane != null);
this._pane = pane;
}
public string Name
{
get
{
string name = null;
ErrorHandler.ThrowOnFailure(this._pane.GetName(ref name));
return name;
}
set
{
ErrorHandler.ThrowOnFailure(this._pane.SetName(value));
}
}
public void Dispose()
{
_pane = null;
}
public void Activate()
{
ErrorHandler.ThrowOnFailure(this._pane.Activate());
}
public void Hide()
{
ErrorHandler.ThrowOnFailure(this._pane.Hide());
}
public void Write(string text)
{
Contract.Requires<ArgumentNullException>(text != null);
ErrorHandler.ThrowOnFailure(this._pane.OutputStringThreadSafe(text));
}
public void WriteLine(string text)
{
Contract.Requires<ArgumentNullException>(text != null);
if (!text.EndsWith(Environment.NewLine))
text += Environment.NewLine;
Write(text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment