Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Add Roslyn Analyser to detect common problems #45

Description

@adam-resdiary

We can potentially create Roslyn Analysers to detect common issues when people are using the runtime library or generated code. Examples of problems we can detect are:

  • Returning null from a service method.
  • Throwing an exception that isn't part of the service method definition.

To illustrate this, let's take the example of returning null from a service method. Thrift doesn't support null return results from service methods, and has no way to serialise that. So if someone writes the following code:

public async Task<User> GetUser(int userId)
{
    var user = this.userRepository.GetById(userId);

    if (user != null)
    {
        return this.mapper.Map<User>(user);
    }

    return null;
           ^^^^
}

We can report an error when returning null since we know that it isn't a valid return result.

An example of a project that provides analysers like this is xUnit. It can detect problems like Theories not having the correct parameters passed to them at compile time, something that would typically cause a runtime error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/epicUsed to describe a larger chunk of work that will need to be broken down into further tasks

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions