-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into split-params-docs
- Loading branch information
Showing
5 changed files
with
76 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
static class Extensions | ||
{ | ||
public static string GetTypeNameWithGenericParameters(this TypeDeclarationSyntax syntax) => | ||
syntax.Identifier.ToString() + syntax.TypeParameterList; | ||
|
||
public static IEnumerable<INamedTypeSymbol> GetBaseTypes(this ITypeSymbol symbol) | ||
{ | ||
var baseType = symbol.BaseType; | ||
|
||
while (baseType is not null) | ||
{ | ||
yield return baseType; | ||
baseType = baseType.BaseType; | ||
} | ||
} | ||
|
||
public static IncrementalValuesProvider<TSource> WhereNotNull<TSource>(this IncrementalValuesProvider<TSource?> source) where TSource : struct => | ||
source | ||
.Where(_ => _.HasValue) | ||
.Select((item, _) => item!.Value); | ||
|
||
public static bool HasAttributeOfType(this ISymbol symbol, string fullyQualifiedAttributeName, bool includeDerived) | ||
{ | ||
foreach (var attribute in symbol.GetAttributes()) | ||
{ | ||
var typeSymbol = attribute.AttributeClass; | ||
while (typeSymbol is not null) | ||
{ | ||
if (typeSymbol.ToDisplayString() == fullyQualifiedAttributeName) | ||
{ | ||
return true; | ||
} | ||
|
||
if (includeDerived) | ||
{ | ||
typeSymbol = typeSymbol.BaseType; | ||
continue; | ||
} | ||
|
||
typeSymbol = null; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static string? GetNamespaceOrDefault(this ISymbol symbol) | ||
{ | ||
var ns = symbol.ContainingNamespace; | ||
if (ns.IsGlobalNamespace) | ||
{ | ||
return null; | ||
} | ||
|
||
return ns.ToString(); | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/Verify.MSTest.SourceGenerator/IncrementalValuesProviderExtensions.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters