本文整理汇总了C#中ImmutableArray.Where方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.Where方法的具体用法?C# ImmutableArray.Where怎么用?C# ImmutableArray.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableArray
的用法示例。
在下文中一共展示了ImmutableArray.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDocumentFixesAsync
public override async Task AddDocumentFixesAsync(Document document, ImmutableArray<Diagnostic> diagnostics, Action<CodeAction> addFix, FixAllContext fixAllContext)
{
var pragmaActionsBuilder = ImmutableArray.CreateBuilder<IPragmaBasedCodeAction>();
var pragmaDiagnosticsBuilder = ImmutableArray.CreateBuilder<Diagnostic>();
foreach (var diagnostic in diagnostics.Where(d => d.Location.IsInSource && !d.IsSuppressed))
{
var span = diagnostic.Location.SourceSpan;
var pragmaSuppressions = await _suppressionFixProvider.GetPragmaSuppressionsAsync(document, span, SpecializedCollections.SingletonEnumerable(diagnostic), fixAllContext.CancellationToken).ConfigureAwait(false);
var pragmaSuppression = pragmaSuppressions.SingleOrDefault();
if (pragmaSuppression != null)
{
if (fixAllContext is FixMultipleContext)
{
pragmaSuppression = pragmaSuppression.CloneForFixMultipleContext();
}
pragmaActionsBuilder.Add(pragmaSuppression);
pragmaDiagnosticsBuilder.Add(diagnostic);
}
}
// Get the pragma batch fix.
if (pragmaActionsBuilder.Count > 0)
{
var pragmaBatchFix = PragmaBatchFixHelpers.CreateBatchPragmaFix(_suppressionFixProvider, document,
pragmaActionsBuilder.ToImmutable(), pragmaDiagnosticsBuilder.ToImmutable(), fixAllContext);
addFix(pragmaBatchFix);
}
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:31,代码来源:AbstractSuppressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs
示例2: SequnceStartsWith
private bool SequnceStartsWith(ImmutableArray<string> header, List<string> existingHeader)
{
// Only try if the existing header is at least as long as the new copyright header
if (existingHeader.Count >= header.Count())
{
return !header.Where((headerLine, i) => existingHeader[i] != headerLine).Any();
}
return false;
}
示例3: AddDocumentFixesAsync
public override async Task AddDocumentFixesAsync(Document document, ImmutableArray<Diagnostic> diagnostics, Action<CodeAction> addFix, FixAllContext fixAllContext)
{
foreach (var diagnosticsForSpan in diagnostics.Where(d => d.Location.IsInSource).GroupBy(d => d.Location.SourceSpan))
{
var span = diagnosticsForSpan.First().Location.SourceSpan;
var pragmaSuppressions = await _suppressionFixProvider.GetPragmaSuppressionsAsync(document, span, diagnosticsForSpan, fixAllContext.CancellationToken).ConfigureAwait(false);
foreach (var pragmaSuppression in pragmaSuppressions)
{
addFix(pragmaSuppression);
}
}
}
开发者ID:noahfalk,项目名称:roslyn,代码行数:12,代码来源:AbstractSuppressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs
示例4: AddDocumentFixesAsync
public override async Task AddDocumentFixesAsync(
Document document, ImmutableArray<Diagnostic> diagnostics, Action<CodeAction> addFix,
FixAllState fixAllState, CancellationToken cancellationToken)
{
// Batch all the pragma remove suppression fixes by executing them sequentially for the document.
var pragmaActionsBuilder = ArrayBuilder<IPragmaBasedCodeAction>.GetInstance();
var pragmaDiagnosticsBuilder = ArrayBuilder<Diagnostic>.GetInstance();
foreach (var diagnostic in diagnostics.Where(d => d.Location.IsInSource && d.IsSuppressed))
{
var span = diagnostic.Location.SourceSpan;
var removeSuppressionFixes = await _suppressionFixProvider.GetSuppressionsAsync(
document, span, SpecializedCollections.SingletonEnumerable(diagnostic), cancellationToken).ConfigureAwait(false);
var removeSuppressionFix = removeSuppressionFixes.SingleOrDefault();
if (removeSuppressionFix != null)
{
var codeAction = removeSuppressionFix.Action as RemoveSuppressionCodeAction;
if (codeAction != null)
{
if (fixAllState.IsFixMultiple)
{
codeAction = codeAction.CloneForFixMultipleContext();
}
var pragmaRemoveAction = codeAction as PragmaRemoveAction;
if (pragmaRemoveAction != null)
{
pragmaActionsBuilder.Add(pragmaRemoveAction);
pragmaDiagnosticsBuilder.Add(diagnostic);
}
else
{
addFix(codeAction);
}
}
}
}
// Get the pragma batch fix.
if (pragmaActionsBuilder.Count > 0)
{
var pragmaBatchFix = PragmaBatchFixHelpers.CreateBatchPragmaFix(
_suppressionFixProvider, document,
pragmaActionsBuilder.ToImmutableAndFree(),
pragmaDiagnosticsBuilder.ToImmutableAndFree(),
fixAllState, cancellationToken);
addFix(pragmaBatchFix);
}
}
开发者ID:jkotas,项目名称:roslyn,代码行数:50,代码来源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs
示例5: AddCompilationInfo
public static void AddCompilationInfo(this RunningResults results, ImmutableArray<Diagnostic> diagnostics)
{
if (diagnostics.Length == 0)
{
return;
}
var sb = new StringBuilder();
var errors = diagnostics.Where(d => d.DefaultSeverity.IsOneOf(DiagnosticSeverity.Error, DiagnosticSeverity.Warning)).ToList();
foreach (var error in errors)
{
sb.Append(error);
}
if (errors.Any(e => e.DefaultSeverity == DiagnosticSeverity.Error))
results.Verdict = Verdict.CompilationError;
results.CompilationOutput = sb.ToString();
}
示例6: AddProjectFixesAsync
public async override Task AddProjectFixesAsync(Project project, ImmutableArray<Diagnostic> diagnostics, Action<CodeAction> addFix, FixAllContext fixAllContext)
{
foreach (var diagnostic in diagnostics.Where(d => !d.Location.IsInSource && d.IsSuppressed))
{
var removeSuppressionFixes = await _suppressionFixProvider.GetSuppressionsAsync(project, SpecializedCollections.SingletonEnumerable(diagnostic), fixAllContext.CancellationToken).ConfigureAwait(false);
var removeSuppressionCodeAction = removeSuppressionFixes.SingleOrDefault()?.Action as RemoveSuppressionCodeAction;
if (removeSuppressionCodeAction != null)
{
if (fixAllContext is FixMultipleContext)
{
removeSuppressionCodeAction = removeSuppressionCodeAction.CloneForFixMultipleContext();
}
addFix(removeSuppressionCodeAction);
}
}
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:17,代码来源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs
示例7: WriteWarnings
private static void WriteWarnings(ImmutableArray<Diagnostic> diagnostics)
{
IEnumerable<Diagnostic> warnings = diagnostics.Where(diagnostic =>
diagnostic.Severity == DiagnosticSeverity.Warning);
foreach (Diagnostic diagnostic in warnings)
{
Console.Error.WriteLine("WARNING: {0}: {1}", diagnostic.Id, diagnostic.GetMessage());
}
}
示例8: MergeDiagnostics
private ImmutableArray<DiagnosticData> MergeDiagnostics(ImmutableArray<DiagnosticData> liveDiagnostics, ImmutableArray<DiagnosticData> existingDiagnostics)
{
ImmutableArray<DiagnosticData>.Builder builder = null;
if (liveDiagnostics.Length > 0)
{
builder = ImmutableArray.CreateBuilder<DiagnosticData>();
builder.AddRange(liveDiagnostics);
}
if (existingDiagnostics.Length > 0)
{
builder = builder ?? ImmutableArray.CreateBuilder<DiagnosticData>();
builder.AddRange(existingDiagnostics.Where(d => d.Severity == DiagnosticSeverity.Hidden));
}
return builder == null ? ImmutableArray<DiagnosticData>.Empty : builder.ToImmutable();
}
示例9: AssertMultipleFilesOutput
protected static void AssertMultipleFilesOutput(ImmutableArray<TestFile> input, ImmutableArray<TestFile> output, BuildConstants buildConstants = null, bool ignoreEmptyLines = false) {
AssertMultipleFilesResult(input, (result, testEnvironment) => {
Assert.Equal<string>(
output
.Where(x => x.IsInFlow)
.Select(x => x.Name)
.OrderBy(x => x),
result.ToRight().OrderBy(x => x));
Assert.Equal(input.Length + output.Length, testEnvironment.FileCount);
AssertFiles(output, testEnvironment, ignoreEmptyLines);
}, buildConstants);
}
示例10: AssertMultipleFilesResult
static void AssertMultipleFilesResult(ImmutableArray<TestFile> input, Action<GeneratorResult, TestEnvironment> assertion, BuildConstants buildConstants) {
var testEnvironment = CreateEnvironment(buildConstants);
input.ForEach(file => testEnvironment.Environment.WriteText(file.Name, file.Text));
var result = Generator.Generate(input.Where(file => file.IsInFlow).Select(file => file.Name).ToImmutableArray(), testEnvironment.Environment);
AssertFiles(input, testEnvironment, ignoreEmptyLines: false);
assertion(result, testEnvironment);
}
示例11: ShouldAddExternAlias
private static bool ShouldAddExternAlias(ImmutableArray<string> aliases, CompilationUnitSyntax root)
{
var identifiers = root.DescendantNodes().OfType<ExternAliasDirectiveSyntax>().Select(e => e.Identifier.ToString());
var externAliases = aliases.Where(a => identifiers.Contains(a));
return !externAliases.Any();
}
示例12: ToArgs
/// <summary>
///
/// </summary>
/// <param name="properties"></param>
/// <returns></returns>
private static object[] ToArgs(ImmutableArray<ShapeProperty> properties)
{
return properties.Where(x => x != null).Select(x => x.Value).ToArray();
}
示例13: TraceCompilationDiagnostics
private void TraceCompilationDiagnostics(ImmutableArray<Diagnostic> diagnostics)
{
foreach (var diagnostic in diagnostics.Where(d => !d.IsSuppressed))
{
TraceLevel level = GetTraceLevelFromDiagnostic(diagnostic);
TraceWriter.Trace(new TraceEvent(level, diagnostic.ToString()));
ImmutableArray<Diagnostic> scriptDiagnostics = GetFunctionDiagnostics(diagnostic);
if (!scriptDiagnostics.IsEmpty)
{
TraceCompilationDiagnostics(scriptDiagnostics);
}
}
}
示例14: TraceCompilationDiagnostics
internal void TraceCompilationDiagnostics(ImmutableArray<Diagnostic> diagnostics, LogTargets logTarget = LogTargets.All)
{
if (logTarget == LogTargets.None)
{
return;
}
TraceWriter traceWriter = TraceWriter;
IDictionary<string, object> properties = PrimaryHostTraceProperties;
if (!logTarget.HasFlag(LogTargets.User))
{
traceWriter = Host.TraceWriter;
properties = PrimaryHostSystemTraceProperties;
}
else if (!logTarget.HasFlag(LogTargets.System))
{
properties = PrimaryHostUserTraceProperties;
}
foreach (var diagnostic in diagnostics.Where(d => !d.IsSuppressed))
{
traceWriter.Trace(diagnostic.ToString(), diagnostic.Severity.ToTraceLevel(), properties);
}
}
示例15: GetErrors
private AddTypeCompilerError[] GetErrors(ImmutableArray<Diagnostic> diagnostics)
{
return diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error || d.Severity == DiagnosticSeverity.Warning)
.Select(d => new AddTypeCompilerError
{
ErrorText = d.GetMessage(),
FileName = null,
Line = d.Location.GetMappedLineSpan().StartLinePosition.Line + 1, // Convert 0-based to 1-based
IsWarning = !d.IsWarningAsError && d.Severity == DiagnosticSeverity.Warning,
Column = d.Location.GetMappedLineSpan().StartLinePosition.Character + 1, // Convert 0-based to 1-based
ErrorNumber = d.Id
}).ToArray();
}