I am creating a converter for use in a Windows 8 XAML app (MVVM). As you can see in the code below, the converter is used to convert a bool into one of two strings from a language resource file.
My question is, is it better to create one instance of ResourceLoader for the converter class or should I continue creating new instances each time the method is called?
class BooleanToBudgetYearStringConverter : IValueConverter
{
private const string CALENDAR = "BudgetCycle_Calendar",
FISCAL = "BudgetCycle_Fiscal";
private Windows.ApplicationModel.Resources.ResourceLoader loader;
public object Convert(object value, Type targetType, object parameter, string language)
{
string entryName = (value is bool && (bool)value) ? CALENDAR : FISCAL; //The name of the entry desired from the entry file.
return new Windows.ApplicationModel.Resources.ResourceLoader().GetString(entryName);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
return (value is string && (string)value == new Windows.ApplicationModel.Resources.ResourceLoader().GetString(CALENDAR));
}
}
I am specifically concerned about speed and memory use.