Type can be moved to separate file
- 2 minutes to read
CodeRush Classic shows the Type can be moved to separate file code issue if a file contains more then one type of declarations.
The code issue highlights declarations of the types whose names differ from the file name, provided that the file contains more than one type of a declaration.
#Fix
Move the type declaration to separate files.
#Purpose
Highlights the type declarations, which can be moved to a separate file to improve code readability and simplify working with types.
#Example
//PluginManager.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);
}
}
public class │PluginInfo
{
public PluginInfo(string name, string path, bool enabled)
{
Name = name;
Path = path;
Enabled = enabled;
}
public string Name { get; set; }
public string Path { get; set; }
public bool Enabled { get; set; }
}
}
Fix:
//PluginManager.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);
}
}
}
//PluginInfo.cs
using System;
using System.Collections.Generic;
namespace MySolution
{
public class PluginInfo
{
public PluginInfo(string name, string path, bool enabled)
{
Name = name;
Path = path;
Enabled = enabled;
}
public string Name { get; set; }
public string Path { get; set; }
public bool Enabled { get; set; }
}
}