Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a model Class with fixed prefix

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading