|
| 1 | +using Microsoft.CodeAnalysis; |
| 2 | +using System; |
| 3 | +using System.Collections; |
| 4 | +using System.Collections.Generic; |
| 5 | + |
| 6 | +namespace FluentAssertions.Analyzers.Utilities |
| 7 | +{ |
| 8 | + internal static class SemanticModelTypeExtensions |
| 9 | + { |
| 10 | + public static INamedTypeSymbol GetActionType(this SemanticModel semanticModel) |
| 11 | + => GetTypeFrom(semanticModel, typeof(Action)); |
| 12 | + |
| 13 | + public static INamedTypeSymbol GetGenericIEnumerableType(this SemanticModel semanticModel) |
| 14 | + => GetTypeFrom(semanticModel, SpecialType.System_Collections_Generic_IEnumerable_T); |
| 15 | + |
| 16 | + public static INamedTypeSymbol GetIEnumerableType(this SemanticModel semanticModel) |
| 17 | + => GetTypeFrom(semanticModel, SpecialType.System_Collections_IEnumerable); |
| 18 | + |
| 19 | + public static INamedTypeSymbol GetIDictionaryType(this SemanticModel semanticModel) |
| 20 | + => GetTypeFrom(semanticModel, typeof(IDictionary)); |
| 21 | + |
| 22 | + public static INamedTypeSymbol GetGenericIDictionaryType(this SemanticModel semanticModel) |
| 23 | + => GetTypeFrom(semanticModel, typeof(IDictionary<,>)); |
| 24 | + |
| 25 | + public static INamedTypeSymbol GetIReadOnlyDictionaryType(this SemanticModel semanticModel) |
| 26 | + => GetTypeFrom(semanticModel, typeof(IReadOnlyDictionary<,>)); |
| 27 | + |
| 28 | + private static INamedTypeSymbol GetTypeFrom(SemanticModel semanticModel, Type type) |
| 29 | + => semanticModel.Compilation.GetTypeByMetadataName(type.FullName); |
| 30 | + |
| 31 | + private static INamedTypeSymbol GetTypeFrom(SemanticModel semanticModel, SpecialType type) |
| 32 | + => semanticModel.Compilation.GetSpecialType(type); |
| 33 | + } |
| 34 | +} |
0 commit comments