![](/img/trans.png)
[英]Roslyn VisitArgumentList and VisitArgument how do I get the comma trivia?
[英]How do I get the Kind of Elements in an Array using Roslyn
我正在嘗試使用Roslyn來獲得迭代的Type。 我可以使用以下事實將對象定義為String()
Dim ElementTypeInfo As TypeInfo = SemanticModel.GetTypeInfo(ForEachStatement.Expression)
Dim expressionType As ITypeSymbol = ElementTypeInfo.Type
在Visual Studio調試器中,我可以查看expressionType.ElementType並找出它是一個String。 但是,當我嘗試在代碼中訪問ElementType時,出現錯誤,指出ElementType不是ITypeSymbol的成員。
如果知道expressionType
將是一個數組,則可以將其IArrayTypeSymbol
為IArrayTypeSymbol
。 之后,您將可以訪問其ElementType
:
Dim expressionType = DirectCast(elementTypeInfo.Type, IArrayTypeSymbol)
Dim elementType As ITypeSymbol = expressionType.ElementType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.