I am curious about the best C# practice for the following scenario:
I have a class called Platform
which contains a constructor that allows for a single argument called platformName
. I would like to create an instance of an object that populates the instance with properties related to that variable name. For example...I want to create an instance of a class like so:
var spotify = new Platform("PlatformName_Spotify");
When this is instantiated, it sets properties related to Spotify (such as its brand color, its slogan, and monthly users) so that I can access them like:
spotify.color or spotify.slogan or spotify.monthlyUsers
Is it best to make dictionaries of each brand inside the Platform
class and then assign the dictionary to the matching variable name that is passed? This is what I came up with, but I feel like there has to be a better way! How would you accomplish this?
public class Platform
{
private readonly Dictionary<string, string> spotify = new Dictionary<string, string>
{
{ "color", "green" },
{ "slogan", "Music For Everyone" },
{ "monthlyUsers", "14M" }
};
private readonly string color;
private readonly string slogan;
private readonly string monthlyUsers;
public Platform(string platformName)
{
if(platformName == "PlatformName_Spotify")
{
this.color = spotify["color"];
this.slogan = spotify["slogan"];
this.monthlyUsers = spotify["monthlyUsers"];
}
}
}