What is the correct way to replace type nodes

The plugin I am upgrading converts to and from alias/clr type names. The previous version replaced IDeclaredTypeUsageNode, ITypeUsageNode, IReferenceExpressionNode and IPredefinedTypeExpressionNode nodes. This was really clunky especially when generic types were involved.

In my latest code base, I have found that all these have an ITokenNode as a child which seems to be core reference to the type name. My code successfully replaces the internal ITokenNode (int with Int32 for example) for each applicable node, but it seems to make the node tree a little invalid. For example, IMethodDeclaration.TypeUsage throws an exception when public static bool DoSomething() is replaced with public static Boolean DoSomething.

Do I need to go back to handling all those higher level node types or is there an appropriate way to replace the lower level ITokenNode references without causes node tree failures?

1 comment
Comment actions Permalink

Yes, you cannot replace the contents of the IPredefinedTypeUsageNode since it has dedicated semantics.  To achieve your goal, you should replace the whole IPredefinedTypeUsageNody by ITypeUsageNode. To create it, use CSharpElementFactory.GetInstance(...).CreateTypeUsageNode(...) method


Please sign in to leave a comment.