Files
2026-08-27 10:56:38 -06:00

76 lines
2.9 KiB
C#

using System.Collections.Generic;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.CSharp;
internal static class DiagnosticBagExtensions
{
internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location)
{
CSDiagnosticInfo cSDiagnosticInfo = new CSDiagnosticInfo(code);
CSDiagnostic cSDiagnostic = new CSDiagnostic((DiagnosticInfo)(object)cSDiagnosticInfo, location);
diagnostics.Add((Diagnostic)(object)cSDiagnostic);
return cSDiagnosticInfo;
}
internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, params object[] args)
{
CSDiagnosticInfo cSDiagnosticInfo = new CSDiagnosticInfo(code, args);
CSDiagnostic cSDiagnostic = new CSDiagnostic((DiagnosticInfo)(object)cSDiagnosticInfo, location);
diagnostics.Add((Diagnostic)(object)cSDiagnostic);
return cSDiagnosticInfo;
}
internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, ImmutableArray<Symbol> symbols, params object[] args)
{
CSDiagnosticInfo cSDiagnosticInfo = new CSDiagnosticInfo(code, args, symbols, ImmutableArray<Location>.Empty);
CSDiagnostic cSDiagnostic = new CSDiagnostic((DiagnosticInfo)(object)cSDiagnosticInfo, location);
diagnostics.Add((Diagnostic)(object)cSDiagnostic);
return cSDiagnosticInfo;
}
internal static void Add(this DiagnosticBag diagnostics, DiagnosticInfo info, Location location)
{
CSDiagnostic cSDiagnostic = new CSDiagnostic(info, location);
diagnostics.Add((Diagnostic)(object)cSDiagnostic);
}
internal static bool Add(this DiagnosticBag diagnostics, SyntaxNode node, HashSet<DiagnosticInfo> useSiteDiagnostics)
{
if (!HashSetExtensions.IsNullOrEmpty<DiagnosticInfo>(useSiteDiagnostics))
{
return diagnostics.Add(node.Location, (IReadOnlyCollection<DiagnosticInfo>)useSiteDiagnostics);
}
return false;
}
internal static bool Add(this DiagnosticBag diagnostics, SyntaxToken token, HashSet<DiagnosticInfo> useSiteDiagnostics)
{
if (!HashSetExtensions.IsNullOrEmpty<DiagnosticInfo>(useSiteDiagnostics))
{
return diagnostics.Add(((SyntaxToken)(ref token)).GetLocation(), (IReadOnlyCollection<DiagnosticInfo>)useSiteDiagnostics);
}
return false;
}
internal static bool Add(this DiagnosticBag diagnostics, Location location, IReadOnlyCollection<DiagnosticInfo> useSiteDiagnostics)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Invalid comparison between Unknown and I4
if (CollectionsExtensions.IsNullOrEmpty<DiagnosticInfo>(useSiteDiagnostics))
{
return false;
}
bool result = false;
foreach (DiagnosticInfo useSiteDiagnostic in useSiteDiagnostics)
{
if ((int)useSiteDiagnostic.Severity == 3)
{
result = true;
}
diagnostics.Add((Diagnostic)(object)new CSDiagnostic(useSiteDiagnostic, location));
}
return result;
}
}