Skip to content

Commit 0b74ba9

Browse files
Don't require the Convert type
1 parent dd98e10 commit 0b74ba9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

CodeConverter/CSharp/ExpressionNodeVisitor.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ private static Dictionary<ITypeSymbol, string> CreateConvertMethodsLookupByRetur
5858
SemanticModel semanticModel)
5959
{
6060
// In some projects there's a source declaration as well as the referenced one, which causes the first of these methods to fail
61+
var symbolsWithName = semanticModel.Compilation
62+
.GetSymbolsWithName(n => n.Equals(ConvertType.Name, StringComparison.Ordinal), SymbolFilter.Type).ToList();
63+
6164
var convertType =
6265
semanticModel.Compilation.GetTypeByMetadataName(ConvertType.FullName) ??
63-
(ITypeSymbol)semanticModel.Compilation
64-
.GetSymbolsWithName(n => n.Equals(ConvertType.Name, StringComparison.Ordinal), SymbolFilter.Type).First(s =>
66+
(ITypeSymbol)symbolsWithName.FirstOrDefault(s =>
6567
s.ContainingNamespace.ToDisplayString().Equals(ConvertType.Namespace, StringComparison.Ordinal));
6668

69+
if (convertType is null) return new Dictionary<ITypeSymbol, string>();
70+
6771
var convertMethods = convertType.GetMembers().Where(m =>
6872
m.Name.StartsWith("To", StringComparison.Ordinal) && m.GetParameters().Length == 1);
6973
var methodsByType = convertMethods

0 commit comments

Comments
 (0)