11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33
4- using System ;
54using System . Collections . Immutable ;
65using System . Linq ;
76using Microsoft . AspNetCore . Analyzers . RouteEmbeddedLanguage . Infrastructure ;
@@ -22,13 +21,8 @@ public static bool IsEnumerable(this ITypeSymbol type, INamedTypeSymbol enumerab
2221 return type . ImplementsInterface ( enumerable ) || SymbolEqualityComparer . Default . Equals ( type , enumerable ) ;
2322 }
2423
25- public static bool ImplementsValidationAttribute ( this ITypeSymbol typeSymbol , INamedTypeSymbol ? validationAttributeSymbol )
24+ public static bool ImplementsValidationAttribute ( this ITypeSymbol typeSymbol , INamedTypeSymbol validationAttributeSymbol )
2625 {
27- if ( validationAttributeSymbol is null )
28- {
29- return false ;
30- }
31-
3226 var baseType = typeSymbol . BaseType ;
3327 while ( baseType != null )
3428 {
@@ -42,9 +36,8 @@ public static bool ImplementsValidationAttribute(this ITypeSymbol typeSymbol, IN
4236 return false ;
4337 }
4438
45- public static ITypeSymbol UnwrapType ( this ITypeSymbol type , INamedTypeSymbol ? enumerable )
39+ public static ITypeSymbol UnwrapType ( this ITypeSymbol type , INamedTypeSymbol enumerable )
4640 {
47-
4841 if ( type . OriginalDefinition . SpecialType == SpecialType . System_Nullable_T &&
4942 type is INamedTypeSymbol { TypeArguments . Length : 1 } )
5043 {
@@ -59,11 +52,6 @@ public static ITypeSymbol UnwrapType(this ITypeSymbol type, INamedTypeSymbol? en
5952 type = type . WithNullableAnnotation ( NullableAnnotation . NotAnnotated ) ;
6053 }
6154
62- if ( enumerable is null )
63- {
64- return type ;
65- }
66-
6755 if ( type is INamedTypeSymbol namedType && namedType . IsEnumerable ( enumerable ) && namedType . TypeArguments . Length == 1 )
6856 {
6957 // Extract the T from an IEnumerable<T> or List<T>
@@ -73,13 +61,8 @@ public static ITypeSymbol UnwrapType(this ITypeSymbol type, INamedTypeSymbol? en
7361 return type ;
7462 }
7563
76- internal static bool ImplementsInterface ( this ITypeSymbol type , ITypeSymbol ? interfaceType )
64+ internal static bool ImplementsInterface ( this ITypeSymbol type , ITypeSymbol interfaceType )
7765 {
78- if ( interfaceType is null )
79- {
80- return false ;
81- }
82-
8366 foreach ( var iface in type . AllInterfaces )
8467 {
8568 if ( SymbolEqualityComparer . Default . Equals ( interfaceType , iface ) )
@@ -90,13 +73,8 @@ internal static bool ImplementsInterface(this ITypeSymbol type, ITypeSymbol? int
9073 return false ;
9174 }
9275
93- internal static ImmutableArray < INamedTypeSymbol > ? GetJsonDerivedTypes ( this ITypeSymbol type , INamedTypeSymbol ? jsonDerivedTypeAttribute )
76+ internal static ImmutableArray < INamedTypeSymbol > ? GetJsonDerivedTypes ( this ITypeSymbol type , INamedTypeSymbol jsonDerivedTypeAttribute )
9477 {
95- if ( jsonDerivedTypeAttribute is null )
96- {
97- return null ;
98- }
99-
10078 var derivedTypes = ImmutableArray . CreateBuilder < INamedTypeSymbol > ( ) ;
10179 foreach ( var attribute in type . GetAttributes ( ) )
10280 {
@@ -117,23 +95,15 @@ internal static bool ImplementsInterface(this ITypeSymbol type, ITypeSymbol? int
11795 // types themselves so we short-circuit on them.
11896 internal static bool IsExemptType ( this ITypeSymbol type , WellKnownTypes wellKnownTypes )
11997 {
120- try
121- {
122- return SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_HttpContext ) )
123- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_HttpRequest ) )
124- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_HttpResponse ) )
125- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . System_Threading_CancellationToken ) )
126- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_IFormCollection ) )
127- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_IFormFileCollection ) )
128- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_IFormFile ) )
129- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . System_IO_Stream ) )
130- || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . System_IO_Pipelines_PipeReader ) ) ;
131-
132- }
133- catch ( InvalidOperationException )
134- {
135- return false ;
136- }
98+ return SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_HttpContext ) )
99+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_HttpRequest ) )
100+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_HttpResponse ) )
101+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . System_Threading_CancellationToken ) )
102+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_IFormCollection ) )
103+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_IFormFileCollection ) )
104+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . Microsoft_AspNetCore_Http_IFormFile ) )
105+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . System_IO_Stream ) )
106+ || SymbolEqualityComparer . Default . Equals ( type , wellKnownTypes . Get ( WellKnownTypeData . WellKnownType . System_IO_Pipelines_PipeReader ) ) ;
137107 }
138108
139109 internal static IPropertySymbol ? FindPropertyIncludingBaseTypes ( this INamedTypeSymbol typeSymbol , string propertyName )
@@ -162,13 +132,8 @@ internal static bool IsExemptType(this ITypeSymbol type, WellKnownTypes wellKnow
162132 /// <param name="parameter">The parameter to check.</param>
163133 /// <param name="fromServiceMetadataSymbol">The symbol representing the [FromService] attribute.</param>
164134 /// <param name="fromKeyedServiceAttributeSymbol">The symbol representing the [FromKeyedService] attribute.</param>
165- internal static bool IsServiceParameter ( this IParameterSymbol parameter , INamedTypeSymbol ? fromServiceMetadataSymbol , INamedTypeSymbol ? fromKeyedServiceAttributeSymbol )
135+ internal static bool IsServiceParameter ( this IParameterSymbol parameter , INamedTypeSymbol fromServiceMetadataSymbol , INamedTypeSymbol fromKeyedServiceAttributeSymbol )
166136 {
167- if ( fromServiceMetadataSymbol is null || fromKeyedServiceAttributeSymbol is null )
168- {
169- return false ;
170- }
171-
172137 return parameter . GetAttributes ( ) . Any ( attr =>
173138 attr . AttributeClass is not null &&
174139 ( attr . AttributeClass . ImplementsInterface ( fromServiceMetadataSymbol ) ||
@@ -181,7 +146,7 @@ attr.AttributeClass is not null &&
181146 /// <param name="property">The property to check.</param>
182147 /// <param name="fromServiceMetadataSymbol">The symbol representing the [FromServices] attribute.</param>
183148 /// <param name="fromKeyedServiceAttributeSymbol">The symbol representing the [FromKeyedServices] attribute.</param>
184- internal static bool IsServiceProperty ( this IPropertySymbol property , INamedTypeSymbol ? fromServiceMetadataSymbol , INamedTypeSymbol ? fromKeyedServiceAttributeSymbol )
149+ internal static bool IsServiceProperty ( this IPropertySymbol property , INamedTypeSymbol fromServiceMetadataSymbol , INamedTypeSymbol fromKeyedServiceAttributeSymbol )
185150 {
186151 if ( fromServiceMetadataSymbol is null || fromKeyedServiceAttributeSymbol is null )
187152 {
@@ -199,29 +164,19 @@ attr.AttributeClass is not null &&
199164 /// </summary>
200165 /// <param name="property">The property to check.</param>
201166 /// <param name="jsonIgnoreAttributeSymbol">The symbol representing the [JsonIgnore] attribute.</param>
202- internal static bool IsJsonIgnoredProperty ( this IPropertySymbol property , INamedTypeSymbol ? jsonIgnoreAttributeSymbol )
167+ internal static bool IsJsonIgnoredProperty ( this IPropertySymbol property , INamedTypeSymbol jsonIgnoreAttributeSymbol )
203168 {
204- if ( jsonIgnoreAttributeSymbol is null )
205- {
206- return false ;
207- }
208-
209169 return property . GetAttributes ( ) . Any ( attr =>
210170 attr . AttributeClass is not null &&
211171 SymbolEqualityComparer . Default . Equals ( attr . AttributeClass , jsonIgnoreAttributeSymbol ) ) ;
212172 }
213173
214- internal static bool IsSkippedValidationProperty ( this IPropertySymbol property , INamedTypeSymbol ? skipValidationAttributeSymbol )
174+ internal static bool IsSkippedValidationProperty ( this IPropertySymbol property , INamedTypeSymbol skipValidationAttributeSymbol )
215175 {
216- if ( skipValidationAttributeSymbol is null )
217- {
218- return false ;
219- }
220-
221176 return property . HasAttribute ( skipValidationAttributeSymbol ) || property . Type . HasAttribute ( skipValidationAttributeSymbol ) ;
222177 }
223178
224- internal static bool IsSkippedValidationParameter ( this IParameterSymbol parameter , INamedTypeSymbol ? skipValidationAttributeSymbol )
179+ internal static bool IsSkippedValidationParameter ( this IParameterSymbol parameter , INamedTypeSymbol skipValidationAttributeSymbol )
225180 {
226181 return parameter . HasAttribute ( skipValidationAttributeSymbol ) || parameter . Type . HasAttribute ( skipValidationAttributeSymbol ) ;
227182 }
0 commit comments