Skip to content

Commit

Permalink
Merge pull request #1177 from sharwell/fix-lightup
Browse files Browse the repository at this point in the history
Update ProgrammaticSuppressionInfoWrapper for Roslyn 4.10
  • Loading branch information
sharwell authored Aug 14, 2024
2 parents fd1b713 + 504ead5 commit d0c5cbf
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@ internal readonly struct ProgrammaticSuppressionInfoWrapper
{
internal const string WrappedTypeName = "Microsoft.CodeAnalysis.Diagnostics.ProgrammaticSuppressionInfo";
internal static readonly Type? WrappedType = typeof(Diagnostic).GetTypeInfo().Assembly.GetType(WrappedTypeName);
private static readonly Func<object, ImmutableHashSet<(string id, LocalizableString justification)>> s_suppressions;
private static readonly Func<object, object> s_suppressions;

private readonly object _instance;

static ProgrammaticSuppressionInfoWrapper()
{
s_suppressions = LightupHelpers.CreatePropertyAccessor<object, ImmutableHashSet<(string id, LocalizableString justification)>>(WrappedType, nameof(Suppressions), ImmutableHashSet<(string id, LocalizableString justification)>.Empty);
s_suppressions = LightupHelpers.CreatePropertyAccessor<object, object>(WrappedType, nameof(Suppressions), ImmutableHashSet<(string id, LocalizableString justification)>.Empty);
}

private ProgrammaticSuppressionInfoWrapper(object instance)
{
_instance = instance;
}

public ImmutableHashSet<(string id, LocalizableString justification)> Suppressions => s_suppressions(_instance);
public ImmutableHashSet<(string id, LocalizableString justification)> Suppressions
{
get
{
var suppressions = s_suppressions(_instance);
if (suppressions is ImmutableHashSet<(string id, LocalizableString justification)> set)
{
return set;
}

// https://github.com/dotnet/roslyn-sdk/issues/1175
throw new NotImplementedException("The test framework does not yet support suppressions format from Roslyn 4.10+");
}
}

public static ProgrammaticSuppressionInfoWrapper FromInstance(object instance)
{
Expand Down

0 comments on commit d0c5cbf

Please sign in to comment.