I am facing a problem of scalability with a big Enum file, which has more than 1700 records.
I have to add more records to this Enum, and I am thinking to create a new Enum file to avoid adding more bloat the existing one. This allows as well to separate the Enum type by domain.
The problem is that this does not work, I have to change or duplicate or cast every function that takes this Enum type when I call the function in my new code.
This old Enum file has been created and updated manually overtime, it is not generated from a database. The project has a very very long age (probably 15+ years).
What can be a solution?
namespace SomeNameSpace
{
public enum OldBigListDoneBySomeIrresponsiveDev
{
[FriendlyName("Unknown")]
Unknown = 0,
[FriendlyName("Page1")]
Page1_Summary = 100000,
[FriendlyName("Page2")]
Page2_Summary = 100101,
[FriendlyName("Page3")]
Page3_Summary = 100102,
// .....
Page1700_Summary = 107102,
}
}
namespace SomeNameSpace2
{
public class SomeAttribute: FilterAttribute
{
public CheckEnumAttributeAttribute()
{
this.Order = 0;
}
/// <summary>
/// Gets or sets the OldBigListDoneBySomeIrresponsiveDev
/// </summary>
public OldBigListDoneBySomeIrresponsiveDev AttrID { get; set; }
}
}
// attempt to improve
namespace SomeNameSpace
{
public enum SmallerNicerEnumList
{
[FriendlyName("Unknown")]
Unknown = 0,
[FriendlyName("Page2000")]
Page2000_Summary = 100000,
[FriendlyName("Page2001")]
Page2001_Summary = 100101,
[FriendlyName("Page2002")]
Page2002_Summary = 100102,
}
}
// tenative usage of the attribute with new Enum
SomeAttribute(AttrID = SmallerNicerEnumList.Page2000_Summary)
public void SomeController(){}
Raises error: Cannot implicity convert type from SmallerNicerEnumList to OldBigListDoneBySomeIrresponsiveDev
You can convert the
enumto arecordand use therecordinstead, which can be madepartial, it can also be extended withimplicitand the like to make it work like anenum.Here is a code example of a console app: