有人知道我们如何使用"托管兼容模式"调试器,从VS2015内部的VSIX包代码中附加进程?我们目前使用以下代码来查找"Managed 4.0"引擎,但似乎无法找到"托管兼容模式"引擎.
foreach (EnvDTE80.Transport tr in Debugger.Transports)
foreach (EnvDTE80.Engine eng in tr.Engines)
{
if (VisualStudioDebugEngines.Managed40.Equals(new Guid(eng.ID)))
{
transport = tr;
engine = eng;
}
}
process.Attach2(engine);
Run Code Online (Sandbox Code Playgroud)
换句话说:如何在代码中执行此操作:
我们使用Microsoft.VisualStudio.XmlEditor命名空间(https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.xmleditor.aspx)中的类来修改Visual Studio扩展中的xml文档.
由于某种原因,在调用XmlEditingScope.Complete()方法后发生死锁.在Visual Studio的状态栏中,我们看到消息"等待解析完成..."
这是死锁UI线程的堆栈跟踪:
WindowsBase.dll!System.Windows.Threading.DispatcherSynchronizationContext.Wait(System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
mscorlib.dll!System.Threading.SynchronizationContext.InvokeWaitMethodHelper(System.Threading.SynchronizationContext syncContext, System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext)
Microsoft.VisualStudio.Package.LanguageService.14.0.dll!Microsoft.VisualStudio.Package.LanguageService.ParseWaitHandle.WaitOne(int millisecondsTimeout, bool exitContext)
Microsoft.XmlEditor.dll!Microsoft.XmlEditor.XmlLanguageService.WaitForParse(System.IAsyncResult result, Microsoft.XmlEditor.StatusBarIndicator indicator)
Microsoft.XmlEditor.dll!Microsoft.XmlEditor.XmlLanguageService.WaitForParse()
Microsoft.XmlEditor.dll!Microsoft.XmlEditor.XmlParserLock.XmlParserLock(Microsoft.XmlEditor.XmlLanguageService service)
Microsoft.XmlEditor.dll!Microsoft.XmlEditor.Transaction.PushToEditorTreeAndBuffer()
Microsoft.XmlEditor.dll!Microsoft.XmlEditor.Transaction.Complete()
XmlEditingScope.Complete() Line 64
Run Code Online (Sandbox Code Playgroud)
并且Visual Studio解析线程:
mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext) + 0x21 bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) + 0x28 bytes
Microsoft.XmlEditor.dll!Microsoft.XmlEditor.LockManager.Lock(object …Run Code Online (Sandbox Code Playgroud) 我们目前正在使用以下算法来检测地理点是否位于复杂多边形内。这工作正常,除非多边形穿过 180\xc2\xb0 经线。
\n\n例如,在多边形中未检测到点 (-170, 60) 160,65,0 160,15,0 -160,15,0 -160,65,0 160,65,0
\n\n看下图:\n[Img]http://tinypic.com/r/14x2xl1[/img]\n我想要红框中的所有内容。不是黄盒子!
\n\n public static bool IsCoordinateInPolygon(IList<KMLCoordinate> polygon, KMLCoordinate testPoint)\n {\n\n bool result = false;\n int j = polygon.Count - 1;\n for (int i = 0; i < polygon.Count; i++)\n {\n if (polygon[i].Latitude < testPoint.Latitude && polygon[j].Latitude >= testPoint.Latitude || polygon[j].Latitude < testPoint.Latitude && polygon[i].Latitude >= testPoint.Latitude)\n {\n if (polygon[i].Longitude + (testPoint.Latitude - polygon[i].Latitude) / (polygon[j].Latitude - polygon[i].Latitude) * (polygon[j].Longitude - polygon[i].Longitude) < testPoint.Longitude)\n {\n result = !result;\n …Run Code Online (Sandbox Code Playgroud) 我有两个列表框的视图:
列表框 1 元素:A、B、C。列表框 2 元素:...、A、...、B、...、C、...(长列表)。
当用户在列表框 1 中选择一个元素时,我想在列表框 2 中也将相同的元素滚动到视图中(而不是选择)。
在我的视图模型中,我有一个属性绑定到列表框 2 的 SelectedItem。但是如何将该元素滚动到列表框 2 的视图中?当然,我不能在我的 VM 中执行 listbox.ScrollIntoView(selectedItem)。
使用 MVVM 模式解决此问题的最佳解决方案是什么?
有没有一种简单的方法可以从树中删除 SyntaxNode(即方法),但保留结构化的琐事?
在下面的代码中,我想删除 MethodA:
public class Sample
{
#region SomeRegion
public void MethodA()
{
}
#endregion
}
Run Code Online (Sandbox Code Playgroud)
我使用 CSharpSyntaxRewriter 来重写 SyntaxTree。在 VisitMethodDeclaration 方法中,我只是为 MethodA 返回 null。这种方法的问题在于 #region 标签的 StructuredTrivia 也被删除了。这是结果结果:
public class Sample
{
#endregion
}
Run Code Online (Sandbox Code Playgroud)
在我的 CSharpSyntaxRewriter 中:
public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
{
if (...)
return null;
else
return node;
}
Run Code Online (Sandbox Code Playgroud)
编辑:如以下答案之一所述,我可以将 SyntaxNode.RemoveNodes 与 SyntaxRemoveOptions.KeepDirectives 选项一起使用。这个解决方案有两个很大的缺点:
EDIT2:这是我正在尝试做的一些代码:https : //dotnetfiddle.net/1Cg6UZ
在下面的代码中,"Console.WriteLine"调用需要使用"System"using指令才能工作.我已经有一个"使用System"的UsingDirectiveSyntax对象和一个"Console.Writeline"的InvocationExpressionSyntax对象.但是,如何使用Roslyn知道InvocationExpressionSyntax和UsingDirectiveSyntax对象是否相互属于何?
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
Run Code Online (Sandbox Code Playgroud) 从Visual Studio 2015开始,扩展SDK支持在文档窗口的顶部显示信息栏:请参阅https://msdn.microsoft.com/en-us/library/mt300796.aspx#BKMK_Infobars.不幸的是,功能性不适用于VS2010.由于我们的扩展还需要支持较旧的Visual Studio版本,从Visual Studio 2010开始,是否有另一种可能的解决方案在文档窗口顶部显示信息栏?
我试图使用边距来动态显示信息栏.但这并不奏效.看起来Visual Studio不喜欢我在显示/隐藏信息边缘中的项目时更改边距大小的事实.
c# visual-studio vs-extensibility vsix visual-studio-extensions
是否可以通过Roslyn了解Symbol是否是接口中某些内容的实现?比如Dispose()在IDisposable?
我有一个表示Dispose()方法的符号,但据我所知,没有属性表明它是由IDisposable接口定义的方法的实现.
我正在使用以下代码来检索代码块中使用的所有符号。这包括声明和对符号的引用。不幸的是,GetSymbolInfo调用非常慢,因此,此方法花费的总时间可能很长。有没有办法加快速度?
public static IEnumerable<ISymbol> GetAllSymbols(CSharpCompilation compilation, SyntaxNode root)
{
var noDuplicates = new HashSet<ISymbol>();
var model = compilation.GetSemanticModel(root.SyntaxTree);
foreach (var node in root.DescendantNodesAndSelf())
{
ISymbol symbol = model.GetDeclaredSymbol(node) ??
model.GetSymbolInfo(node).Symbol;
if (symbol != null)
{
if (noDuplicates.Add(symbol))
yield return symbol;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下日期时间:
Start = 15/12/2012 13:00:00
End = 16/02/2013 14:00:00
Run Code Online (Sandbox Code Playgroud)
我怎样才能将它分成3个部分?
- 15-12-2012 13:00:00 -> 01-01-2013 00:00:00
- 01-01-2013 00:00:00 -> 01-02-2013 00:00:00
- 01-02-2013 00:00:00 -> 16-02-2013 14:00:00
Run Code Online (Sandbox Code Playgroud)
总时间跨度必须保持不变.LINQ可以轻松完成吗?
是否有可能以某种方式在面向Visual Studio版本2010的VsExtension中使用VisualStudioWorkspace服务?(http://source.roslyn.codeplex.com/#Microsoft.VisualStudio.LanguageServices/Implementation/ProjectSystem/VisualStudioWorkspace.cs,e757fe6b8e91e765)
我尝试使用MEF导入服务,如https://joshvarty.wordpress.com/2014/09/12/learn-roslyn-now-part-6-working-with-workspaces/所述,但这不适用于所有.
[Import(typeof(Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace))]
public VisualStudioWorkspace myWorkspace { get; set; }
Run Code Online (Sandbox Code Playgroud)