private FixedFormatInfoPatternParser <T> EnsureFixedFormatInitialized <T>(ref FixedFormatInfoPatternParser <T> field, Func <IPatternParser <T> > patternParserFactory) { if (field == null) { field = new FixedFormatInfoPatternParser <T>(patternParserFactory(), this); } return(field); }
private FixedFormatInfoPatternParser <T> EnsureFixedFormatInitialized <T>(ref FixedFormatInfoPatternParser <T>?field, Func <IPatternParser <T> > patternParserFactory) { lock (fieldLock) { if (field != null) { return(field); } } // Construct the cache outside the lock to avoid possible deadlocks. The locally constructed // version is ignored if another thread has set the field in-between: this returns a consistent result, // but can occasionally perform redundant work. var localConstruction = new FixedFormatInfoPatternParser <T>(patternParserFactory(), this); lock (fieldLock) { if (field is null) { field = localConstruction; } return(field !); } }