Downgrade target Roslyn version in analyzers

Closes #135
This commit is contained in:
Tyrrrz
2023-04-28 17:02:50 +03:00
parent eff84fd7ae
commit 83c7af72bf
12 changed files with 24 additions and 12 deletions

View File

@@ -34,6 +34,17 @@ internal static class RoslynExtensions
.FirstOrDefault(i => i.ConstructedFrom.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T)?
.TypeArguments[0];
// Detect if the property is required through roundabout means so as to not have to take dependency
// on higher versions of the C# compiler.
public static bool IsRequired(this IPropertySymbol property) => property
// Can't rely on the RequiredMemberAttribute because it's generated by the compiler, not added by the user,
// so we have to check for the presence of the `required` modifier in the syntax tree instead.
.DeclaringSyntaxReferences
.Select(r => r.GetSyntax())
.OfType<PropertyDeclarationSyntax>()
.SelectMany(p => p.Modifiers)
.Any(m => m.IsKind((SyntaxKind)8447));
public static bool IsAssignable(this Compilation compilation, ITypeSymbol source, ITypeSymbol destination) =>
compilation.ClassifyConversion(source, destination).Exists;