I have the below function of buildculture for calendar:
private void buildCulture(string culture, string calendarType)
{
CultureInfo ci=null;
try
{
if (string.IsNullOrEmpty(culture))
{
ci = System.Threading.Thread.CurrentThread.CurrentCulture;
}
else
{
try
{
ci = new CultureInfo(culture);
}
catch (System.ArgumentException)
{
ci = System.Threading.Thread.CurrentThread.CurrentCulture;
}
}
// Calendar is from system.windows.control.calendar,
// ci is from system.globalization.calendar:
Calendar originalCal = ci.Calendar;
if (!string.IsNullOrEmpty(culture) ||
originalCal.ToString().Replace("System.Globalization.", "") != culture)
{
foreach (Calendar supportCal in ci.OptionalCalendars)
{
if (calendarType ==
supportCal.ToString().Replace("System.Globalization.", ""))
{
ci.DateTimeFormat.Calendar = supportCal;
}
}
}
}
}
This function still work in .net version 3.5. But after I upgrade to .net 4.5, there's an error appear for line Calendar originalCal = ci.Calendar
which says: Calendar is an ambiguous reference between system.windows.control.calendar and system globalization.calendar
.
How do we fix this guys?
You would want to use the either the fully qualified name when declaring the object, like so:
Or, if you know you aren't using the
System.Windows.Control.Calendar
type, you can alias the typeCalendar
to the one inSystem.Globalization
with the followingusing
: