我使用此代码将我的文化更改为 .Net3.5 中的波斯文化:
if (CultureInfo.CurrentCulture.ToString() == "fa-IR")
{
CultureInfo persianCalture = new CultureInfo("fa-IR");
DateTimeFormatInfo info = persianCalture.DateTimeFormat;
info.AbbreviatedDayNames = new string[] { " ی ", " د ", " س ", " چ ", " پ ", " ج ", " ش " };
info.DayNames = new string[] { "يکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه" };
info.AbbreviatedMonthNames = new string[] { "فروردين", "ارديبهشت", "خرداد", "تير", "مرداد", "شهريور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.MonthNames = new string[] { "فروردين", "ارديبهشت", "خرداد", "تير", "مرداد", "شهريور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AbbreviatedMonthGenitiveNames = new string[] { "فروردين", "ارديبهشت", "خرداد", "تير", "مرداد", "شهريور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند", "" };
info.AMDesignator = "صبح";
info.PMDesignator = "عصر";
info.ShortDatePattern = "yyyy/MM/dd";
info.FullDateTimePattern = "yyyy/MM/dd hh:mm:ss";
info.LongDatePattern = "yyyy MMMM dd dddd";
info.FirstDayOfWeek = DayOfWeek.Saturday;
persianCalture.DateTimeFormat = info;
PersianCalendar PersianCal = new PersianCalendar();
typeof(DateTimeFormatInfo).GetField("calendar", (System.Reflection.BindingFlags.NonPublic | (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))).SetValue(info, PersianCal);
typeof(CultureInfo).GetField("calendar", (System.Reflection.BindingFlags.NonPublic | (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))).SetValue(persianCalture, PersianCal);
Thread.CurrentThread.CurrentCulture = persianCalture;
Thread.CurrentThread.CurrentUICulture = persianCalture;
CultureInfo.CurrentCulture.DateTimeFormat = info;
CultureInfo.CurrentUICulture.DateTimeFormat = info;
}
但下面的行是抛出 ArgumentNullException :
System.Globalization.DateTimeFormatInfo.calendar
typeof(DateTimeFormatInfo).GetField("calendar", (System.Reflection.BindingFlags.NonPublic | (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))).SetValue(info, PersianCal);
typeof(CultureInfo).GetField("calendar", (System.Reflection.BindingFlags.NonPublic | (System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))).SetValue(persianCalture, PersianCal);
有谁知道为什么会抛出这个异常?
感谢您的任何帮助,您可以提供。