0

在类型的正常比较中 typeof(nint)==typeof(System.IntPtr)是真的

所以我期待SpecialTypeofSystem.IntPtr就像andnint一样,在使用 进行 CodeAnalysis 时。System.Int32intMicrosoft.CodeAnalysis

但事实证明 System.IntPtr 的 SpecialType 仍然是 System.IntPtr。

这是我的代码

string GetSpecialTypeForDisplayIfAny(ISymbol symbol)
{
   return symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat
            .WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted)
            .AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier)
            .AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.UseSpecialTypes)
            .AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier)
            .AddMiscellaneousOptions(SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier))
);
}

所以我的问题是为什么特殊类型System.IntPtr不在nintCodeAnalysis 中?

PS。我已经浏览了这个文档。我知道“..关键字不仅仅是类型的别名。” 但为什么这是真的typeof(nint)==typeof(System.IntPtr)呢?

4

0 回答 0