Using EnvDTE in a T4 template I can get all methods from a class easily.

Taking it a step further and looping those methods to get the return type as a CodeClass2 (or simply CodeElement2) I get stuck.

((CodeFunction2)codeElement).Type.AsFullName;

This code works fine getting the return type full name, but if I try this;

((CodeFunction2)codeElement).Type as CodeClass2;

I get a null value everytime, even though returning the AsFullName works?

I ultimately need to loop the properties of a functions return type object, but failing miserably at this point.

有帮助吗?

解决方案

Looking at the documentation CodeFunction2.Type returns a CodeTypeRef.

So you should be able to use:

((CodeFunction2)codeElement).Type.CodeType as CodeClass2;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top