Я использую этот код несколько раз для установки значений SVG:
Current.Resources["TuesdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
Я пытался очистить код следующим образом:
var L0 = _resourcesPath + "uncheck_Light.svg";
var L1 = _resourcesPath + "checked_Light.svg";
var D0 = _resourcesPath + "uncheck_Dark.svg";
var D1 = _resourcesPath + "checked_Dark.svg";
Current.Resources["MondayActiveStatusIcon"] = new string[,] { { L0, L1 }, { D0, D1 } }[thc, 0];
Я хотел бы чтобы очистить его еще больше, присваивая { L0, L1 }, { D0, D1 }
в переменную и используя это.
Может кто-нибудь объяснить, как я мог это сделать?
Вот полный код для справки. То, что я пытаюсь сделать, - это упростить это, поскольку сейчас это кажется очень сложным:
var L0 = _resourcesPath + "uncheck_Light.svg";
var L1 = _resourcesPath + "checked_Light.svg";
var D0 = _resourcesPath + "uncheck_Dark.svg";
var D1 = _resourcesPath + "checked_Dark.svg";
Current.Resources["MondayActiveStatusIcon"] = new string[,] { { L0, L1 }, { D0, D1 } }[thc, 0];
Current.Resources["TuesdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
Current.Resources["WednesdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
Current.Resources["ThursdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
Current.Resources["FridayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
Current.Resources["SaturdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
Current.Resources["SundayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 0];
var viewHistoryList = App.DB.GetViewHistory(TIME2.Week.FromDate());
foreach (var item in viewHistoryList)
{
var DD = Convert.ToInt32(item.YYMMDD.Substring(4, 2));
var MM = Convert.ToInt32(item.YYMMDD.Substring(2, 2));
var YY = Convert.ToInt32(item.YYMMDD.Substring(0, 2));
DateTime dt = new DateTime(YY, MM, DD);
switch (dt.DayOfWeek)
{
case DayOfWeek.Monday:
Current.Resources["MondayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
case DayOfWeek.Tuesday:
Current.Resources["TuesdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
case DayOfWeek.Wednesday:
Current.Resources["WednesdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
case DayOfWeek.Thursday:
Current.Resources["ThursdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
case DayOfWeek.Friday:
Current.Resources["FridayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
case DayOfWeek.Saturday:
Current.Resources["SaturdayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
case DayOfWeek.Sunday:
Current.Resources["SundayActiveStatusIcon"] = new string[,] { { _resourcesPath + "uncheck_Light.svg", _resourcesPath + "checked_Light.svg" }, { _resourcesPath + "uncheck_Dark.svg", _resourcesPath + "checked_Dark.svg" } }[thc, 1];
break;
default:
break;
}
}