至少我得到了这个问题的风滚草徽章。
经过大量逆向工程后,我找到了解决方案……没有记录……任何地方……
第 1 步:
首先,您需要创建一个编辑器工厂,其中包含它附带的所有花里胡哨 - MSVS 有一个扩展。
第 2 步:
那你就得创建这样一个类
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
class ProvideFileExtensionMapping : RegistrationAttribute
{
private readonly string _name, _id, _editorGuid, _package;
private readonly int _sortPriority;
public ProvideFileExtensionMapping(string id, string name, object editorGuid, string package, int sortPriority)
{
_id = id;
_name = name;
if (editorGuid is Type)
{
_editorGuid = ((Type)editorGuid).GUID.ToString("B");
}
else
{
_editorGuid = editorGuid.ToString();
}
_package = package;
_sortPriority = sortPriority;
}
public override void Register(RegistrationContext context)
{
using (Key mappingKey = context.CreateKey("FileExtensionMapping\\" + _id))
{
mappingKey.SetValue("", _name);
mappingKey.SetValue("DisplayName", _name);
mappingKey.SetValue("EditorGuid", _editorGuid);
mappingKey.SetValue("Package", _package);
mappingKey.SetValue("SortPriority", _sortPriority);
}
}
public override void Unregister(RegistrationAttribute.RegistrationContext context)
{
}
}
第 3 步:
然后您需要将该类作为属性添加到您的编辑器工厂(您在步骤 1 中创建):
[ProvideFileExtensionMapping("{E23E32ED-3467-4401-A364-1352666A3502}", "RText Editor", typeof(EditorFactory), GuidList.guidRTextEditorPluginEditorFactoryString, 100)]
public sealed class EditorFactory : IVsEditorFactory, IDisposable{...}
就是这样。您现在应该能够在 Visual Studio 的编辑器列表中看到您的编辑器。
当文件映射正确时,您的编辑器将被调用。
希望这篇文章可以为其他人节省大量时间..