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 3977212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:53:48+00:00 2026-05-20T04:53:48+00:00

Check out the following code: private void Foo(object bar) { Type type = bar.GetType();

  • 0

Check out the following code:

private void Foo(object bar)
{
   Type type = bar.GetType();

    if (type != null) // Expression is always true
    {   
    }
}

ReSharper claims type will never be null. That’s obvious to me because there’s always going to be a type for bar, but how does ReSharper know that? How can it know that the result of a method will never be null?

Type is not a struct so it can’t be that. And if the method were written by me, then the return value could certainly be null (not necessarily GetType, but something else).

Is ReSharper clever enough to know that, for only that particular method, the result will never be null? (Like there’s a hard-coded list of known .NET methods which will never return null.)

  • 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-05-20T04:53:49+00:00Added an answer on May 20, 2026 at 4:53 am

    JetBrains perfectly explains how ReSharper does this in their features list.

    Summary from link (this particular question is about NotNullAttribute):

    We have analyzed a great share of .NET Framework Class Library, as well as NUnit Framework, and annotated it through external XML files, using a set of custom attributes from the JetBrains.Annotations namespace, specifically:

    StringFormatMethodAttribute (for methods that take format strings as parameters)
    InvokerParameterNameAttribute (for methods with string literal arguments that should match one of caller parameters)
    AssertionMethodAttribute (for assertion methods)
    AssertionConditionAttribute (for condition parameters of assertion methods)
    TerminatesProgramAttribute (for methods that terminate control flow)
    CanBeNullAttribute (for values that can be null)
    NotNullAttribute (for values that can not be null)
    UsedImplicitlyAttribute (for entities that should not be marked as unused)
    MeansImplicitUseAttribute (for extending semantics of any other attribute to mean that the corresponding entity should not be marked as unused)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my App.xaml.cs private void App_Start(object sender, StartupEventArgs e)
The following code throws an exception... private void EnsureDiskSpace() { using (IsolatedStorageFile file =
Check out this test: [TestFixture] public class Quick_test { [Test] public void Test() {
First check out this code. I seems like it should work for me, but
If I check out a tagged version of my source code without creating a
I'm using the following code to check if a valid date has been typed
I have the following code that will check to see if the div text
I have put the following code in my head to check the session: <script
I'm using the following code to log users of an application out: session_start(); setcookie
Hey, if you have got the following code and want to check if $key

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.