Skip to main content

CRR0048 - The type name does not correspond to the file name

  • 2 minutes to read

This analyzer identifies types whose names should be adjusted in accordance with the file names to improve readability and simplify work with types.

//Manager.cs

using System;
using System.Collections.Generic;

namespace MySolution
{
    public class PluginManager
    {
        public List<PluginInfo> Plugins { get; private set; }
        public void AddPlugin(PluginInfo plugin)
        {
            if (Plugins == null)
                Plugins = new List<PluginInfo>();
            Plugins.Add(plugin);
        }
    }
}

To fix the issue, rename the file or the type to adjust them in accordance with each other:

//Manager.cs

using System;
using System.Collections.Generic;

namespace MySolution
{
    public class Manager
    {
        public List<PluginInfo> Plugins { get; private set; }
        public void AddPlugin(PluginInfo plugin)
        {
            if (Plugins == null)
                Plugins = new List<PluginInfo>();
            Plugins.Add(plugin);
        }
    }
}

Call the Rename Type to Match File or Rename File to Match Type refactoring to adjust the file and type in accordance with each other.