本文整理汇总了C#中Microsoft.CodeAnalysis.CodeActions.CodeAction类的典型用法代码示例。如果您正苦于以下问题:C# CodeAction类的具体用法?C# CodeAction怎么用?C# CodeAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeAction类属于Microsoft.CodeAnalysis.CodeActions命名空间,在下文中一共展示了CodeAction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CodeFix
internal CodeFix(Project project, CodeAction action, ImmutableArray<Diagnostic> diagnostics)
{
Debug.Assert(!diagnostics.IsDefault);
this.Project = project;
this.Action = action;
this.Diagnostics = diagnostics;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:7,代码来源:CodeFix.cs
示例2: SuggestedActionWithFlavors
protected SuggestedActionWithFlavors(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
CodeAction codeAction,
object provider) : base(workspace, subjectBuffer, editHandler, codeAction, provider)
{
}
开发者ID:noahstein,项目名称:roslyn,代码行数:8,代码来源:SuggestedActionWithFlavors.cs
示例3: SuggestedActionWithPreview
public SuggestedActionWithPreview(
Workspace workspace, ITextBuffer subjectBuffer, ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator, CodeAction codeAction, object provider,
IAsynchronousOperationListener operationListener)
: base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction,
provider, operationListener, actionSets: null)
{
}
开发者ID:genlu,项目名称:roslyn,代码行数:8,代码来源:SuggestedActionWithPreview.cs
示例4: SuggestedActionWithNestedActions
public SuggestedActionWithNestedActions(
SuggestedActionsSourceProvider sourceProvider, Workspace workspace,
ITextBuffer subjectBuffer, object provider,
CodeAction codeAction, SuggestedActionSet nestedActionSet)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
NestedActionSet = nestedActionSet;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:8,代码来源:SuggestedActionWithNestedActions.cs
示例5: ExecuteCodeAction
private async Task ExecuteCodeAction(CodeAction codeAction)
{
var operations = await codeAction.GetOperationsAsync(CancellationToken.None).ConfigureAwait(true);
foreach (var operation in operations)
{
operation.Apply(_roslynHost.GetDocument(_documentId).Project.Solution.Workspace, CancellationToken.None);
}
}
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:8,代码来源:RoslynContextActionProvider.cs
示例6: CodeRefactoringSuggestedAction
public CodeRefactoringSuggestedAction(
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace,
ITextBuffer subjectBuffer,
CodeRefactoringProvider provider,
CodeAction codeAction)
: base(sourceProvider, workspace, subjectBuffer, provider, codeAction)
{
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:9,代码来源:CodeRefactoringSuggestedAction.cs
示例7: RegisterRefactoring
/// <summary>
/// Add supplied <paramref name="action"/> to the list of refactorings that will be offered to the user.
/// </summary>
/// <param name="action">The <see cref="CodeAction"/> that will be invoked to apply the refactoring.</param>
public void RegisterRefactoring(CodeAction action)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
_registerRefactoring(action);
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:13,代码来源:CodeRefactoringContext.cs
示例8: CodeRefactoringSuggestedAction
public CodeRefactoringSuggestedAction(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
CodeAction codeAction,
CodeRefactoringProvider provider)
: base(workspace, subjectBuffer, editHandler, codeAction, provider)
{
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:9,代码来源:CodeRefactoringSuggestedAction.cs
示例9: SuggestedActionWithNestedFlavors
public SuggestedActionWithNestedFlavors(
SuggestedActionsSourceProvider sourceProvider,
Workspace workspace, ITextBuffer subjectBuffer,
object provider, CodeAction codeAction,
SuggestedActionSet additionalFlavors = null)
: base(sourceProvider, workspace, subjectBuffer,
provider, codeAction)
{
_additionalFlavors = additionalFlavors;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:10,代码来源:SuggestedActionWithNestedFlavors.cs
示例10: SuggestedActionWithFlavors
protected SuggestedActionWithFlavors(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator,
CodeAction codeAction,
object provider,
IAsynchronousOperationListener operationListener) : base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction, provider, operationListener)
{
}
开发者ID:rgani,项目名称:roslyn,代码行数:10,代码来源:SuggestedActionWithFlavors.cs
示例11: CodeRefactoringSuggestedAction
public CodeRefactoringSuggestedAction(
Workspace workspace,
ITextBuffer subjectBuffer,
ICodeActionEditHandlerService editHandler,
IWaitIndicator waitIndicator,
CodeAction codeAction,
CodeRefactoringProvider provider,
IAsynchronousOperationListener operationListener)
: base(workspace, subjectBuffer, editHandler, waitIndicator, codeAction, provider, operationListener)
{
}
开发者ID:genlu,项目名称:roslyn,代码行数:11,代码来源:CodeRefactoringSuggestedAction.cs
示例12: GetFixAllOperationsAsync
private async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext, string fixAllPreviewChangesTitle, bool showPreviewChangesDialog)
{
// We have computed the fix all occurrences code fix.
// Now fetch the new solution with applied fix and bring up the Preview changes dialog.
var cancellationToken = fixAllContext.CancellationToken;
var workspace = fixAllContext.Project.Solution.Workspace;
cancellationToken.ThrowIfCancellationRequested();
var operations = await codeAction.GetOperationsAsync(cancellationToken).ConfigureAwait(false);
if (operations == null)
{
return null;
}
cancellationToken.ThrowIfCancellationRequested();
var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken).ConfigureAwait(false);
if (showPreviewChangesDialog)
{
cancellationToken.ThrowIfCancellationRequested();
using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken))
{
var previewService = workspace.Services.GetService<IPreviewDialogService>();
var glyph = fixAllContext.Project.Language == LanguageNames.CSharp ?
Glyph.CSharpProject :
Glyph.BasicProject;
var changedSolution = previewService.PreviewChanges(
string.Format(EditorFeaturesResources.PreviewChangesOf, fixAllPreviewChangesTitle),
"vs.codefix.fixall",
codeAction.Title,
fixAllPreviewChangesTitle,
glyph,
newSolution,
fixAllContext.Project.Solution);
if (changedSolution == null)
{
// User clicked cancel.
FixAllLogger.LogPreviewChangesResult(applied: false);
return null;
}
FixAllLogger.LogPreviewChangesResult(applied: true, allChangesApplied: changedSolution == newSolution);
newSolution = changedSolution;
}
}
// Get a code action, with apply changes operation replaced with the newSolution.
return GetNewFixAllOperations(operations, newSolution, cancellationToken);
}
开发者ID:nemec,项目名称:roslyn,代码行数:52,代码来源:FixAllGetFixesService.cs
示例13: RefactoringPreviewTooltipWindow
public RefactoringPreviewTooltipWindow (TextEditor editor, DocumentContext documentContext, CodeAction codeAction)
{
this.editor = editor;
this.documentContext = documentContext;
this.codeAction = codeAction;
TransientFor = IdeApp.Workbench.RootWindow;
fontDescription = Pango.FontDescription.FromString (DefaultSourceEditorOptions.Instance.FontName);
fontDescription.Size = (int)(fontDescription.Size * 0.8f);
using (var metrics = PangoContext.GetMetrics (fontDescription, PangoContext.Language)) {
lineHeight = (int)Math.Ceiling (0.5 + (metrics.Ascent + metrics.Descent) / Pango.Scale.PangoScale);
}
}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:14,代码来源:RefactoringPreviewTooltipWindow.cs
示例14: CodeAction
public static void CodeAction(CodeAction codeAction, Document document, string expectedCode)
{
var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
Assert.That(operations.Count(), Is.EqualTo(1));
var operation = operations.Single();
var workspace = document.Project.Solution.Workspace;
operation.Apply(workspace, CancellationToken.None);
var newDocument = workspace.CurrentSolution.GetDocument(document.Id);
var sourceText = newDocument.GetTextAsync(CancellationToken.None).Result;
var text = sourceText.ToString();
Assert.That(text, Is.EqualTo(expectedCode));
}
开发者ID:sangelov,项目名称:RoslynNUnitLight,代码行数:17,代码来源:Verify.cs
示例15: TryGetRedundantLambdaParameterAction
private static bool TryGetRedundantLambdaParameterAction(SyntaxNode syntaxNode, SyntaxNode root,
Document document, out CodeAction action)
{
var parameterList = syntaxNode.Parent?.Parent as ParameterListSyntax;
if (parameterList == null)
{
action = null;
return false;
}
action = CodeAction.Create(TitleRedundantLambdaParameterType, c =>
{
var newParameterList = parameterList.WithParameters(
SyntaxFactory.SeparatedList(parameterList.Parameters.Select(p =>
SyntaxFactory.Parameter(p.Identifier).WithTriviaFrom(p))));
var newRoot = root.ReplaceNode(parameterList, newParameterList);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}, TitleRedundantLambdaParameterType);
return true;
}
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:20,代码来源:RedundantDeclarationCodeFixProvider.cs
示例16: CodeAction
public static void CodeAction(CodeAction codeAction, Document document, string expectedCode)
{
var operations = codeAction.GetOperationsAsync(CancellationToken.None).Result;
Assert.That(operations.Count(), Is.EqualTo(1));
var operation = operations.Single();
var workspace = document.Project.Solution.Workspace;
operation.Apply(workspace, CancellationToken.None);
var newDocument = workspace.CurrentSolution.GetDocument(document.Id);
var sourceText = newDocument.GetTextAsync(CancellationToken.None).Result;
var text = sourceText.ToString();
Console.WriteLine($"New code:\r\n{text}");
// Need to replace win-style line ending to unix-style to avoid build breaks on AppVeyor
text = text.Replace("\r\n", "\n");
expectedCode = expectedCode.Replace("\r\n", "\n");
Assert.That(text, Is.EqualTo(expectedCode));
}
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:22,代码来源:Verify.cs
示例17: GetFixAllOperationsAsync
private async Task<IEnumerable<CodeActionOperation>> GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext, bool showPreviewChangesDialog)
{
// We have computed the fix all occurrences code fix.
// Now fetch the new solution with applied fix and bring up the Preview changes dialog.
var cancellationToken = fixAllContext.CancellationToken;
var workspace = fixAllContext.Project.Solution.Workspace;
cancellationToken.ThrowIfCancellationRequested();
var operations = await codeAction.GetOperationsAsync(cancellationToken).ConfigureAwait(false);
if (operations == null)
{
return null;
}
cancellationToken.ThrowIfCancellationRequested();
var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
if (showPreviewChangesDialog)
{
newSolution = PreviewChanges(
fixAllContext.Project.Solution,
newSolution,
FeaturesResources.FixAllOccurrences,
codeAction.Title,
fixAllContext.Project.Language,
workspace,
cancellationToken);
if (newSolution == null)
{
return null;
}
}
// Get a code action, with apply changes operation replaced with the newSolution.
return GetNewFixAllOperations(operations, newSolution, cancellationToken);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:37,代码来源:FixAllGetFixesService.cs
示例18: RegisterCodeFix
/// <summary>
/// Add supplied <paramref name="action"/> to the list of fixes that will be offered to the user.
/// </summary>
/// <param name="action">The <see cref="CodeAction"/> that will be invoked to apply the fix.</param>
/// <param name="diagnostics">The subset of <see cref="Diagnostics"/> being addressed / fixed by the <paramref name="action"/>.</param>
public void RegisterCodeFix(CodeAction action, ImmutableArray<Diagnostic> diagnostics)
{
if (action == null)
{
throw new ArgumentNullException(nameof(action));
}
VerifyDiagnosticsArgument(diagnostics, _span);
// TODO:
// - Check that all diagnostics are unique (no duplicates).
// - Check that supplied diagnostics form subset of diagnostics originally
// passed to the provider via CodeFixContext.Diagnostics.
_registerCodeFix(action, diagnostics);
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:21,代码来源:CodeFixContext.cs
示例19: GetFixAllSuggestedActionSet
/// <summary>
/// If the provided fix all context is non-null and the context's code action Id matches the given code action's Id then,
/// returns the set of fix all occurrences actions associated with the code action.
/// </summary>
internal SuggestedActionSet GetFixAllSuggestedActionSet(
CodeAction action,
int actionCount,
FixAllState fixAllState,
ImmutableArray<FixAllScope> supportedScopes,
Diagnostic firstDiagnostic,
Workspace workspace)
{
if (fixAllState == null)
{
return null;
}
if (actionCount > 1 && action.EquivalenceKey == null)
{
return null;
}
var fixAllSuggestedActions = ArrayBuilder<FixAllSuggestedAction>.GetInstance();
foreach (var scope in supportedScopes)
{
var fixAllStateForScope = fixAllState.WithScopeAndEquivalenceKey(scope, action.EquivalenceKey);
var fixAllSuggestedAction = new FixAllSuggestedAction(
_owner, workspace, _subjectBuffer, fixAllStateForScope,
firstDiagnostic, action);
fixAllSuggestedActions.Add(fixAllSuggestedAction);
}
return new SuggestedActionSet(
fixAllSuggestedActions.ToImmutableAndFree(),
title: EditorFeaturesResources.Fix_all_occurrences_in);
}
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:38,代码来源:SuggestedActionsSourceProvider.cs
示例20: IsApplicable
private bool IsApplicable(CodeAction action, Workspace workspace)
{
if (!action.PerformFinalApplicabilityCheck)
{
// If we don't even need to perform the final applicability check,
// then the code actoin is applicable.
return true;
}
// Otherwise, defer to the action to make the decision.
this.AssertIsForeground();
return action.IsApplicable(workspace);
}
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:13,代码来源:SuggestedActionsSourceProvider.cs
注:本文中的Microsoft.CodeAnalysis.CodeActions.CodeAction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论