CodeSOD: Vestigial Organs

This post was originally published on this site

The Daily WTF

Matt inherited some C# code that reads from a JSON config file.

public ServerJsonLoader(string configFile) { using (StreamReader reader = File.OpenText(configFile)) { JObject config = … //snip if (config.GetValue(“inputs”) != null) { this.mixedConfig = config; //Inputs var inputs = … //snip //Outputs if (config.GetValue(“outputs”) != null) { var outputs = … //snip } } else { if(config.GetValue(“inputs”) != null) this.serverConfig = config; if (config.GetValue(“outputs”) != null) this.clientConfig = config; } } }

We open the file as a stream, and then hand it off to a JObject, which handles the parsing for us. Then, if it has a value “inputs”, we store the config as mixedConfig, and handle the inputs. Then, if it also has “outputs”, we also process the outputs.

If we don’t have an “inputs”, we go down the else path, where we check: if we have “inputs”, we store the config in serverConfig, and if we

To read the full article click on the 'post' link at the top.