Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.ComponentModel.DataAnnotations / DataAnnotations / AppSettings.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="AppSettings.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6
7 // AppSettings.cs
8 //
9
10 using System;
11 using System.Collections.Specialized;
12 using System.Configuration;
13 using System.Diagnostics.CodeAnalysis;
14
15 namespace System.ComponentModel.DataAnnotations {
16     internal static class AppSettings {
17         private static volatile bool _settingsInitialized = false;
18         private static object _appSettingsLock = new object();
19         private static void EnsureSettingsLoaded() {
20             if (!_settingsInitialized) {
21                 lock (_appSettingsLock) {
22                     if (!_settingsInitialized) {
23                         NameValueCollection settings = null;
24
25                         try {
26                             settings = ConfigurationManager.AppSettings;
27                         }
28                         catch (ConfigurationErrorsException) { }
29                         finally {
30                             if (settings == null || !Boolean.TryParse(settings["dataAnnotations:dataTypeAttribute:disableRegEx"], out _disableRegEx))
31                                 _disableRegEx = false;
32
33                             _settingsInitialized = true;
34                         }
35                     }
36                 }
37             }
38         }
39
40         private static bool _disableRegEx;
41         internal static bool DisableRegEx {
42             get {
43                 EnsureSettingsLoaded();
44                 return _disableRegEx;
45             }
46         }
47     }
48 }