Like most software, users are able to specify how they'd like to handle certain things. In my case, users can specify what kind of formatting they would prefer. There are 3 options, leave unformatted, camel case or proper case. I currently have it working but it feels very clunky and repetitive. Here is a jist of the class.
public static class Extensions
{
public static string GetPreferenceFormattedText(this string text, ApplicationPreferences applicationPreferences, bool pluralize)
{
if (applicationPreferences.FieldNamingConvention.Equals(FieldNamingConvention.SameAsDatabase))
return text;
string formattedText = text.Replace('_', ' ');
formattedText = formattedText.MakeTitleCase();
formattedText = formattedText.Replace(" ", "");
if (applicationPreferences.FieldNamingConvention.Equals(FieldNamingConvention.Prefixed))
return applicationPreferences.Prefix + formattedText;
return applicationPreferences.FieldNamingConvention.Equals(FieldNamingConvention.CamelCase)
? formattedText.MakeFirstCharLowerCase()
: formattedText;
}
}
The method itself doesn't really feel clunky. It's the way it's being called. Always having to pass the user preferences every time I want to obtain the formatted text doesn't seem like the best way to go. Would I be better off making a regular class and pass the application preferences object through the constructor?
Thank you.