我使用来自http://msdn.microsoft.com/en-us/library/dd885242(v=vs.110).aspx的信息为VS2012创建了一个MEF编辑器扩展(VSIX)
语法突出显示,语句完成,签名帮助和概述功能正常工作。
编辑器扩展链接文件扩展名与内容的方式如下:http://msdn.microsoft.com/en-us/library/ee372313(v=vs.110).aspx
[Export]
[FileExtension(".hid")]
[ContentType("hid")]
internal static FileExtensionToContentTypeDefinition hiddenFileExtensionDefinition;
我找不到将一些特定的无扩展名文件链接到内容类型的方法。我怎样才能做到这一点?
感谢您阅读我的问题。
感谢Chris Eelmaa的建议,我找到了解决这个问题的方法。它可能不是最好的方法,但至少我解决了这个问题。
所以,在这里,我创建了一个新类,如下所示:
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
class ExtensionlessViewCreationListener : IWpfTextViewCreationListener
{
[Import]
internal IEditorFormatMapService FormatMapService = null;
[Import]
internal IContentTypeRegistryService ContentTypeRegistryService = null;
[Import]
internal SVsServiceProvider ServiceProvider = null;
#region IWpfTextViewCreationListener Members
void IWpfTextViewCreationListener.TextViewCreated(IWpfTextView textView)
{
DTE dte = (DTE)ServiceProvider.GetService(typeof(DTE));
string docName = dte.Documents.Item(dte.Documents.Count).Name;
if (docName.ToLower() == EditorConstants.DICTIONARY_FILE_NAME)
{
var contentType = ContentTypeRegistryService.GetContentType(EditorConstants.LANGUAGE_TYPE);
textView.TextBuffer.ChangeContentType(contentType, null);
}
}
#endregion
}
干杯