e79aa3c0ed
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
//------------------------------------------------------------------------------
|
|
// <copyright file="AppSettings.cs" company="Microsoft">
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// </copyright>
|
|
//------------------------------------------------------------------------------
|
|
|
|
namespace System.Xml.Serialization {
|
|
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Configuration;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Security.Permissions;
|
|
|
|
internal static class AppSettings {
|
|
private const string UseLegacySerializerGenerationAppSettingsString = "System:Xml:Serialization:UseLegacySerializerGeneration";
|
|
private static bool? useLegacySerializerGeneration;
|
|
private static volatile bool settingsInitalized = false;
|
|
private static object appSettingsLock = new object();
|
|
|
|
internal static bool? UseLegacySerializerGeneration {
|
|
get {
|
|
EnsureSettingsLoaded();
|
|
return useLegacySerializerGeneration;
|
|
}
|
|
}
|
|
|
|
static void EnsureSettingsLoaded() {
|
|
#if CONFIGURATION_DEP
|
|
if (!settingsInitalized) {
|
|
lock (appSettingsLock) {
|
|
if (!settingsInitalized) {
|
|
NameValueCollection appSettingsSection = null;
|
|
try {
|
|
appSettingsSection = ConfigurationManager.AppSettings;
|
|
}
|
|
catch (ConfigurationErrorsException) {
|
|
}
|
|
finally {
|
|
bool tempUseLegacySerializerGeneration;
|
|
if ((appSettingsSection == null) || !bool.TryParse(appSettingsSection[UseLegacySerializerGenerationAppSettingsString], out tempUseLegacySerializerGeneration)) {
|
|
useLegacySerializerGeneration = null;
|
|
}
|
|
else {
|
|
useLegacySerializerGeneration = (bool?)tempUseLegacySerializerGeneration;
|
|
}
|
|
|
|
settingsInitalized = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|