dimanche 19 juillet 2020

A better way instead of a switch case

Consider the code snippet :

switch (sectionType)
        {
            case "CategoryConfig":
                maxSize = config.Value.FileUploadConfig.CategoryConfig.MaxSize;
                break;
            case "SpecialShowConfig":
                 maxSize = config.Value.FileUploadConfig.SpecialShowConfig.MaxSize;
                break;
            case "BrandConfig":
                maxSize = config.Value.FileUploadConfig.BrandConfig.MaxSize;
                break;
           case " ...."
                break;   ,....
        }

How can I implement the same thing using A better way instead of a switch case ?

Something like this:

config.Value.FileUploadConfig."sectionType".MaxSize

I also use config to access the json file which is for site settings

IOptions <AppConfig> config




Aucun commentaire:

Enregistrer un commentaire