Add conditionals allowing some calenders to be disabled.#270
Add conditionals allowing some calenders to be disabled.#270marek-safar merged 2 commits intomono:masterfrom
Conversation
src/Common/src/CoreLib/System/Globalization/GlobalizationSupport.cs
Outdated
Show resolved
Hide resolved
d2a0cc6 to
018e36e
Compare
This allows the Japanese, Taiwan and Hebrew calendars to be disabled.
018e36e to
715b2ab
Compare
| { | ||
| if (!GlobalizationMode.Invariant) | ||
| { | ||
| m_hebrewNumberParser = new MatchNumberDelegate(DateTimeParse.MatchHebrewDigits); |
There was a problem hiding this comment.
This should be LazyInitialized instead of explicit static cctor which we won't be able easily remove
There was a problem hiding this comment.
I am fine with using some Lazy<T> initialization and / or putting that inside DoStrictParse().
However, the field initializer that this code was previously using has to go away.
The general rule here is that the pattern new SomeDelegate (ConditionalMethod) must not be used outside a linker conditional (like for instance GlobalizationMode.Invariant), so you cannot put it into a field initializer. The linker is unable to "go inside" that delegate initialization and we also don't have full support for dead field elimination yet.
There was a problem hiding this comment.
That's what I meant. You keep only internal static MatchNumberDelegate m_hebrewNumberParser; with LazyInitializer.EnsureInitialized (ref m_hebrewNumberParser, ...) inside DoStrictParse
There was a problem hiding this comment.
Like this:
if (!GlobalizationMode.Invariant && (CalendarId)parseInfo.calendar.ID == CalendarId.HEBREW)
{
LazyInitializer.EnsureInitialized (ref m_hebrewNumberParser, () => new MatchNumberDelegate(DateTimeParse.MatchHebrewDigits));
parseInfo.parseNumberDelegate = m_hebrewNumberParser;
parseInfo.fCustomNumberParser = true;
}
or do we need locking?
There was a problem hiding this comment.
yep, EnsureInitialized is thread-safe
Add
GlobalizationMode.Invariantconditionals to some calendar code.This allows the Japanese, Taiwan and Hebrew calendars to be disabled.