Skip to content

Commit

Permalink
修复 对象数组 作为参数时,SimplifyNameByAddUsing 方法中typeSymbol.ContainingNamespac…
Browse files Browse the repository at this point in the history
…e.ToString() 空指针异常.
  • Loading branch information
cruz committed Oct 28, 2022
1 parent 4eda4a1 commit 3711e1e
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public SourceTextBuilder AddUsingForTypes(params ITypeSymbol[] typeSymbols)
public string SimplifyNameByAddUsing(ITypeSymbol typeSymbol)
{
var originalName = typeSymbol.ToString();
var @namespace = typeSymbol.ContainingNamespace.ToString();
var @namespace = typeSymbol.ContainingNamespace?.ToString();
if (@namespace == null)
{
return originalName;
}
if (originalName.StartsWith(@namespace, StringComparison.Ordinal))
{
// 常规类型,“命名空间.类名”型。
Expand Down

0 comments on commit 3711e1e

Please sign in to comment.