How to get System.Type from PropertyDeclaration.ReturnType?

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 11 years ago by Mitch Blake
Let's say you have the following text (C#):
using System;
...other using statements...

public class MyClass
TimeSpan myTimeSpanField

If you are editing this doc in the SyntaxEditor, you can hover over "TimeSpan" in the property declaration and the tooptip says "System.TimeSpan". So, the editor knows how to get the full name of the type. If you comment out the "using System" line, the tooltip won't show. That's all as expected.

Now, in code, I have a PropertyDeclaration object. The PropertyDeclaration.ReturnType.Name is "TimeSpan". How can I resolve that ReturnType to the fully qualified type name "System.TimeSpan" in the same way that is used to display the tooltip when editing (I'd like it to resolve the same way so that I get the same answer as when editing the doc in the editor).

Any help is appreciated.

Thanks - Mitch

Comments (3)

Posted 11 years ago by Mitch Blake
Rarely do I get to answer my own question :)

IDomType domType = propertyDeclaration.ReturnType.Resolve(MyProjectResolver);

string fullName = domType.FullName;

That will set fullName to "System.TimeSpan".

[Modified at 05/09/2008 02:50 PM]
Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Mitch,

Correct, resolving the type reference is what you want to do like that. Just be sure to do a null check on the domType in case it wasn't able to be resolved.

Actipro Software Support

Posted 11 years ago by Mitch Blake
Thanks! Good point... added a check for null.
The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.