当前位置: 首页>>代码示例>>C#>>正文


C# CodeFixProvider.GetType方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# CodeFixProvider.GetType方法的具体用法?C# CodeFixProvider.GetType怎么用?C# CodeFixProvider.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider的用法示例。


在下文中一共展示了CodeFixProvider.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsInternalCodeFixProvider

        private static bool IsInternalCodeFixProvider(CodeFixProvider fixer)
        {
            var exportAttributes = fixer.GetType().GetTypeInfo().GetCustomAttributes(typeof(ExportCodeFixProviderAttribute), false);
            if (exportAttributes?.Any() == true)
            {
                var exportAttribute = (ExportCodeFixProviderAttribute)exportAttributes.First();
                return s_predefinedCodeFixProviderNames.Contains(exportAttribute.Name);
            }

            return false;
        }
开发者ID:noahfalk,项目名称:roslyn,代码行数:11,代码来源:FixAllCodeAction.cs

示例2: IsInternalCodeFixProvider

        private static bool IsInternalCodeFixProvider(CodeFixProvider fixer)
        {
            var exportAttributes = fixer.GetType().GetCustomAttributes(typeof(ExportCodeFixProviderAttribute), false);
            if (exportAttributes != null && exportAttributes.Length > 0)
            {
                var exportAttribute = (ExportCodeFixProviderAttribute)exportAttributes[0];
                return s_predefinedCodeFixProviderNames.Contains(exportAttribute.Name);
            }

            return false;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:11,代码来源:FixAllCodeAction.cs

示例3: HasImplementation

        /// <summary>
        /// Check the method body of the Initialize method of an analyzer and if that's empty,
        /// then the analyzer hasn't been implemented yet.
        /// </summary>
        private static bool HasImplementation(CodeFixProvider fixer)
        {
            var method = fixer.GetType().GetTypeInfo().GetMethod("RegisterCodeFixesAsync");
            var stateMachineAttr = method?.GetCustomAttribute<AsyncStateMachineAttribute>();
            var moveNextMethod = stateMachineAttr?.StateMachineType.GetTypeInfo().GetDeclaredMethod("MoveNext");
            if (moveNextMethod != null)
            {
                var body = moveNextMethod.GetMethodBody();
                var ilInstructionCount = body?.GetILAsByteArray()?.Count();
                return ilInstructionCount != 177;
            }

            return true;
        }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:18,代码来源:FixerExtensions.cs

示例4: GetDefaultFixesAsync

 public async Task GetDefaultFixesAsync(CodeFixProvider codefix)
 {
     var tuple = await ServiceSetupAsync(codefix);
     using (var workspace = tuple.Item1)
     {
         Document document;
         EditorLayerExtensionManager.ExtensionManager extensionManager;
         GetDocumentAndExtensionManager(tuple.Item2, workspace, out document, out extensionManager);
         var fixes = await tuple.Item3.GetFixesAsync(document, TextSpan.FromBounds(0, 0), includeSuppressionFixes: true, cancellationToken: CancellationToken.None);
         Assert.True(((TestErrorLogger)tuple.Item4).Messages.Count == 1);
         string message;
         Assert.True(((TestErrorLogger)tuple.Item4).Messages.TryGetValue(codefix.GetType().Name, out message));
     }
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:14,代码来源:CodeFixServiceTests.cs

示例5: GetAndTestFixableDiagnosticIds

        private static ImmutableArray<string> GetAndTestFixableDiagnosticIds(CodeFixProvider codeFixProvider)
        {
            var ids = codeFixProvider.FixableDiagnosticIds;
            if (ids.IsDefault)
            {
                throw new InvalidOperationException(
                    string.Format(
                        WorkspacesResources.FixableDiagnosticIdsIncorrectlyInitialized,
                        codeFixProvider.GetType().Name + "." + nameof(CodeFixProvider.FixableDiagnosticIds)));
            }

            return ids;
        }
开发者ID:binsys,项目名称:roslyn,代码行数:13,代码来源:CodeFixService.cs

示例6: GetDefaultFixes

 public void GetDefaultFixes(CodeFixProvider codefix)
 {
     TestDiagnosticAnalyzerService diagnosticService;
     CodeFixService fixService;
     IErrorLoggerService errorLogger;
     using (var workspace = ServiceSetup(codefix, out diagnosticService, out fixService, out errorLogger))
     {
         Document document;
         EditorLayerExtensionManager.ExtensionManager extensionManager;
         GetDocumentAndExtensionManager(diagnosticService, workspace, out document, out extensionManager);
         var fixes = fixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), includeSuppressionFixes: true, cancellationToken: CancellationToken.None).Result;
         Assert.True(((TestErrorLogger)errorLogger).Messages.Count == 1);
         string message;
         Assert.True(((TestErrorLogger)errorLogger).Messages.TryGetValue(codefix.GetType().Name, out message));
     }
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:16,代码来源:CodeFixServiceTests.cs

示例7: GetFixableDiagnosticIds

        private ImmutableArray<DiagnosticId> GetFixableDiagnosticIds(CodeFixProvider fixer, IExtensionManager extensionManager)
        {
            // If we are passed a null extension manager it means we do not have access to a document so there is nothing to 
            // show the user.  In this case we will log any exceptions that occur, but the user will not see them.
            if (extensionManager != null)
            {
                return extensionManager.PerformFunction(
                    fixer,
                    () => ImmutableInterlocked.GetOrAdd(ref _fixerToFixableIdsMap, fixer, f => f.FixableDiagnosticIds),
                    ImmutableArray<DiagnosticId>.Empty);
            }

            try
            {
                return ImmutableInterlocked.GetOrAdd(ref _fixerToFixableIdsMap, fixer, f => f.FixableDiagnosticIds);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                foreach (var logger in _errorLoggers)
                {
                    logger.Value.LogError(fixer.GetType().Name, e.Message + Environment.NewLine + e.StackTrace);
                }
                return ImmutableArray<DiagnosticId>.Empty;
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:29,代码来源:CodeFixService.cs

示例8: VerifyFixAllAsync

 private async static Task VerifyFixAllAsync(string language, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string[] oldSources, string[] newSources, bool allowNewCompilerDiagnostics, LanguageVersion languageVersionCSharp, Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersionVB, string equivalenceKey = null)
 {
     var project = CreateProject(oldSources, language, languageVersionCSharp, languageVersionVB);
     var compilerDiagnostics = (await Task.WhenAll(project.Documents.Select(d => GetCompilerDiagnosticsAsync(d))).ConfigureAwait(true)).SelectMany(d => d);
     var fixAllProvider = codeFixProvider.GetFixAllProvider();
     if (equivalenceKey == null) equivalenceKey = codeFixProvider.GetType().Name;
     FixAllContext fixAllContext;
     if (analyzer != null)
     {
         var analyzerDiagnostics = await GetSortedDiagnosticsFromDocumentsAsync(analyzer, project.Documents.ToArray()).ConfigureAwait(true);
         Func<Document, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getDocumentDiagnosticsAsync = (doc, ids, ct) =>
             Task.FromResult(analyzerDiagnostics.Where(d => d.Location.SourceTree.FilePath == doc.Name));
         Func<Project, bool, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getProjectDiagnosticsAsync = (proj, b, ids, ct) =>
             Task.FromResult((IEnumerable<Diagnostic>)analyzerDiagnostics); //todo: verify, probably wrong
         var fixAllDiagnosticProvider = new FixAllDiagnosticProvider(codeFixProvider.FixableDiagnosticIds.ToImmutableHashSet(), getDocumentDiagnosticsAsync, getProjectDiagnosticsAsync);
         fixAllContext = new FixAllContext(project.Documents.First(), codeFixProvider, FixAllScope.Solution,
             equivalenceKey,
             codeFixProvider.FixableDiagnosticIds,
             fixAllDiagnosticProvider,
             CancellationToken.None);
     }
     else
     {
         Func<Document, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getDocumentDiagnosticsAsync = async (doc, ids, ct) =>
         {
             var compilerDiags = await GetCompilerDiagnosticsAsync(doc).ConfigureAwait(true);
             return compilerDiags.Where(d => codeFixProvider.FixableDiagnosticIds.Contains(d.Id));
         };
         Func<Project, bool, ImmutableHashSet<string>, CancellationToken, Task<IEnumerable<Diagnostic>>> getProjectDiagnosticsAsync = async (proj, b, ids, ct) =>
             {
                 var theDocs = proj.Documents;
                 var diags = await Task.WhenAll(theDocs.Select(d => getDocumentDiagnosticsAsync(d, ids, ct))).ConfigureAwait(true);
                 return diags.SelectMany(d => d);
             };
         var fixAllDiagnosticProvider = new FixAllDiagnosticProvider(codeFixProvider.FixableDiagnosticIds.ToImmutableHashSet(), getDocumentDiagnosticsAsync, getProjectDiagnosticsAsync);
         fixAllContext = new FixAllContext(project.Documents.First(), codeFixProvider, FixAllScope.Solution,
             equivalenceKey,
             codeFixProvider.FixableDiagnosticIds,
             fixAllDiagnosticProvider,
             CancellationToken.None);
     }
     var action = await fixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(true);
     if (action == null) throw new Exception("No action supplied for the code fix.");
     project = await ApplyFixAsync(project, action).ConfigureAwait(true);
     //check if applying the code fix introduced any new compiler diagnostics
     var newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, (await Task.WhenAll(project.Documents.Select(d => GetCompilerDiagnosticsAsync(d))).ConfigureAwait(true)).SelectMany(d => d));
     if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
         Assert.True(false, $"Fix introduced new compiler diagnostics:\r\n{string.Join("\r\n", newCompilerDiagnostics.Select(d => d.ToString()))}\r\n");
     var docs = project.Documents.ToArray();
     for (int i = 0; i < docs.Length; i++)
     {
         var document = docs[i];
         var actual = await GetStringFromDocumentAsync(document).ConfigureAwait(true);
         newSources[i].Should().Be(actual);
     }
 }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:56,代码来源:CodeFixVerifier.cs


注:本文中的Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。