0

I am trying to get the Type that is iterated through using Roslyn. I can get the fact that the object is defined as String() using

  Dim ElementTypeInfo As TypeInfo = SemanticModel.GetTypeInfo(ForEachStatement.Expression)
  Dim expressionType As ITypeSymbol = ElementTypeInfo.Type

and in the Visual Studio debugger I can look at expressionType.ElementType and find out it is a String. But when I try to access ElementType in code I get an error saying the ElementType is not a member of ITypeSymbol.

Paul Cohen
  • 241
  • 4
  • 14
  • `Dim expressionType As ITypeSymbol` is where you're going wrong? If so, then don't declare it as such. – Ally Mar 25 '17 at 08:43

1 Answers1

1

If you know that expressionType is going to be an array, you can cast it to IArrayTypeSymbol. After that, you will be able to access its ElementType:

Dim expressionType = DirectCast(elementTypeInfo.Type, IArrayTypeSymbol)
Dim elementType As ITypeSymbol = expressionType.ElementType
svick
  • 236,525
  • 50
  • 385
  • 514