コード例 #1
0
 protected override Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
 {
     SetILPathCommand.Initialize(this);
     ShowDefinitionInILSpyCommand.Initialize(this);
     return(base.InitializeAsync(cancellationToken, progress));
 }
コード例 #2
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(Microsoft.VisualStudio.Shell.Package package)
 {
     Instance = new SetILPathCommand(package);
 }
コード例 #3
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var roslynDoc     = GetRoslynDocument();
                var semanticModel = await roslynDoc.GetSemanticModelAsync();

                var symbolAtCursor = getChosenSymbol();
                Debug.WriteLine($" *** Selected Symbol: {symbolAtCursor?.Name} - {symbolAtCursor?.Kind} - {symbolAtCursor?.ContainingAssembly}");

                if (symbolAtCursor == null)
                {
                    ShowInfo("Cannot find symbol selected. Returning...");
                }

                var roslynProject = roslynDoc.Project;

                var id = (symbolAtCursor.OriginalDefinition ?? symbolAtCursor)
                         .GetDocumentationCommentId();
                //ShowInfo(id);

                INamedTypeSymbol namedTypeSymbol = symbolAtCursor as INamedTypeSymbol;
                var alias = symbolAtCursor as IAliasSymbol;
                if (alias != null)
                {
                    namedTypeSymbol = alias.Target as INamedTypeSymbol;
                    //id = namedTypeSymbol.GetDocumentationCommentId();
                }

                var assemblySymbol = (namedTypeSymbol != null)?namedTypeSymbol.ContainingAssembly
                    :symbolAtCursor?.ContainingAssembly;



                bool     isProject;
                var      fullName  = assemblySymbol?.ToDisplayString();
                var      assemPath = GetAssemblyPath(semanticModel, fullName, out isProject);
                var      realPath  = assemPath;
                Assembly assembly  = null;
                try
                {
                    if (assemPath.Contains("packages") || isProject)
                    {
                        assembly = Assembly.ReflectionOnlyLoad(assemPath);
                    }
                    else
                    {
                        Debug.WriteLine($" !!! - loading assembly {assemblySymbol?.Identity.Name} ...");
                        assembly = Assembly.Load(fullName); //such as System
                    }

                    if (assembly != null)
                    {
                        //replace referecend assemblies path with real path
                        //e.g. C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll
                        assemPath = assembly.Location;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }

                var args = "";
                if (assemPath.Contains("assembly\\GAC_"))
                {
                    args = $"\"{assemPath}\" /navigateTo:{id} /singleInstance";
                }
                else
                {
                    args = $"\"{realPath}\" /navigateTo:{id} /singleInstance";
                }

                ShowInfo(args);

                if (string.IsNullOrEmpty(DefSpy.Default.ILSpyPath))
                {
                    SetILPathCommand.GetILSpyPath();
                }
                if (string.IsNullOrEmpty(DefSpy.Default.ILSpyPath))
                {
                    ShowInfo("Please specify path to ILSpy.exe first!");
                }
                else
                {
                    if (_ilSpyProcess == null || _ilSpyProcess.HasExited)
                    {
                        if (_ilSpyProcess != null)
                        {
                            _ilSpyProcess.Dispose();
                        }
                        Trace.WriteLine($"Launching {args}");
                        _ilSpyProcess = Process.Start(DefSpy.Default.ILSpyPath, args);
                        SetWindowText(_ilSpyProcess.MainWindowHandle, $"ILSpy for DefILSpy");
                    }
                    else
                    {
                        //send a message to existing instance
                        var msg = $"ILSpy:\r\n{realPath}\r\n/navigateTo:{id}\r\n/singleInstance";
                        Send(_ilSpyProcess.MainWindowHandle, msg);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowInfo(ex.Message + ":" + ex.StackTrace);
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
        }