Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:47:54+00:00 2026-06-01T18:47:54+00:00

Using Microsoft Roslyn I am trying to determine if a methods return type is

  • 0

Using Microsoft Roslyn I am trying to determine if a methods return type is void.
I have the handle on my MethodDeclarationSyntax and can see the property Called "ReturnType" this is a PredefinedType of void. Do I have to actually check the keyword kind? Is there a better way to do this?

((PredefinedTypeSyntax)methodDec.ReturnType).Keyword.Kind() != SyntaxKind.VoidKeyword

Is there a recommended method of accomplishing what I am trying to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:47:55+00:00Added an answer on June 1, 2026 at 6:47 pm

    For void, that’s perfect, since there’s no other way to say it. Saying System.Void is explicitly prohibited there.

    For other predefined types like int, keep in mind that you can write it either with the keyword or with the .NET type System.Int32. Depending on your scenario, you might actually care to distinguish between them, and so the syntactic check would still be correct. If you don’t care about the difference and just want to know if it’s an integer, you should then do some binding with a SemanticModel:

    var methodSymbol = (MethodSymbol)semanticModel.GetDeclaredSymbol(methodDecl);
    if (methodSymbol.ReturnType.SpecialType == SpecialType.System_Int32)
    {
        /* ...whatever goes here */
    }
    

    MethodSymbol also has a ReturnsVoid property which you might find useful if you happen to have the symbol for it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Microsoft Visual Studio 2010: Can I write this type of macro in C?
Using Microsoft Spy++, I can see that the following windows that belong to a
Using Microsoft SQL server 2008 I have a query that is in need of
I'm using Microsoft Sync framework 1.0 (without ADO.NET services) I have created 2 custom
I am using Microsoft SQL Server. I have a Table which had been updated
Using Microsoft SQL Server 2005 - wondering how can I escape parenthesis in my
I'm using microsoft SQL server management studio 2005 I'm trying to run a job
We have been using Microsoft Enterprise Lib for data access, some old legacy code
Using Microsoft SQL Server Management Studio, I have created a view, which pulls in
I'm using Microsoft Visual Basic 2008 Express Edition. I have a Folder Dialog Browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.