I have a dotnet core application. I added model class everytime with fixed prefix. It goes very lengthy and unhandled way. Is there any better way to handle this?
public class Category
{
public string? gmailIN{ get; set; }
public string? aolIN{ get; set; }
public string? outlookIN{ get; set; }
public string? yahooIN{ get; set; }
public string? hotmailIN{ get; set; }
public string? ZohoIN; set; }
public string? aolAU{ get; set; }
public string? outlookAU{ get; set; }
public string? yahooAU{ get; set; }
public string? hotmailAU{ get; set; }
public string? ZohoAU{get; set; }
public string? gmailAU{ get; set; }
public string? aolUK{ get; set; }
public string? outlookUK{ get; set; }
public string? yahooUK{ get; set; }
public string? hotmailUK{ get; set; }
public string? ZohoUK{get; set; }
public string? gmailUK{ get; set; }
public string? gmailUS{ get; set; }
public string? aolUS{ get; set; }
public string? outlookUS{ get; set; }
public string? yahooUS{ get; set; }
public string? hotmailUS{ get; set; }
public string? ZohoU{get; set; }
}
Prefix is always the same. Is there any better way to add variables instead of adding above way?
CodePudding user response:
If possible split Category and Country.
You can create a class like:
public class Category
{
public string? gmail{ get; set; }
public string? aol{ get; set; }
public string? outlook{ get; set; }
public string? yahoo{ get; set; }
public string? hotmail{ get; set; }
public string? Zoho{get; set; }
}
and then one Dictionary for mapping it with country
public Dictionary<string,Category> Categories;
or add the Country property inside the Category class itself.