Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

68 lines
2.1 KiB
C#

// <copyright>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
namespace System.Runtime.Serialization
{
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.Security.Permissions;
static class AppSettings
{
internal const string MaxMimePartsAppSettingsString = "microsoft:xmldictionaryreader:maxmimeparts";
const int DefaultMaxMimeParts = 1000;
static int maxMimeParts;
static volatile bool settingsInitalized = false;
static object appSettingsLock = new object();
internal static int MaxMimeParts
{
get
{
EnsureSettingsLoaded();
return maxMimeParts;
}
}
[SuppressMessage(FxCop.Category.ReliabilityBasic, "Reliability104:CaughtAndHandledExceptionsRule",
Justification = "Handle the configuration exceptions here to avoid regressions on customer's existing scenarios")]
static void EnsureSettingsLoaded()
{
if (!settingsInitalized)
{
lock (appSettingsLock)
{
if (!settingsInitalized)
{
NameValueCollection appSettingsSection = null;
#if !NO_CONFIGURATION
try
{
appSettingsSection = ConfigurationManager.AppSettings;
}
catch (ConfigurationErrorsException)
{
}
finally
{
#endif
if ((appSettingsSection == null) || !int.TryParse(appSettingsSection[MaxMimePartsAppSettingsString], out maxMimeParts))
{
maxMimeParts = DefaultMaxMimeParts;
}
settingsInitalized = true;
#if !NO_CONFIGURATION
}
#endif
}
}
}
}
}
}