Skip to content

Commit 34aa0bd

Browse files
Enable nullable for file
1 parent d384eaa commit 34aa0bd

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

CodeConverter/Util/ISymbolExtensions.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#nullable enable
12
namespace ICSharpCode.CodeConverter.Util;
23

34
internal static class ISymbolExtensions
@@ -23,7 +24,7 @@ public static bool IsDefinedInSource(this ISymbol symbol)
2324
return symbol.Locations.Any(loc => loc.IsInSource);
2425
}
2526

26-
public static TSymbol ExtractBestMatch<TSymbol>(this SymbolInfo info, Func<TSymbol, bool> isMatch = null) where TSymbol : class, ISymbol
27+
public static TSymbol? ExtractBestMatch<TSymbol>(this SymbolInfo info, Func<TSymbol, bool>? isMatch = null) where TSymbol : class, ISymbol
2728
{
2829
isMatch ??= (_ => true);
2930
if (info.Symbol == null && info.CandidateSymbols.Length == 0)
@@ -38,16 +39,16 @@ public static TSymbol ExtractBestMatch<TSymbol>(this SymbolInfo info, Func<TSymb
3839
return null;
3940
}
4041

41-
public static string ToCSharpDisplayString(this ISymbol symbol, SymbolDisplayFormat format = null)
42+
public static string? ToCSharpDisplayString(this ISymbol symbol, SymbolDisplayFormat? format = null)
4243
{
4344
if (TryGetSpecialVBTypeConversion(symbol, out var cSharpDisplayString)) return cSharpDisplayString;
4445

4546
return symbol.ToDisplayString(format);
4647
}
4748

48-
private static bool TryGetSpecialVBTypeConversion(ISymbol symbol, out string cSharpDisplayString)
49+
private static bool TryGetSpecialVBTypeConversion(ISymbol symbol, out string? cSharpDisplayString)
4950
{
50-
var containingNamespace = symbol?.ContainingNamespace?.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat);
51+
var containingNamespace = symbol.ContainingNamespace?.ToDisplayString(SymbolDisplayFormat.CSharpErrorMessageFormat);
5152
if (containingNamespace == "Microsoft.VisualBasic" || containingNamespace == "System") {
5253
if (symbol is ITypeSymbol && TypesToConvertToDateTime.Contains(symbol.Name)) {
5354
{
@@ -68,28 +69,28 @@ private static bool TryGetSpecialVBTypeConversion(ISymbol symbol, out string cSh
6869
return false;
6970
}
7071

71-
public static bool IsPartialMethodImplementation(this ISymbol declaredSymbol)
72+
public static bool IsPartialMethodImplementation(this ISymbol? declaredSymbol)
7273
{
73-
return declaredSymbol is IMethodSymbol ms && ms.PartialDefinitionPart != null;
74+
return declaredSymbol is IMethodSymbol {PartialDefinitionPart: not null};
7475
}
7576

76-
public static bool CanHaveMethodBody(this ISymbol declaredSymbol)
77+
public static bool CanHaveMethodBody(this ISymbol? declaredSymbol)
7778
{
7879
return declaredSymbol is IMethodSymbol ms && (!ms.IsPartialDefinition && (ms.PartialImplementationPart == null && !ms.IsExtern));
7980
}
8081

81-
public static bool IsPartialMethodDefinition(this ISymbol declaredSymbol)
82+
public static bool IsPartialMethodDefinition(this ISymbol? declaredSymbol)
8283
{
8384
return declaredSymbol is IMethodSymbol ms && (ms.PartialImplementationPart != null || ms.IsPartialDefinition);
8485
}
8586

86-
public static bool IsPartialClassDefinition(this ISymbol declaredSymbol)
87+
public static bool IsPartialClassDefinition(this ISymbol? declaredSymbol)
8788
{
8889
return declaredSymbol is ITypeSymbol ts && (ts.DeclaringSyntaxReferences.Length > 1
8990
|| ts.ContainingAssembly.Name == ForcePartialTypesAssemblyName);
9091
}
9192

92-
public static bool IsReducedTypeParameterMethod(this ISymbol symbol)
93+
public static bool IsReducedTypeParameterMethod(this ISymbol? symbol)
9394
{
9495
return symbol is IMethodSymbol ms && ms.ReducedFrom?.TypeParameters.Length > ms.TypeParameters.Length;
9596
}
@@ -98,5 +99,5 @@ public static bool IsReducedTypeParameterMethod(this ISymbol symbol)
9899
/// Since non value types can't be ref types for extension methods in C#, convert to a static invocation
99100
/// https://github.com/icsharpcode/CodeConverter/issues/785
100101
/// </summary>
101-
public static bool ValidCSharpExtensionMethodParameter(this IParameterSymbol vbSymbol) => vbSymbol != null && (vbSymbol.RefKind != RefKind.Ref || vbSymbol.Type.IsValueType);
102+
public static bool ValidCSharpExtensionMethodParameter(this IParameterSymbol? vbSymbol) => vbSymbol != null && (vbSymbol.RefKind != RefKind.Ref || vbSymbol.Type.IsValueType);
102103
}

0 commit comments

Comments
 (0)