本文整理汇总了C#中DiagnosticBag.AsEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticBag.AsEnumerable方法的具体用法?C# DiagnosticBag.AsEnumerable怎么用?C# DiagnosticBag.AsEnumerable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiagnosticBag
的用法示例。
在下文中一共展示了DiagnosticBag.AsEnumerable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetErrorMessageAndMissingAssemblyIdentities
internal string GetErrorMessageAndMissingAssemblyIdentities(DiagnosticBag diagnostics, DiagnosticFormatter formatter, CultureInfo preferredUICulture, AssemblyIdentity linqLibrary, out bool useReferencedModulesOnly, out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities)
{
var errors = diagnostics.AsEnumerable().Where(d => d.Severity == DiagnosticSeverity.Error);
foreach (var error in errors)
{
missingAssemblyIdentities = this.GetMissingAssemblyIdentities(error, linqLibrary);
if (!missingAssemblyIdentities.IsDefault)
{
break;
}
}
if (missingAssemblyIdentities.IsDefault)
{
missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
}
useReferencedModulesOnly = errors.All(HasDuplicateTypesOrAssemblies);
var firstError = errors.FirstOrDefault();
Debug.Assert(firstError != null);
var simpleMessage = firstError as SimpleMessageDiagnostic;
return (simpleMessage != null) ?
simpleMessage.GetMessage() :
formatter.Format(firstError, preferredUICulture ?? CultureInfo.CurrentUICulture);
}
示例2: TestErrors
public void TestErrors(string code, params string[] errors)
{
var compilation = CreateCompilationWithMscorlib(code);
var method = (SourceMethodSymbol)compilation.GlobalNamespace.GetTypeMembers("C").Single().GetMembers("M").Single();
var factory = compilation.GetBinderFactory(method.SyntaxTree);
var bodyBlock = (BlockSyntax)method.BodySyntax;
var parameterBinderContext = factory.GetBinder(bodyBlock);
var binder = new ExecutableCodeBinder(bodyBlock.Parent, method, parameterBinderContext);
var diagnostics = new DiagnosticBag();
var block = binder.BindEmbeddedBlock(bodyBlock, diagnostics);
AssertEx.SetEqual(errors, diagnostics.AsEnumerable().Select(DumpDiagnostic));
}
示例3: GetErrorAndMissingAssemblyIdentities
internal Diagnostic GetErrorAndMissingAssemblyIdentities(DiagnosticBag diagnostics, out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities)
{
var diagnosticsEnumerable = diagnostics.AsEnumerable();
foreach (Diagnostic diagnostic in diagnosticsEnumerable)
{
missingAssemblyIdentities = GetMissingAssemblyIdentities(diagnostic);
if (!missingAssemblyIdentities.IsDefault)
{
break;
}
}
if (missingAssemblyIdentities.IsDefault)
{
missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
}
return diagnosticsEnumerable.FirstOrDefault(d => d.Severity == DiagnosticSeverity.Error);
}
示例4: RecordBindingDiagnostics
/// <remarks>
/// Respects the DocumentationMode at the source location.
/// </remarks>
private void RecordBindingDiagnostics(DiagnosticBag bindingDiagnostics, Location sourceLocation)
{
if (!bindingDiagnostics.IsEmptyWithoutResolution && ((SyntaxTree)sourceLocation.SourceTree).ReportDocumentationCommentDiagnostics())
{
foreach (Diagnostic diagnostic in bindingDiagnostics.AsEnumerable())
{
// CONSIDER: Dev11 actually uses the originating location plus the offset into the cref/name,
// but that just seems silly.
diagnostics.Add(diagnostic.WithLocation(sourceLocation));
}
}
}
示例5: HasNonObsoleteError
private static bool HasNonObsoleteError(DiagnosticBag unusedDiagnostics)
{
foreach (Diagnostic diag in unusedDiagnostics.AsEnumerable())
{
// CONSIDER: If this check is too slow, we could add a helper to DiagnosticBag
// that checks for unrealized diagnostics without expanding them.
switch ((ErrorCode)diag.Code)
{
case ErrorCode.ERR_DeprecatedSymbolStr:
case ErrorCode.ERR_DeprecatedCollectionInitAddStr:
break;
default:
if (diag.Severity == DiagnosticSeverity.Error)
{
return true;
}
break;
}
}
return false;
}
示例6: TestWarnings
public void TestWarnings(string code, params string[] expectedWarnings)
{
var compilation = CreateCompilationWithMscorlib(code);
var method = (SourceMethodSymbol)compilation.GlobalNamespace.GetTypeMembers("C").Single().GetMembers("M").Single();
var factory = compilation.GetBinderFactory(method.SyntaxTree);
var bodyBlock = (BlockSyntax)method.BodySyntax;
var parameterBinderContext = factory.GetBinder(bodyBlock);
var binder = new ExecutableCodeBinder(bodyBlock.Parent, method, parameterBinderContext);
var block = (BoundBlock)binder.BindStatement(bodyBlock, new DiagnosticBag());
var actualWarnings = new DiagnosticBag();
DiagnosticsPass.IssueDiagnostics(compilation, block, actualWarnings, method);
AssertEx.SetEqual(expectedWarnings, actualWarnings.AsEnumerable().Select(DumpDiagnostic));
}
示例7: PreventsSuccessfulDelegateConversion
/// <remarks>
/// WARNING: will resolve lazy diagnostics - do not call this before the member lists are completed
/// or you could trigger infinite recursion.
/// </remarks>
internal static bool PreventsSuccessfulDelegateConversion(DiagnosticBag diagnostics)
{
foreach (Diagnostic diag in diagnostics.AsEnumerable()) // Checking the code would have resolved them anyway.
{
if (ErrorFacts.PreventsSuccessfulDelegateConversion((ErrorCode)diag.Code))
{
return true;
}
}
return false;
}
示例8: CompilationError
private void CompilationError(DiagnosticBag diagnostics)
{
var resolvedLocalDiagnostics = diagnostics.AsEnumerable();
var firstError = resolvedLocalDiagnostics.FirstOrDefault(d => d.Severity == DiagnosticSeverity.Error);
if (firstError != null)
{
throw new CompilationErrorException(FormatDiagnostic(firstError, CultureInfo.CurrentCulture),
(resolvedLocalDiagnostics.AsImmutable()));
}
}