async Task LoadExceptionList()
 {
     classes.Add("System.Exception");
     try {
         Microsoft.CodeAnalysis.Compilation compilation    = null;
         Microsoft.CodeAnalysis.ProjectId   dummyProjectId = null;
         if (IdeApp.ProjectOperations.CurrentSelectedProject != null)
         {
             compilation = await TypeSystemService.GetCompilationAsync(IdeApp.ProjectOperations.CurrentSelectedProject);
         }
         if (compilation == null)
         {
             //no need to unload this assembly context, it's not cached.
             dummyProjectId = Microsoft.CodeAnalysis.ProjectId.CreateNewId("GetExceptionsProject");
             compilation    = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create("GetExceptions")
                              .AddReferences(MetadataReferenceCache.LoadReference(dummyProjectId, System.Reflection.Assembly.GetAssembly(typeof(object)).Location))                                                        //corlib
                              .AddReferences(MetadataReferenceCache.LoadReference(dummyProjectId, System.Reflection.Assembly.GetAssembly(typeof(Uri)).Location));                                                          //System.dll
         }
         var exceptionClass = compilation.GetTypeByMetadataName("System.Exception");
         foreach (var t in compilation.GlobalNamespace.GetAllTypes().Where((arg) => arg.IsDerivedFromClass(exceptionClass)))
         {
             classes.Add(t.GetFullMetadataName());
         }
         if (dummyProjectId != null)
         {
             MetadataReferenceCache.RemoveReferences(dummyProjectId);
         }
     } catch (Exception e) {
         LoggingService.LogError("Failed to obtain exceptions list in breakpoint dialog.", e);
     }
     await Runtime.RunInMainThread(() => {
         entryExceptionType.SetCodeCompletionList(classes.ToList());
     });
 }
Ejemplo n.º 2
0
        async Task LoadExceptionList()
        {
            classes.Add("System.Exception");
            try {
                Microsoft.CodeAnalysis.Compilation compilation = null;
                MonoDevelopWorkspace workspace = null;

                var project = IdeApp.ProjectOperations.CurrentSelectedProject;
                if (project != null)
                {
                    var roslynProj = IdeApp.TypeSystemService.GetProject(project);
                    if (roslynProj != null)
                    {
                        workspace   = (MonoDevelopWorkspace)roslynProj.Solution.Workspace;
                        compilation = await roslynProj.GetCompilationAsync();
                    }
                }

                if (compilation == null)
                {
                    // TypeSystemService.Workspace always returns a workspace,
                    // even if it might be empty.
                    workspace = workspace ?? (MonoDevelopWorkspace)IdeServices.TypeSystemService.Workspace;
                    var service = workspace.MetadataReferenceManager;
                    var corlib  = service.GetOrCreateMetadataReferenceSnapshot(System.Reflection.Assembly.GetAssembly(typeof(object)).Location, MetadataReferenceProperties.Assembly);
                    var system  = service.GetOrCreateMetadataReferenceSnapshot(System.Reflection.Assembly.GetAssembly(typeof(Uri)).Location, MetadataReferenceProperties.Assembly);

                    //no need to unload this assembly context, it's not cached.
                    compilation = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create("GetExceptions")
                                  .AddReferences(corlib)
                                  .AddReferences(system);
                }
                var exceptionClass = compilation.GetTypeByMetadataName("System.Exception");
                foreach (var t in compilation.GlobalNamespace.GetAllTypes().Where((arg) => arg.IsDerivedFromClass(exceptionClass)))
                {
                    classes.Add(t.GetFullMetadataName());
                }
            } catch (Exception e) {
                LoggingService.LogError("Failed to obtain exceptions list in breakpoint dialog.", e);
            }
            await Runtime.RunInMainThread(() => {
                entryExceptionType.SetCodeCompletionList(classes.ToList());
            });
        }
Ejemplo n.º 3
0
 internal static Microsoft.CodeAnalysis.INamedTypeSymbol GetTypeBySystemType <T>(this Microsoft.CodeAnalysis.Compilation compilation)
 {
     return(compilation.GetTypeByMetadataName(typeof(T).FullName));
 }