Re-enable xunit warning 2005 (dotnet/corefx#39866) (dotnet/corefx#39864)
authorStephen Toub <stoub@microsoft.com>
Tue, 30 Jul 2019 12:45:39 +0000 (08:45 -0400)
committerGitHub <noreply@github.com>
Tue, 30 Jul 2019 12:45:39 +0000 (08:45 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/9142b477f9355ed184df326d7cd1de4963631228

54 files changed:
src/libraries/CodeAnalysis.ruleset
src/libraries/Common/src/Interop/OSX/Interop.CoreFoundation.CFProxy.cs
src/libraries/Common/src/System/CSharpHelpers.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientSettingsSection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationManager.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConnectionStringSettings.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConnectionStringSettingsCollection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConnectionStringsSection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/DateTimeConfigurationCollection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/DateTimeConfigurationElement.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/KeyValueConfigurationCollection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/KeyValueConfigurationElement.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/NameValueConfigurationCollection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/NameValueConfigurationElement.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ProtectedConfigurationSection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ProviderSettingsCollection.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SchemeSettingElement.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingElement.cs
src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/XmlUtilWriter.cs
src/libraries/System.Data.Common/src/System/Xml/XPathNodePointer.cs
src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcConnectionStringbuilder.cs
src/libraries/System.Data.OleDb/src/OleDbConnectionStringBuilder.cs
src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj
src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsManager.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/SystemIcons.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.cs
src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs
src/libraries/System.Net.Http/src/System/Net/Http/CurlHandler/CurlHandler.cs
src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketProtocolComponent.cs
src/libraries/System.Net.Mail/src/System/Net/Mail/MailHeaderInfo.cs
src/libraries/System.Net.WebHeaderCollection/src/System/Net/HeaderInfoTable.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Attributes.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DictionaryGlobals.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/EnumDataContract.cs
src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ExtensionDataReader.cs
src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaComplexType.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/GenerateHelper.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILModule.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilPatternVisitor.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlNavigatorFilter.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryTypeFactory.cs
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs
src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/Configuration/MemoryCacheElement.cs
src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/Configuration/MemoryCacheSection.cs
src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/Configuration/MemoryCacheSettingsCollection.cs
src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/MemoryMonitor.Windows.cs
src/libraries/System.Runtime.Extensions/src/System/Diagnostics/Stopwatch.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/XmlKeyHelper.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Timeout.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs

index bc48c51..e0fdf5a 100644 (file)
@@ -43,7 +43,6 @@
     <Rule Id="CA1724" Action="None" /> <!-- Type names should not match namespaces -->
     <Rule Id="CA1801" Action="None" /> <!-- Review unused parameters -->
     <Rule Id="CA1806" Action="None" /> <!-- Do not ignore method results -->
-    <Rule Id="CA1810" Action="None" /> <!-- Initialize reference type static fields inline -->
     <Rule Id="CA1812" Action="None" /> <!-- Avoid uninstantiated internal classes -->
     <Rule Id="CA1814" Action="None" /> <!-- Prefer jagged arrays over multidimensional -->
     <Rule Id="CA1815" Action="None" /> <!-- Override equals and operator equals on value types -->
index 1f6cc07..2ed609b 100644 (file)
@@ -65,6 +65,7 @@ internal static partial class Interop
             private static readonly IntPtr kCFProxyTypeKey;
             private static readonly IntPtr kCFProxyUsernameKey;
 
+#pragma warning disable CA1810 // explicit static cctor
             static CFProxy()
             {
                 IntPtr lib = NativeLibrary.Load(Interop.Libraries.CFNetworkLibrary);
@@ -86,6 +87,7 @@ internal static partial class Interop
                     kCFProxyUsernameKey = LoadSymbol(lib, "kCFProxyUsernameKey");
                 }
             }
+#pragma warning restore CA1810
 
             public CFProxy(SafeCFDictionaryHandle dictionary)
             {
index 2aa74d5..0f4f375 100644 (file)
@@ -12,23 +12,93 @@ namespace System
     /// </devdoc>
     internal abstract class CSharpHelpers
     {
-        private static Dictionary<string, object> s_fixedStringLookup;
-
-        static CSharpHelpers()
+        private static readonly HashSet<string> s_fixedStringLookup = new HashSet<string>()
         {
-            s_fixedStringLookup = new Dictionary<string, object>();
-            for (int i = 0; i < s_keywords.Length; i++)
-            {
-                string[] values = s_keywords[i];
-                if (values != null)
-                {
-                    for (int j = 0; j < values.Length; j++)
-                    {
-                        s_fixedStringLookup.Add(values[j], null);
-                    }
-                }
-            }
-        }
+            "as",
+            "do",
+            "if",
+            "in",
+            "is",
+            "for",
+            "int",
+            "new",
+            "out",
+            "ref",
+            "try",
+            "base",
+            "bool",
+            "byte",
+            "case",
+            "char",
+            "else",
+            "enum",
+            "goto",
+            "lock",
+            "long",
+            "null",
+            "this",
+            "true",
+            "uint",
+            "void",
+            "break",
+            "catch",
+            "class",
+            "const",
+            "event",
+            "false",
+            "fixed",
+            "float",
+            "sbyte",
+            "short",
+            "throw",
+            "ulong",
+            "using",
+            "where",
+            "while",
+            "yield",
+            "double",
+            "extern",
+            "object",
+            "params",
+            "public",
+            "return",
+            "sealed",
+            "sizeof",
+            "static",
+            "string",
+            "struct",
+            "switch",
+            "typeof",
+            "unsafe",
+            "ushort",
+            "checked",
+            "decimal",
+            "default",
+            "finally",
+            "foreach",
+            "partial",
+            "private",
+            "virtual",
+            "abstract",
+            "continue",
+            "delegate",
+            "explicit",
+            "implicit",
+            "internal",
+            "operator",
+            "override",
+            "readonly",
+            "volatile",
+            "__arglist",
+            "__makeref",
+            "__reftype",
+            "interface",
+            "namespace",
+            "protected",
+            "unchecked",
+            "__refvalue",
+            "stackalloc",
+        };
 
         public static string CreateEscapedIdentifier(string name)
         {
@@ -52,115 +122,9 @@ namespace System
             return IsValidTypeNameOrIdentifier(value, false);
         }
 
-        private static readonly string[][] s_keywords = new string[][] {
-            null,           // 1 character
-            new string[] {  // 2 characters
-                "as",
-                "do",
-                "if",
-                "in",
-                "is",
-            },
-            new string[] {  // 3 characters
-                "for",
-                "int",
-                "new",
-                "out",
-                "ref",
-                "try",
-            },
-            new string[] {  // 4 characters
-                "base",
-                "bool",
-                "byte",
-                "case",
-                "char",
-                "else",
-                "enum",
-                "goto",
-                "lock",
-                "long",
-                "null",
-                "this",
-                "true",
-                "uint",
-                "void",
-            },
-            new string[] {  // 5 characters
-                "break",
-                "catch",
-                "class",
-                "const",
-                "event",
-                "false",
-                "fixed",
-                "float",
-                "sbyte",
-                "short",
-                "throw",
-                "ulong",
-                "using",
-                "where",
-                "while",
-                "yield",
-            },
-            new string[] {  // 6 characters
-                "double",
-                "extern",
-                "object",
-                "params",
-                "public",
-                "return",
-                "sealed",
-                "sizeof",
-                "static",
-                "string",
-                "struct",
-                "switch",
-                "typeof",
-                "unsafe",
-                "ushort",
-            },
-            new string[] {  // 7 characters
-                "checked",
-                "decimal",
-                "default",
-                "finally",
-                "foreach",
-                "partial",
-                "private",
-                "virtual",
-            },
-            new string[] {  // 8 characters
-                "abstract",
-                "continue",
-                "delegate",
-                "explicit",
-                "implicit",
-                "internal",
-                "operator",
-                "override",
-                "readonly",
-                "volatile",
-            },
-            new string[] {  // 9 characters
-                "__arglist",
-                "__makeref",
-                "__reftype",
-                "interface",
-                "namespace",
-                "protected",
-                "unchecked",
-            },
-            new string[] {  // 10 characters
-                "__refvalue",
-                "stackalloc",
-            },
-        };
-
         internal static bool IsKeyword(string value)
         {
-            return s_fixedStringLookup.ContainsKey(value);
+            return s_fixedStringLookup.Contains(value);
         }
 
         internal static bool IsPrefixTwoUnderscore(string value)
index 7615325..97c5f72 100644 (file)
@@ -9,14 +9,8 @@ namespace System.Configuration
     /// </summary>
     public sealed class ClientSettingsSection : ConfigurationSection
     {
-        private static ConfigurationPropertyCollection _properties;
-        private static readonly ConfigurationProperty _propSettings = new ConfigurationProperty(null, typeof(SettingElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
-
-        static ClientSettingsSection()
-        {
-            _properties = new ConfigurationPropertyCollection();
-            _properties.Add(_propSettings);
-        }
+        private static readonly ConfigurationProperty s_propSettings = new ConfigurationProperty(null, typeof(SettingElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection() { s_propSettings };
 
         public ClientSettingsSection()
         {
@@ -26,7 +20,7 @@ namespace System.Configuration
         {
             get
             {
-                return _properties;
+                return s_properties;
             }
         }
 
@@ -35,7 +29,7 @@ namespace System.Configuration
         {
             get
             {
-                return (SettingElementCollection)base[_propSettings];
+                return (SettingElementCollection)base[s_propSettings];
             }
         }
     }
index 33f779d..6d0aebd 100644 (file)
@@ -13,16 +13,10 @@ namespace System.Configuration
         private static volatile IInternalConfigSystem s_configSystem;
 
         // Initialization state
-        private static volatile InitState s_initState;
-        private static readonly object s_initLock;
+        private static volatile InitState s_initState = InitState.NotStarted;
+        private static readonly object s_initLock = new object();
         private static volatile Exception s_initError;
 
-        static ConfigurationManager()
-        {
-            s_initState = InitState.NotStarted;
-            s_initLock = new object();
-        }
-
         // to be used by System.Diagnostics to avoid false config results during config init
         internal static bool SetConfigurationSystemInProgress
             => (InitState.NotStarted < s_initState) && (s_initState < InitState.Completed);
@@ -265,4 +259,4 @@ namespace System.Configuration
             Completed
         };
     }
-}
\ No newline at end of file
+}
index 50e30f2..ec1400d 100644 (file)
@@ -6,8 +6,6 @@ namespace System.Configuration
 {
     public sealed class ConnectionStringSettings : ConfigurationElement
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
         private static readonly ConfigurationProperty s_propName =
             new ConfigurationProperty("name", typeof(string), null, null,
                 ConfigurationProperty.s_nonEmptyStringValidator,
@@ -19,11 +17,7 @@ namespace System.Configuration
         private static readonly ConfigurationProperty s_propProviderName =
             new ConfigurationProperty("providerName", typeof(string), string.Empty, ConfigurationPropertyOptions.None);
 
-        static ConnectionStringSettings()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection { s_propName, s_propConnectionString, s_propProviderName };
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection { s_propName, s_propConnectionString, s_propProviderName };
 
         public ConnectionStringSettings() { }
 
@@ -73,4 +67,4 @@ namespace System.Configuration
             return ConnectionString;
         }
     }
-}
\ No newline at end of file
+}
index bc24236..f143181 100644 (file)
@@ -7,13 +7,7 @@ namespace System.Configuration
     [ConfigurationCollection(typeof(ConnectionStringSettings))]
     public sealed class ConnectionStringSettingsCollection : ConfigurationElementCollection
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
-        static ConnectionStringSettingsCollection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
 
         public ConnectionStringSettingsCollection()
             : base(StringComparer.OrdinalIgnoreCase)
index 7f23566..f3c0aea 100644 (file)
@@ -6,17 +6,11 @@ namespace System.Configuration
 {
     public sealed class ConnectionStringsSection : ConfigurationSection
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
         private static readonly ConfigurationProperty s_propConnectionStrings =
             new ConfigurationProperty(null, typeof(ConnectionStringSettingsCollection), null,
                 ConfigurationPropertyOptions.IsDefaultCollection);
 
-        static ConnectionStringsSection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection { s_propConnectionStrings };
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection { s_propConnectionStrings };
 
         protected internal override ConfigurationPropertyCollection Properties => s_properties;
 
@@ -30,4 +24,4 @@ namespace System.Configuration
             return this; // return the read only object
         }
     }
-}
\ No newline at end of file
+}
index 0587bb3..a6977dc 100644 (file)
@@ -7,13 +7,7 @@ namespace System.Configuration
     [ConfigurationCollection(typeof(DateTimeConfigurationElement))]
     internal sealed class DateTimeConfigurationCollection : ConfigurationElementCollection
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
-        static DateTimeConfigurationCollection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
 
         protected internal override ConfigurationPropertyCollection Properties => s_properties;
 
@@ -54,4 +48,4 @@ namespace System.Configuration
             return ((DateTimeConfigurationElement)element).Value;
         }
     }
-}
\ No newline at end of file
+}
index 6a64d09..64b10ce 100644 (file)
@@ -6,21 +6,15 @@ namespace System.Configuration
 {
     internal class DateTimeConfigurationElement : ConfigurationElement
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
         private static readonly ConfigurationProperty s_propValue =
             new ConfigurationProperty("value", typeof(DateTime), DateTime.MinValue, ConfigurationPropertyOptions.IsKey);
 
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection { s_propValue };
+
         private readonly DateTime _initValue;
 
         private bool _needsInit;
 
-        static DateTimeConfigurationElement()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection { s_propValue };
-        }
-
         public DateTimeConfigurationElement() { }
 
         public DateTimeConfigurationElement(DateTime value)
@@ -52,4 +46,4 @@ namespace System.Configuration
             }
         }
     }
-}
\ No newline at end of file
+}
index ee96433..ae67937 100644 (file)
@@ -7,13 +7,7 @@ namespace System.Configuration
     [ConfigurationCollection(typeof(KeyValueConfigurationElement))]
     public class KeyValueConfigurationCollection : ConfigurationElementCollection
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
-        static KeyValueConfigurationCollection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
 
         public KeyValueConfigurationCollection() :
             base(StringComparer.OrdinalIgnoreCase)
@@ -76,4 +70,4 @@ namespace System.Configuration
             return ((KeyValueConfigurationElement)element).Key;
         }
     }
-}
\ No newline at end of file
+}
index 6afbf90..c6b575b 100644 (file)
@@ -6,8 +6,6 @@ namespace System.Configuration
 {
     public class KeyValueConfigurationElement : ConfigurationElement
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
         private static readonly ConfigurationProperty s_propKey =
             new ConfigurationProperty("key", typeof(string), string.Empty,
                 ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);
@@ -15,16 +13,13 @@ namespace System.Configuration
         private static readonly ConfigurationProperty s_propValue =
             new ConfigurationProperty("value", typeof(string), string.Empty, ConfigurationPropertyOptions.None);
 
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection { s_propKey, s_propValue };
+
         private readonly string _initKey;
         private readonly string _initValue;
 
         private bool _needsInit;
 
-        static KeyValueConfigurationElement()
-        {
-            s_properties = new ConfigurationPropertyCollection { s_propKey, s_propValue };
-        }
-
         internal KeyValueConfigurationElement() { }
 
         public KeyValueConfigurationElement(string key, string value)
@@ -61,4 +56,4 @@ namespace System.Configuration
             }
         }
     }
-}
\ No newline at end of file
+}
index 6ca14ca..bfca200 100644 (file)
@@ -7,13 +7,7 @@ namespace System.Configuration
     [ConfigurationCollection(typeof(NameValueConfigurationElement))]
     public sealed class NameValueConfigurationCollection : ConfigurationElementCollection
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
-        static NameValueConfigurationCollection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
 
         protected internal override ConfigurationPropertyCollection Properties => s_properties;
 
@@ -66,4 +60,4 @@ namespace System.Configuration
             return ((NameValueConfigurationElement)element).Name;
         }
     }
-}
\ No newline at end of file
+}
index e958ffb..3cea062 100644 (file)
@@ -6,19 +6,13 @@ namespace System.Configuration
 {
     public sealed class NameValueConfigurationElement : ConfigurationElement
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
         private static readonly ConfigurationProperty s_propName =
             new ConfigurationProperty("name", typeof(string), string.Empty, ConfigurationPropertyOptions.IsKey);
 
         private static readonly ConfigurationProperty s_propValue =
             new ConfigurationProperty("value", typeof(string), string.Empty, ConfigurationPropertyOptions.None);
 
-        static NameValueConfigurationElement()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection { s_propName, s_propValue };
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection { s_propName, s_propValue };
 
         internal NameValueConfigurationElement() { }
 
@@ -40,4 +34,4 @@ namespace System.Configuration
             set { base[s_propValue] = value; }
         }
     }
-}
\ No newline at end of file
+}
index df02774..76ae5b4 100644 (file)
@@ -12,8 +12,6 @@ namespace System.Configuration
     {
         private const string EncryptedSectionTemplate = "<{0} {1}=\"{2}\"> {3} </{0}>";
 
-        private static readonly ConfigurationPropertyCollection s_properties;
-
         private static readonly ConfigurationProperty s_propProviders =
             new ConfigurationProperty("providers",
                 typeof(ProtectedProviderSettings),
@@ -28,11 +26,7 @@ namespace System.Configuration
                 validator: ConfigurationProperty.s_nonEmptyStringValidator,
                 options: ConfigurationPropertyOptions.None);
 
-        static ProtectedConfigurationSection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection { s_propProviders, s_propDefaultProvider };
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection { s_propProviders, s_propDefaultProvider };
 
         public ProtectedConfigurationSection(){}
 
index ac37635..bf79da8 100644 (file)
@@ -7,13 +7,7 @@ namespace System.Configuration
     [ConfigurationCollection(typeof(ProviderSettings))]
     public sealed class ProviderSettingsCollection : ConfigurationElementCollection
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-
-        static ProviderSettingsCollection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
 
         public ProviderSettingsCollection() :
             base(StringComparer.OrdinalIgnoreCase)
@@ -64,4 +58,4 @@ namespace System.Configuration
             return ((ProviderSettings)element).Name;
         }
     }
-}
\ No newline at end of file
+}
index 9f75209..39c238d 100644 (file)
@@ -6,23 +6,12 @@ namespace System.Configuration
 {
     public sealed class SchemeSettingElement : ConfigurationElement
     {
-        private static readonly ConfigurationPropertyCollection s_properties;
-        private static readonly ConfigurationProperty s_name;
-        private static readonly ConfigurationProperty s_genericUriParserOptions;
-
-        static SchemeSettingElement()
-        {
-            s_name = new ConfigurationProperty(CommonConfigurationStrings.SchemeName, typeof(string), null,
+        private static readonly ConfigurationProperty s_name = new ConfigurationProperty(CommonConfigurationStrings.SchemeName, typeof(string), null,
                 ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
-
-            s_genericUriParserOptions = new ConfigurationProperty(CommonConfigurationStrings.GenericUriParserOptions,
+        private static readonly ConfigurationProperty s_genericUriParserOptions = new ConfigurationProperty(CommonConfigurationStrings.GenericUriParserOptions,
                 typeof(GenericUriParserOptions), GenericUriParserOptions.Default,
                 ConfigurationPropertyOptions.IsRequired);
-
-            s_properties = new ConfigurationPropertyCollection();
-            s_properties.Add(s_name);
-            s_properties.Add(s_genericUriParserOptions);
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection() { s_name, s_genericUriParserOptions };
 
         [ConfigurationProperty(CommonConfigurationStrings.SchemeName,
             DefaultValue = null, IsRequired = true, IsKey = true)]
index a93c89a..8e7d384 100644 (file)
@@ -8,34 +8,23 @@ namespace System.Configuration
 {
     public sealed class SettingElement : ConfigurationElement
     {
-        private static ConfigurationPropertyCollection _properties;
-        private static readonly ConfigurationProperty _propName = new ConfigurationProperty(
+        private static readonly ConfigurationProperty s_propName = new ConfigurationProperty(
             "name",
             typeof(string),
             "",
             ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
-        private static readonly ConfigurationProperty _propSerializeAs = new ConfigurationProperty(
+        private static readonly ConfigurationProperty s_propSerializeAs = new ConfigurationProperty(
             "serializeAs",
             typeof(SettingsSerializeAs),
             SettingsSerializeAs.String,
             ConfigurationPropertyOptions.IsRequired);
-        private static readonly ConfigurationProperty _propValue = new ConfigurationProperty(
+        private static readonly ConfigurationProperty s_propValue = new ConfigurationProperty(
             "value",
             typeof(SettingValueElement),
             null,
             ConfigurationPropertyOptions.IsRequired);
-        private static XmlDocument _document = new XmlDocument();
-
-        static SettingElement()
-        {
-            // Property initialization
-            _properties = new ConfigurationPropertyCollection();
-
-            _properties.Add(_propName);
-            _properties.Add(_propSerializeAs);
-            _properties.Add(_propValue);
-
-        }
+        private static readonly XmlDocument s_document = new XmlDocument();
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection() { s_propName, s_propSerializeAs, s_propValue };
 
         public SettingElement()
         {
@@ -70,7 +59,7 @@ namespace System.Configuration
         {
             get
             {
-                return _properties;
+                return s_properties;
             }
         }
 
@@ -79,11 +68,11 @@ namespace System.Configuration
         {
             get
             {
-                return (string)base[_propName];
+                return (string)base[s_propName];
             }
             set
             {
-                base[_propName] = value;
+                base[s_propName] = value;
             }
         }
 
@@ -92,11 +81,11 @@ namespace System.Configuration
         {
             get
             {
-                return (SettingsSerializeAs)base[_propSerializeAs];
+                return (SettingsSerializeAs)base[s_propSerializeAs];
             }
             set
             {
-                base[_propSerializeAs] = value;
+                base[s_propSerializeAs] = value;
             }
         }
 
@@ -105,11 +94,11 @@ namespace System.Configuration
         {
             get
             {
-                return (SettingValueElement)base[_propValue];
+                return (SettingValueElement)base[s_propValue];
             }
             set
             {
-                base[_propValue] = value;
+                base[s_propValue] = value;
             }
         }
     }
index 65d8fb9..f96ebcf 100644 (file)
@@ -25,19 +25,12 @@ namespace System.Configuration
         private const char Space = ' ';
         private const string NewLine = "\r\n";
 
-        private static readonly string s_spaces8;
-        private static readonly string s_spaces4;
-        private static readonly string s_spaces2;
+        private static readonly string s_spaces8 = new string(Space, 8);
+        private static readonly string s_spaces4 = new string(Space, 4);
+        private static readonly string s_spaces2 = new string(Space, 2);
         private readonly Stream _baseStream; // stream under TextWriter when tracking position
         private object _lineStartCheckpoint; // checkpoint taken at the start of each line
 
-        static XmlUtilWriter()
-        {
-            s_spaces8 = new string(Space, 8);
-            s_spaces4 = new string(Space, 4);
-            s_spaces2 = new string(Space, 2);
-        }
-
         internal XmlUtilWriter(TextWriter writer, bool trackPosition)
         {
             Writer = writer;
@@ -385,4 +378,4 @@ namespace System.Configuration
             }
         }
     }
-}
\ No newline at end of file
+}
index 9344c2e..fe7946d 100644 (file)
@@ -18,13 +18,13 @@ namespace System.Xml
         private DataColumn _column;
         private bool _fOnValue;
         internal XmlBoundElement _parentOfNS;
-        internal static readonly int[] s_xmlNodeType_To_XpathNodeType_Map;
+        internal static readonly int[] s_xmlNodeType_To_XpathNodeType_Map = CreateXmlNodeTypeToXpathNodeTypeMap();
         internal const string StrReservedXmlns = "http://www.w3.org/2000/xmlns/";
         internal const string StrReservedXml = "http://www.w3.org/XML/1998/namespace";
         internal const string StrXmlNS = "xmlns";
         private bool _bNeedFoliate;
 
-        static XPathNodePointer()
+        private static int[] CreateXmlNodeTypeToXpathNodeTypeMap()
         {
 #if DEBUG
             int max = 0, tempVal = 0;
@@ -37,26 +37,27 @@ namespace System.Xml
             }
             Debug.Assert(max == (int)XmlNodeType.XmlDeclaration);
 #endif        
-            s_xmlNodeType_To_XpathNodeType_Map = new int[20];
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.None)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Element)] = (int)XPathNodeType.Element;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Attribute)] = (int)XPathNodeType.Attribute;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Text)] = (int)XPathNodeType.Text;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.CDATA)] = (int)XPathNodeType.Text;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.EntityReference)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Entity)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.ProcessingInstruction)] = (int)XPathNodeType.ProcessingInstruction;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Comment)] = (int)XPathNodeType.Comment;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Document)] = (int)XPathNodeType.Root;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.DocumentType)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.DocumentFragment)] = (int)XPathNodeType.Root;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Notation)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.Whitespace)] = (int)XPathNodeType.Whitespace;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.SignificantWhitespace)] = (int)XPathNodeType.SignificantWhitespace;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.EndElement)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.EndEntity)] = -1;
-            s_xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.XmlDeclaration)] = -1;
-            // xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.All)] = -1;      
+            var map = new int[20];
+            map[(int)XmlNodeType.None] = -1;
+            map[(int)XmlNodeType.Element] = (int)XPathNodeType.Element;
+            map[(int)XmlNodeType.Attribute] = (int)XPathNodeType.Attribute;
+            map[(int)XmlNodeType.Text] = (int)XPathNodeType.Text;
+            map[(int)XmlNodeType.CDATA] = (int)XPathNodeType.Text;
+            map[(int)XmlNodeType.EntityReference] = -1;
+            map[(int)XmlNodeType.Entity] = -1;
+            map[(int)XmlNodeType.ProcessingInstruction] = (int)XPathNodeType.ProcessingInstruction;
+            map[(int)XmlNodeType.Comment] = (int)XPathNodeType.Comment;
+            map[(int)XmlNodeType.Document] = (int)XPathNodeType.Root;
+            map[(int)XmlNodeType.DocumentType] = -1;
+            map[(int)XmlNodeType.DocumentFragment] = (int)XPathNodeType.Root;
+            map[(int)XmlNodeType.Notation] = -1;
+            map[(int)XmlNodeType.Whitespace] = (int)XPathNodeType.Whitespace;
+            map[(int)XmlNodeType.SignificantWhitespace] = (int)XPathNodeType.SignificantWhitespace;
+            map[(int)XmlNodeType.EndElement] = -1;
+            map[(int)XmlNodeType.EndEntity] = -1;
+            map[(int)XmlNodeType.XmlDeclaration] = -1;
+            // xmlNodeType_To_XpathNodeType_Map[(int)(XmlNodeType.All)] = -1;     
+            return map;
         }
 
         private XPathNodeType DecideXPNodeTypeForTextNodes(XmlNode node)
index 9724ca0..8fdf08e 100644 (file)
@@ -14,39 +14,28 @@ namespace System.Data.Odbc
     public sealed class OdbcConnectionStringBuilder : DbConnectionStringBuilder
     {
         private enum Keywords
-        { // must maintain same ordering as _validKeywords array
-          //            NamedConnection,
+        {
+            // must maintain same ordering as s_validKeywords array
             Dsn,
-
             Driver,
         }
 
-        private static readonly string[] s_validKeywords;
-        private static readonly Dictionary<string, Keywords> s_keywords;
+        private static readonly string[] s_validKeywords = new string[2]
+        {
+            DbConnectionStringKeywords.Dsn, // (int)Keywords.Dsn
+            DbConnectionStringKeywords.Driver // (int)Keywords.Driver
+        };
+        private static readonly Dictionary<string, Keywords> s_keywords = new Dictionary<string, Keywords>(2, StringComparer.OrdinalIgnoreCase)
+        {
+            { DbConnectionStringKeywords.Driver, Keywords.Driver },
+            { DbConnectionStringKeywords.Dsn, Keywords.Dsn }
+        };
 
         private string[] _knownKeywords;
 
         private string _dsn = DbConnectionStringDefaults.Dsn;
-        //        private string _namedConnection  = DbConnectionStringDefaults.NamedConnection;
-
         private string _driver = DbConnectionStringDefaults.Driver;
 
-        static OdbcConnectionStringBuilder()
-        {
-            string[] validKeywords = new string[2];
-            validKeywords[(int)Keywords.Driver] = DbConnectionStringKeywords.Driver;
-            validKeywords[(int)Keywords.Dsn] = DbConnectionStringKeywords.Dsn;
-            //            validKeywords[(int)Keywords.NamedConnection] = DbConnectionStringKeywords.NamedConnection;
-            s_validKeywords = validKeywords;
-
-            Dictionary<string, Keywords> hash = new Dictionary<string, Keywords>(2, StringComparer.OrdinalIgnoreCase);
-            hash.Add(DbConnectionStringKeywords.Driver, Keywords.Driver);
-            hash.Add(DbConnectionStringKeywords.Dsn, Keywords.Dsn);
-            //            hash.Add(DbConnectionStringKeywords.NamedConnection, Keywords.NamedConnection);
-            Debug.Assert(2 == hash.Count, "initial expected size is incorrect");
-            s_keywords = hash;
-        }
-
         public OdbcConnectionStringBuilder() : this((string)null)
         {
         }
@@ -86,7 +75,6 @@ namespace System.Data.Odbc
                         {
                             case Keywords.Driver: Driver = ConvertToString(value); break;
                             case Keywords.Dsn: Dsn = ConvertToString(value); break;
-                            //                      case Keywords.NamedConnection: NamedConnection = ConvertToString(value); break;
                             default:
                                 Debug.Fail("unexpected keyword");
                                 throw ADP.KeywordNotSupported(keyword);
@@ -127,20 +115,7 @@ namespace System.Data.Odbc
                 _dsn = value;
             }
         }
-        /*
-                [DisplayName(DbConnectionStringKeywords.NamedConnection)]
-                [ResCategoryAttribute(Res.DataCategory_NamedConnectionString)]
-                [ResDescriptionAttribute(Res.DbConnectionString_NamedConnection)]
-                [RefreshPropertiesAttribute(RefreshProperties.All)]
-                [TypeConverter(typeof(NamedConnectionStringConverter))]
-                public string NamedConnection {
-                    get { return _namedConnection; }
-                    set {
-                        SetValue(DbConnectionStringKeywords.NamedConnection, value);
-                        _namedConnection = value;
-                    }
-                }
-        */
+
         public override ICollection Keys
         {
             get
@@ -224,52 +199,12 @@ namespace System.Data.Odbc
             {
                 case Keywords.Driver: return Driver;
                 case Keywords.Dsn: return Dsn;
-                //          case Keywords.NamedConnection: return NamedConnection;
                 default:
                     Debug.Fail("unexpected keyword");
                     throw ADP.KeywordNotSupported(s_validKeywords[(int)index]);
             }
         }
 
-        /*
-        protected override void GetProperties(Hashtable propertyDescriptors) {
-            object value;
-            if (TryGetValue(DbConnectionStringSynonyms.TRUSTEDCONNECTION, out value)) {
-                bool trusted = false;
-                if (value is bool) {
-                    trusted = (bool)value;
-                }
-                else if ((value is string) && !Boolean.TryParse((string)value, out trusted)) {
-                    trusted = false;
-                }
-
-                if (trusted) {
-                   Attribute[] attributes = new Attribute[] {
-                        BrowsableAttribute.Yes,
-                        RefreshPropertiesAttribute.All,
-                    };
-                    DbConnectionStringBuilderDescriptor descriptor;
-                    descriptor = new DbConnectionStringBuilderDescriptor(DbConnectionStringSynonyms.TRUSTEDCONNECTION,
-                                        this.GetType(), typeof(bool), false, attributes);
-                    descriptor.RefreshOnChange = true;
-                    propertyDescriptors[DbConnectionStringSynonyms.TRUSTEDCONNECTION] = descriptor;
-
-                    if (ContainsKey(DbConnectionStringSynonyms.Pwd)) {
-                        descriptor = new DbConnectionStringBuilderDescriptor(DbConnectionStringSynonyms.Pwd,
-                                            this.GetType(), typeof(string), true, attributes);
-                        propertyDescriptors[DbConnectionStringSynonyms.Pwd] = descriptor;
-                    }
-                    if (ContainsKey(DbConnectionStringSynonyms.UID)) {
-                        descriptor = new DbConnectionStringBuilderDescriptor(DbConnectionStringSynonyms.UID,
-                                            this.GetType(), typeof(string), true, attributes);
-                        propertyDescriptors[DbConnectionStringSynonyms.UID] = descriptor;
-                    }
-                }
-            }
-            base.GetProperties(propertyDescriptors);
-        }
-        */
-
         public override bool Remove(string keyword)
         {
             ADP.CheckArgumentNull(keyword, nameof(keyword));
@@ -299,9 +234,6 @@ namespace System.Data.Odbc
                 case Keywords.Dsn:
                     _dsn = DbConnectionStringDefaults.Dsn;
                     break;
-                //            case Keywords.NamedConnection:
-                //               _namedConnection = DbConnectionStringDefaults.NamedConnection;
-                //                break;
                 default:
                     Debug.Fail("unexpected keyword");
                     throw ADP.KeywordNotSupported(s_validKeywords[(int)index]);
index a30c852..b6ee6eb 100644 (file)
@@ -18,19 +18,29 @@ namespace System.Data.OleDb
     public sealed class OleDbConnectionStringBuilder : DbConnectionStringBuilder
     {
         private enum Keywords
-        { // specific ordering for ConnectionString output construction
-          //          NamedConnection,
+        {
             FileName,
-
             Provider,
             DataSource,
             PersistSecurityInfo,
-
             OleDbServices,
         }
-
-        private static readonly string[] _validKeywords;
-        private static readonly Dictionary<string, Keywords> _keywords;
+        private static readonly string[] s_validKeywords = new string[5]
+        {
+            DbConnectionStringKeywords.FileName,
+            DbConnectionStringKeywords.Provider,
+            DbConnectionStringKeywords.DataSource,
+            DbConnectionStringKeywords.PersistSecurityInfo,
+            DbConnectionStringKeywords.OleDbServices
+        };
+        private static readonly Dictionary<string, Keywords> s_keywords = new Dictionary<string, Keywords>(5, StringComparer.OrdinalIgnoreCase)
+        {
+            { DbConnectionStringKeywords.FileName, Keywords.FileName },
+            { DbConnectionStringKeywords.Provider, Keywords.Provider },
+            { DbConnectionStringKeywords.DataSource, Keywords.DataSource },
+            { DbConnectionStringKeywords.PersistSecurityInfo, Keywords.PersistSecurityInfo },
+            { DbConnectionStringKeywords.OleDbServices, Keywords.OleDbServices },
+        };
 
         private string[] _knownKeywords;
         private Dictionary<string, OleDbPropertyInfo> _propertyInfo;
@@ -44,29 +54,9 @@ namespace System.Data.OleDb
 
         private bool _persistSecurityInfo = DbConnectionStringDefaults.PersistSecurityInfo;
 
-        static OleDbConnectionStringBuilder()
-        {
-            string[] validKeywords = new string[5];
-            validKeywords[(int)Keywords.DataSource] = DbConnectionStringKeywords.DataSource;
-            validKeywords[(int)Keywords.FileName] = DbConnectionStringKeywords.FileName;
-            validKeywords[(int)Keywords.OleDbServices] = DbConnectionStringKeywords.OleDbServices;
-            validKeywords[(int)Keywords.PersistSecurityInfo] = DbConnectionStringKeywords.PersistSecurityInfo;
-            validKeywords[(int)Keywords.Provider] = DbConnectionStringKeywords.Provider;
-            _validKeywords = validKeywords;
-
-            Dictionary<string, Keywords> hash = new Dictionary<string, Keywords>(9, StringComparer.OrdinalIgnoreCase);
-            hash.Add(DbConnectionStringKeywords.DataSource, Keywords.DataSource);
-            hash.Add(DbConnectionStringKeywords.FileName, Keywords.FileName);
-            hash.Add(DbConnectionStringKeywords.OleDbServices, Keywords.OleDbServices);
-            hash.Add(DbConnectionStringKeywords.PersistSecurityInfo, Keywords.PersistSecurityInfo);
-            hash.Add(DbConnectionStringKeywords.Provider, Keywords.Provider);
-            Debug.Assert(5 == hash.Count, "initial expected size is incorrect");
-            _keywords = hash;
-        }
-
         public OleDbConnectionStringBuilder() : this(null)
         {
-            _knownKeywords = _validKeywords;
+            _knownKeywords = s_validKeywords;
         }
 
         public OleDbConnectionStringBuilder(string connectionString) : base()
@@ -84,7 +74,7 @@ namespace System.Data.OleDb
                 ADP.CheckArgumentNull(keyword, "keyword");
                 object value;
                 Keywords index;
-                if (_keywords.TryGetValue(keyword, out index))
+                if (s_keywords.TryGetValue(keyword, out index))
                 {
                     value = GetAt(index);
                 }
@@ -102,7 +92,7 @@ namespace System.Data.OleDb
                 {
                     ADP.CheckArgumentNull(keyword, "keyword");
                     Keywords index;
-                    if (_keywords.TryGetValue(keyword, out index))
+                    if (s_keywords.TryGetValue(keyword, out index))
                     {
                         switch (index)
                         {
@@ -112,7 +102,6 @@ namespace System.Data.OleDb
                             case Keywords.FileName:
                                 FileName = ConvertToString(value);
                                 break;
-                            //                      case Keywords.NamedConnection:     NamedConnection = ConvertToString(value); break;
                             case Keywords.Provider:
                                 Provider = ConvertToString(value);
                                 break;
@@ -217,13 +206,13 @@ namespace System.Data.OleDb
                     Dictionary<string, OleDbPropertyInfo> dynamic = GetProviderInfo(Provider);
                     if (0 < dynamic.Count)
                     {
-                        knownKeywords = new string[_validKeywords.Length + dynamic.Count];
-                        _validKeywords.CopyTo(knownKeywords, 0);
-                        dynamic.Keys.CopyTo(knownKeywords, _validKeywords.Length);
+                        knownKeywords = new string[s_validKeywords.Length + dynamic.Count];
+                        s_validKeywords.CopyTo(knownKeywords, 0);
+                        dynamic.Keys.CopyTo(knownKeywords, s_validKeywords.Length);
                     }
                     else
                     {
-                        knownKeywords = _validKeywords;
+                        knownKeywords = s_validKeywords;
                     }
 
                     int count = 0;
@@ -276,7 +265,7 @@ namespace System.Data.OleDb
         public override bool ContainsKey(string keyword)
         {
             ADP.CheckArgumentNull(keyword, "keyword");
-            return _keywords.ContainsKey(keyword) || base.ContainsKey(keyword);
+            return s_keywords.ContainsKey(keyword) || base.ContainsKey(keyword);
         }
 
         private static bool ConvertToBoolean(object value)
@@ -295,12 +284,12 @@ namespace System.Data.OleDb
         public override void Clear()
         {
             base.Clear();
-            for (int i = 0; i < _validKeywords.Length; ++i)
+            for (int i = 0; i < s_validKeywords.Length; ++i)
             {
                 Reset((Keywords)i);
             }
             base.ClearPropertyDescriptors();
-            _knownKeywords = _validKeywords;
+            _knownKeywords = s_validKeywords;
         }
 
         private object GetAt(Keywords index)
@@ -311,7 +300,6 @@ namespace System.Data.OleDb
                     return DataSource;
                 case Keywords.FileName:
                     return FileName;
-                //          case Keywords.NamedConnection:     return NamedConnection;
                 case Keywords.OleDbServices:
                     return OleDbServices;
                 case Keywords.PersistSecurityInfo:
@@ -320,7 +308,7 @@ namespace System.Data.OleDb
                     return Provider;
                 default:
                     Debug.Assert(false, "unexpected keyword");
-                    throw ADP.KeywordNotSupported(_validKeywords[(int)index]);
+                    throw ADP.KeywordNotSupported(s_validKeywords[(int)index]);
             }
         }
 
@@ -330,7 +318,7 @@ namespace System.Data.OleDb
             bool value = base.Remove(keyword);
 
             Keywords index;
-            if (_keywords.TryGetValue(keyword, out index))
+            if (s_keywords.TryGetValue(keyword, out index))
             {
                 Reset(index);
             }
@@ -364,7 +352,7 @@ namespace System.Data.OleDb
                     break;
                 default:
                     Debug.Assert(false, "unexpected keyword");
-                    throw ADP.KeywordNotSupported(_validKeywords[(int)index]);
+                    throw ADP.KeywordNotSupported(s_validKeywords[(int)index]);
             }
         }
 
@@ -398,7 +386,7 @@ namespace System.Data.OleDb
         {
             ADP.CheckArgumentNull(keyword, "keyword");
             Keywords index;
-            if (_keywords.TryGetValue(keyword, out index))
+            if (s_keywords.TryGetValue(keyword, out index))
             {
                 value = GetAt(index);
                 return true;
@@ -441,7 +429,7 @@ namespace System.Data.OleDb
                             {
                                 Keywords index;
                                 OleDbPropertyInfo info = entry.Value;
-                                if (!_keywords.TryGetValue(info._description, out index))
+                                if (!s_keywords.TryGetValue(info._description, out index))
                                 {
                                     if ((OleDbPropertySetGuid.DBInit == info._propertySet) &&
                                             ((ODB.DBPROP_INIT_ASYNCH == info._propertyID) ||
index c4c878b..26b934e 100644 (file)
@@ -4,7 +4,7 @@
     <AssemblyName>System.DirectoryServices.AccountManagement</AssemblyName>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <DefineConstants>$(DefineConstants);FLAVOR_WHIDBEY;PAPI_AD;PAPI_REGSAM;USE_CTX_CACHE</DefineConstants>
-    <NoWarn>$(NoWarn);8073</NoWarn>
+    <NoWarn>$(NoWarn);8073;CA1810</NoWarn>
     <!-- Although we have a netstandard configuration, we know we are not currently UAP compatible-->
     <UWPCompatible>false</UWPCompatible>
     <IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
index ac06dd5..9674149 100644 (file)
@@ -3,7 +3,7 @@
     <ProjectGuid>{135980AC-4583-44EC-894E-CB3B1A481920}</ProjectGuid>
     <AssemblyName>System.DirectoryServices.Protocols</AssemblyName>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <NoWarn>$(NoWarn);0649</NoWarn>
+    <NoWarn>$(NoWarn);0649;CA1810</NoWarn>
     <!-- Although we have a netstandard configuration, we know we are not currently UAP compatible-->
     <UWPCompatible>false</UWPCompatible>
     <IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
@@ -62,4 +62,4 @@
   <ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
     <Reference Include="System.ComponentModel.Primitives" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index 7f194df..d1fc965 100644 (file)
 //
 //
 
-
 namespace System.Drawing
 {
     public static class BufferedGraphicsManager
     {
-        private static BufferedGraphicsContext graphics_context;
-
-        static BufferedGraphicsManager()
-        {
-            graphics_context = new BufferedGraphicsContext();
-        }
-
-        public static BufferedGraphicsContext Current
-        {
-            get { return graphics_context; }
-        }
+        public static BufferedGraphicsContext Current { get; } = new BufferedGraphicsContext();
     }
 }
-
index 677c64f..d9c13e2 100644 (file)
@@ -49,24 +49,13 @@ namespace System.Drawing.Printing
     {
         #region Private Fields
 
-        private static Hashtable doc_info = new Hashtable();
-        private static bool cups_installed;
-
-        private static Hashtable installed_printers;
+        private static readonly Hashtable doc_info = new Hashtable();
+        private static readonly bool cups_installed = CheckCupsInstalled();
+        private static readonly Hashtable installed_printers = new Hashtable();
         private static string default_printer = string.Empty;
 
         #endregion
 
-        #region Constructor
-
-        static PrintingServices()
-        {
-            installed_printers = new Hashtable();
-            CheckCupsInstalled();
-        }
-
-        #endregion
-
         #region Properties
 
         internal static PrinterSettings.StringCollection InstalledPrinters
@@ -101,7 +90,7 @@ namespace System.Drawing.Printing
         /// <summary>
         /// Do a cups call to check if it is installed
         /// </summary>
-        private static void CheckCupsInstalled()
+        private static bool CheckCupsInstalled()
         {
             try
             {
@@ -114,11 +103,10 @@ namespace System.Drawing.Printing
 #else
                 Console.WriteLine("libcups not found. To have printing support, you need cups installed");
 #endif
-                cups_installed = false;
-                return;
+                return false;
             }
 
-            cups_installed = true;
+            return true;
         }
 
         /// <summary>
index d08a0dd..ef0c7c4 100644 (file)
@@ -35,8 +35,6 @@ namespace System.Drawing
 {
     public static class SystemIcons
     {
-
-        static Icon[] icons;
         private const int Application_Winlogo = 0;
         private const int Asterisk_Information = 1;
         private const int Error_Hand = 2;
@@ -44,28 +42,27 @@ namespace System.Drawing
         private const int Question_ = 4;
         private const int Shield_ = 5;
 
-        static SystemIcons()
+        // we minimize the # of icons to load since most of them are duplicates
+        // we use an internal .ctor to ensure the SystemIcons can't de disposed
+        private static readonly Icon[] icons = new Icon[6]
         {
-            // we minimize the # of icons to load since most of them are duplicates
-            icons = new Icon[6];
-            // we use an internal .ctor to ensure the SystemIcons can't de disposed
 #if NETCORE
             // TODO: Decide which icons to use for this.
-            icons[Application_Winlogo] = new Icon("placeholder.ico", true);
-            icons[Asterisk_Information] = new Icon("placeholder.ico", true);
-            icons[Error_Hand] = new Icon("placeholder.ico", true);
-            icons[Exclamation_Warning] = new Icon("placeholder.ico", true);
-            icons[Question_] = new Icon("placeholder.ico", true);
-            icons[Shield_] = new Icon("placeholder.ico", true);
+            new Icon("placeholder.ico", undisposable:true), // Application_Winlogo
+            new Icon("placeholder.ico", undisposable:true), // Asterisk_Information
+            new Icon("placeholder.ico", undisposable:true), // Error_Hand
+            new Icon("placeholder.ico", undisposable:true), // Exclamation_Warning
+            new Icon("placeholder.ico", undisposable:true), // Question_
+            new Icon("placeholder.ico", undisposable:true), // Shield_
 #else
-            icons[Application_Winlogo] = new Icon("Mono.ico", true);
-            icons[Asterisk_Information] = new Icon("Information.ico", true);
-            icons[Error_Hand] = new Icon("Error.ico", true);
-            icons[Exclamation_Warning] = new Icon("Warning.ico", true);
-            icons[Question_] = new Icon("Question.ico", true);
-            icons[Shield_] = new Icon("Shield.ico", true);
+            new Icon("Mono.ico", undisposable:true),        // Application_Winlogo
+            new Icon("Information.ico", undisposable:true), // Asterisk_Information
+            new Icon("Error.ico", undisposable:true),       // Error_Hand
+            new Icon("Warning.ico", undisposable:true),     // Exclamation_Warning
+            new Icon("Question.ico", undisposable:true),    // Question_
+            new Icon("Shield.ico", undisposable:true),      // Shield_
 #endif
-        }
+        };
 
         // note: same as WinLogo (for Mono)
         public static Icon Application
index 1d42e0e..8aecb68 100644 (file)
@@ -345,6 +345,7 @@ namespace System.Drawing
 
         private static readonly ToolboxBitmapAttribute s_defaultComponent;
 
+#pragma warning disable CA1810 // DummyFunction apparently needs to be invoked prior to the rest of the initialization
         static ToolboxBitmapAttribute()
         {
             // When we call Gdip.DummyFunction, JIT will make sure Gdip..cctor will be called.
@@ -357,5 +358,6 @@ namespace System.Drawing
             MakeBackgroundAlphaZero(bitmap);
             s_defaultComponent = new ToolboxBitmapAttribute(bitmap, null);
         }
+#pragma warning restore CA1810
     }
 }
index 98ee161..1dca7d2 100644 (file)
 using System.Collections;
 using System.Reflection;
 using System.Runtime.InteropServices;
-using System.Security;
 
 namespace System.Drawing
 {
-
     internal static class MacSupport
     {
-        internal static Hashtable contextReference = new Hashtable();
-        internal static object lockobj = new object();
-
-        internal static Delegate hwnd_delegate;
+        internal static readonly Hashtable contextReference = new Hashtable();
+        internal static readonly object lockobj = new object();
+        internal static readonly Delegate hwnd_delegate = GetHwndDelegate();
 
 #if DEBUG_CLIPPING
         internal static float red = 1.0f;
@@ -51,7 +48,7 @@ namespace System.Drawing
         internal static int debug_threshold = 1;
 #endif
 
-        static MacSupport()
+        private static Delegate GetHwndDelegate()
         {
 #if !NETSTANDARD1_6
             foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
@@ -61,11 +58,12 @@ namespace System.Drawing
                     Type driver_type = asm.GetType("System.Windows.Forms.XplatUICarbon");
                     if (driver_type != null)
                     {
-                        hwnd_delegate = (Delegate)driver_type.GetTypeInfo().GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
+                        return (Delegate)driver_type.GetTypeInfo().GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
                     }
                 }
             }
 #endif
+            return null;
         }
 
         internal static CocoaContext GetCGContextForNSView(IntPtr handle)
index 13594c1..caeb66c 100644 (file)
@@ -157,6 +157,7 @@ namespace System.Net.Http
 
         #endregion
 
+#pragma warning disable CA1810 // explicit static cctor
         static CurlHandler()
         {
             // curl_global_init call handled by Interop.LibCurl's cctor
@@ -179,6 +180,7 @@ namespace System.Net.Http
                 s_singletonSharedAgent = new MultiAgent(null);
             }
         }
+#pragma warning restore CA1810
 
         public CurlHandler()
         {
index d5b015b..3b9dfee 100644 (file)
@@ -72,6 +72,7 @@ namespace System.Net.WebSockets
             Receive = 2,
         }
 
+#pragma warning disable CA1810 // explicit static cctor
         static WebSocketProtocolComponent()
         {
             s_webSocketDllHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.WebSocket, IntPtr.Zero, 0);
@@ -120,6 +121,7 @@ namespace System.Net.WebSockets
                 };
             }
         }
+#pragma warning restore CA1810
 
         internal static string SupportedVersion
         {
index 1588b8e..2d51de5 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Collections.Generic;
+using System.Diagnostics;
 
 namespace System.Net.Mail
 {
@@ -66,27 +67,18 @@ namespace System.Net.Mail
             new HeaderInfo(MailHeaderID.XSender,                  "X-Sender",                  true,            true,               true)
         };
 
-        private static readonly Dictionary<string, int> s_headerDictionary;
+        private static readonly Dictionary<string, int> s_headerDictionary = CreateHeaderDictionary();
 
-        static MailHeaderInfo()
+        private static Dictionary<string, int> CreateHeaderDictionary()
         {
-#if DEBUG
-            // Check that enum and header info array are in sync
-            for (int i = 0; i < s_headerInfo.Length; i++)
-            {
-                if ((int)s_headerInfo[i].ID != i)
-                {
-                    throw new Exception("Header info data structures are not in sync");
-                }
-            }
-#endif
-
             // Create dictionary for string-to-enum lookup.  Ordinal and IgnoreCase are intentional.
-            s_headerDictionary = new Dictionary<string, int>((int)MailHeaderID.ZMaxEnumValue + 1, StringComparer.OrdinalIgnoreCase);
+            var headers = new Dictionary<string, int>((int)MailHeaderID.ZMaxEnumValue + 1, StringComparer.OrdinalIgnoreCase);
             for (int i = 0; i < s_headerInfo.Length; i++)
             {
-                s_headerDictionary.Add(s_headerInfo[i].NormalizedName, i);
+                Debug.Assert((int)s_headerInfo[i].ID == i, "Header info data structures are not in sync");
+                headers.Add(s_headerInfo[i].NormalizedName, i);
             }
+            return headers;
         }
 
         internal static string GetString(MailHeaderID id)
index ad3780e..a11dcd6 100644 (file)
@@ -4,7 +4,7 @@
 
 using System.Collections;
 using System.Collections.Generic;
-using System.Collections.Specialized;
+using System.Diagnostics;
 using System.Linq;
 
 namespace System.Net
@@ -15,7 +15,7 @@ namespace System.Net
         private static readonly Func<string, string[]> s_multiParser = value => ParseValueHelper(value, isSetCookie: false);
         private static readonly Func<string, string[]> s_setCookieParser = value => ParseValueHelper(value, isSetCookie: true);
         private static readonly HeaderInfo s_unknownHeaderInfo = new HeaderInfo(string.Empty, false, false, false, s_singleParser);
-        private static readonly Hashtable s_headerHashTable;
+        private static readonly Hashtable s_headerHashTable = CreateHeaderHashtable();
 
         private static string[] ParseValueHelper(string value, bool isSetCookie)
         {
@@ -76,69 +76,66 @@ namespace System.Net
             return (isExpires && noComma);
         }
 
-        static HeaderInfoTable()
+        private static Hashtable CreateHeaderHashtable()
         {
-            HeaderInfo[] InfoArray = new HeaderInfo[]
+            const int Items = 52;
+            var headers = new Hashtable(Items * 2, CaseInsensitiveAscii.StaticInstance)
             {
-                new HeaderInfo(HttpKnownHeaderNames.Age,                false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Allow,              false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Accept,             true,   false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Authorization,      false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.AcceptRanges,       false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.AcceptCharset,      false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.AcceptEncoding,     false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.AcceptLanguage,     false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Cookie,             false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Connection,         true,   false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentMD5,         false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentType,        true,   false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.CacheControl,       false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentRange,       false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentLength,      true,   true,   false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentEncoding,    false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentLanguage,    false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ContentLocation,    false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Date,               true,   false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.ETag,               false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Expect,             true,   false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Expires,            false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.From,               false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Host,               true,   false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.IfMatch,            false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.IfRange,            false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.IfNoneMatch,        false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.IfModifiedSince,    true,   false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.IfUnmodifiedSince,  false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.KeepAlive,          false,  true,   false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Location,           false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.LastModified,       false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.MaxForwards,        false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Pragma,             false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ProxyAuthenticate,  false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ProxyAuthorization, false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.ProxyConnection,    true,   false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Range,              true,   false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Referer,            true,   false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.RetryAfter,         false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Server,             false,  false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.SetCookie,          false,  false,  true,   s_setCookieParser),
-                new HeaderInfo(HttpKnownHeaderNames.SetCookie2,         false,  false,  true,   s_setCookieParser),
-                new HeaderInfo(HttpKnownHeaderNames.TE,                 false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Trailer,            false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.TransferEncoding,   true,   true,   true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Upgrade,            false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.UserAgent,          true,   false,  false,  s_singleParser),
-                new HeaderInfo(HttpKnownHeaderNames.Via,                false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Vary,               false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.Warning,            false,  false,  true,   s_multiParser),
-                new HeaderInfo(HttpKnownHeaderNames.WWWAuthenticate,    false,  true,   true,   s_singleParser)
+                { HttpKnownHeaderNames.Age,                new HeaderInfo(HttpKnownHeaderNames.Age,                false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Allow,              new HeaderInfo(HttpKnownHeaderNames.Allow,              false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Accept,             new HeaderInfo(HttpKnownHeaderNames.Accept,             true,   false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Authorization,      new HeaderInfo(HttpKnownHeaderNames.Authorization,      false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.AcceptRanges,       new HeaderInfo(HttpKnownHeaderNames.AcceptRanges,       false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.AcceptCharset,      new HeaderInfo(HttpKnownHeaderNames.AcceptCharset,      false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.AcceptEncoding,     new HeaderInfo(HttpKnownHeaderNames.AcceptEncoding,     false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.AcceptLanguage,     new HeaderInfo(HttpKnownHeaderNames.AcceptLanguage,     false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Cookie,             new HeaderInfo(HttpKnownHeaderNames.Cookie,             false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Connection,         new HeaderInfo(HttpKnownHeaderNames.Connection,         true,   false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ContentMD5,         new HeaderInfo(HttpKnownHeaderNames.ContentMD5,         false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.ContentType,        new HeaderInfo(HttpKnownHeaderNames.ContentType,        true,   false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.CacheControl,       new HeaderInfo(HttpKnownHeaderNames.CacheControl,       false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ContentRange,       new HeaderInfo(HttpKnownHeaderNames.ContentRange,       false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.ContentLength,      new HeaderInfo(HttpKnownHeaderNames.ContentLength,      true,   true,   false,  s_singleParser) },
+                { HttpKnownHeaderNames.ContentEncoding,    new HeaderInfo(HttpKnownHeaderNames.ContentEncoding,    false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ContentLanguage,    new HeaderInfo(HttpKnownHeaderNames.ContentLanguage,    false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ContentLocation,    new HeaderInfo(HttpKnownHeaderNames.ContentLocation,    false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Date,               new HeaderInfo(HttpKnownHeaderNames.Date,               true,   false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.ETag,               new HeaderInfo(HttpKnownHeaderNames.ETag,               false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Expect,             new HeaderInfo(HttpKnownHeaderNames.Expect,             true,   false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Expires,            new HeaderInfo(HttpKnownHeaderNames.Expires,            false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.From,               new HeaderInfo(HttpKnownHeaderNames.From,               false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Host,               new HeaderInfo(HttpKnownHeaderNames.Host,               true,   false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.IfMatch,            new HeaderInfo(HttpKnownHeaderNames.IfMatch,            false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.IfRange,            new HeaderInfo(HttpKnownHeaderNames.IfRange,            false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.IfNoneMatch,        new HeaderInfo(HttpKnownHeaderNames.IfNoneMatch,        false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.IfModifiedSince,    new HeaderInfo(HttpKnownHeaderNames.IfModifiedSince,    true,   false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.IfUnmodifiedSince,  new HeaderInfo(HttpKnownHeaderNames.IfUnmodifiedSince,  false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.KeepAlive,          new HeaderInfo(HttpKnownHeaderNames.KeepAlive,          false,  true,   false,  s_singleParser) },
+                { HttpKnownHeaderNames.Location,           new HeaderInfo(HttpKnownHeaderNames.Location,           false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.LastModified,       new HeaderInfo(HttpKnownHeaderNames.LastModified,       false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.MaxForwards,        new HeaderInfo(HttpKnownHeaderNames.MaxForwards,        false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Pragma,             new HeaderInfo(HttpKnownHeaderNames.Pragma,             false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ProxyAuthenticate,  new HeaderInfo(HttpKnownHeaderNames.ProxyAuthenticate,  false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ProxyAuthorization, new HeaderInfo(HttpKnownHeaderNames.ProxyAuthorization, false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.ProxyConnection,    new HeaderInfo(HttpKnownHeaderNames.ProxyConnection,    true,   false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Range,              new HeaderInfo(HttpKnownHeaderNames.Range,              true,   false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Referer,            new HeaderInfo(HttpKnownHeaderNames.Referer,            true,   false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.RetryAfter,         new HeaderInfo(HttpKnownHeaderNames.RetryAfter,         false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Server,             new HeaderInfo(HttpKnownHeaderNames.Server,             false,  false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.SetCookie,          new HeaderInfo(HttpKnownHeaderNames.SetCookie,          false,  false,  true,   s_setCookieParser) },
+                { HttpKnownHeaderNames.SetCookie2,         new HeaderInfo(HttpKnownHeaderNames.SetCookie2,         false,  false,  true,   s_setCookieParser) },
+                { HttpKnownHeaderNames.TE,                 new HeaderInfo(HttpKnownHeaderNames.TE,                 false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Trailer,            new HeaderInfo(HttpKnownHeaderNames.Trailer,            false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.TransferEncoding,   new HeaderInfo(HttpKnownHeaderNames.TransferEncoding,   true,   true,   true,   s_multiParser) },
+                { HttpKnownHeaderNames.Upgrade,            new HeaderInfo(HttpKnownHeaderNames.Upgrade,            false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.UserAgent,          new HeaderInfo(HttpKnownHeaderNames.UserAgent,          true,   false,  false,  s_singleParser) },
+                { HttpKnownHeaderNames.Via,                new HeaderInfo(HttpKnownHeaderNames.Via,                false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Vary,               new HeaderInfo(HttpKnownHeaderNames.Vary,               false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.Warning,            new HeaderInfo(HttpKnownHeaderNames.Warning,            false,  false,  true,   s_multiParser) },
+                { HttpKnownHeaderNames.WWWAuthenticate,    new HeaderInfo(HttpKnownHeaderNames.WWWAuthenticate,    false,  true,   true,   s_singleParser) }
             };
-
-            s_headerHashTable = new Hashtable(InfoArray.Length * 2, CaseInsensitiveAscii.StaticInstance);
-            for (int i = 0; i < InfoArray.Length; i++)
-            {
-                s_headerHashTable[InfoArray[i].HeaderName] = InfoArray[i];
-            }
+            Debug.Assert(headers.Count == Items);
+            return headers;
         }
 
         internal HeaderInfo this[string name]
index 65af7ca..4538401 100644 (file)
@@ -2,37 +2,27 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System;
-using System.Globalization;
-using System.IO;
 using System.Xml;
 
 namespace System.Runtime.Serialization
 {
     internal class Attributes
     {
-        private static XmlDictionaryString[] s_serializationLocalNames;
-
-        private static XmlDictionaryString[] s_schemaInstanceLocalNames;
-
-        static Attributes()
+        private static XmlDictionaryString[] s_serializationLocalNames = new XmlDictionaryString[]
         {
-            s_serializationLocalNames = new XmlDictionaryString[]
-            {
-                DictionaryGlobals.IdLocalName,
-                DictionaryGlobals.ArraySizeLocalName,
-                DictionaryGlobals.RefLocalName,
-                DictionaryGlobals.ClrTypeLocalName,
-                DictionaryGlobals.ClrAssemblyLocalName,
-                DictionaryGlobals.ISerializableFactoryTypeLocalName
-            };
+            DictionaryGlobals.IdLocalName,
+            DictionaryGlobals.ArraySizeLocalName,
+            DictionaryGlobals.RefLocalName,
+            DictionaryGlobals.ClrTypeLocalName,
+            DictionaryGlobals.ClrAssemblyLocalName,
+            DictionaryGlobals.ISerializableFactoryTypeLocalName
+        };
 
-            s_schemaInstanceLocalNames = new XmlDictionaryString[]
-            {
-                DictionaryGlobals.XsiNilLocalName,
-                DictionaryGlobals.XsiTypeLocalName
-            };
-        }
+        private static XmlDictionaryString[] s_schemaInstanceLocalNames = new XmlDictionaryString[]
+        {
+            DictionaryGlobals.XsiNilLocalName,
+            DictionaryGlobals.XsiTypeLocalName
+        };
 
         internal string Id;
         internal string Ref;
index 6fccc3a..8be38c2 100644 (file)
@@ -2,9 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System;
 using System.Xml;
-using System.Xml.Schema;
 
 namespace System.Runtime.Serialization
 {
@@ -14,174 +12,95 @@ namespace System.Runtime.Serialization
     internal static class DictionaryGlobals
 #endif
     {
-        public static readonly XmlDictionaryString EmptyString;
-        public static readonly XmlDictionaryString SchemaInstanceNamespace;
-        public static readonly XmlDictionaryString SchemaNamespace;
-        public static readonly XmlDictionaryString SerializationNamespace;
-        public static readonly XmlDictionaryString XmlnsNamespace;
-        public static readonly XmlDictionaryString XsiTypeLocalName;
-        public static readonly XmlDictionaryString XsiNilLocalName;
-        public static readonly XmlDictionaryString ClrTypeLocalName;
-        public static readonly XmlDictionaryString ClrAssemblyLocalName;
-        public static readonly XmlDictionaryString ArraySizeLocalName;
-        public static readonly XmlDictionaryString IdLocalName;
-        public static readonly XmlDictionaryString RefLocalName;
-        public static readonly XmlDictionaryString ISerializableFactoryTypeLocalName;
-        public static readonly XmlDictionaryString CharLocalName;
-        public static readonly XmlDictionaryString BooleanLocalName;
-        public static readonly XmlDictionaryString SignedByteLocalName;
-        public static readonly XmlDictionaryString UnsignedByteLocalName;
-        public static readonly XmlDictionaryString ShortLocalName;
-        public static readonly XmlDictionaryString UnsignedShortLocalName;
-        public static readonly XmlDictionaryString IntLocalName;
-        public static readonly XmlDictionaryString UnsignedIntLocalName;
-        public static readonly XmlDictionaryString LongLocalName;
-        public static readonly XmlDictionaryString UnsignedLongLocalName;
-        public static readonly XmlDictionaryString FloatLocalName;
-        public static readonly XmlDictionaryString DoubleLocalName;
-        public static readonly XmlDictionaryString DecimalLocalName;
-        public static readonly XmlDictionaryString DateTimeLocalName;
-        public static readonly XmlDictionaryString StringLocalName;
-        public static readonly XmlDictionaryString ByteArrayLocalName;
-        public static readonly XmlDictionaryString ObjectLocalName;
-        public static readonly XmlDictionaryString TimeSpanLocalName;
-        public static readonly XmlDictionaryString GuidLocalName;
-        public static readonly XmlDictionaryString UriLocalName;
-        public static readonly XmlDictionaryString QNameLocalName;
-        public static readonly XmlDictionaryString Space;
-
-        public static readonly XmlDictionaryString timeLocalName;
-        public static readonly XmlDictionaryString dateLocalName;
-        public static readonly XmlDictionaryString hexBinaryLocalName;
-        public static readonly XmlDictionaryString gYearMonthLocalName;
-        public static readonly XmlDictionaryString gYearLocalName;
-        public static readonly XmlDictionaryString gMonthDayLocalName;
-        public static readonly XmlDictionaryString gDayLocalName;
-        public static readonly XmlDictionaryString gMonthLocalName;
-        public static readonly XmlDictionaryString integerLocalName;
-        public static readonly XmlDictionaryString positiveIntegerLocalName;
-        public static readonly XmlDictionaryString negativeIntegerLocalName;
-        public static readonly XmlDictionaryString nonPositiveIntegerLocalName;
-        public static readonly XmlDictionaryString nonNegativeIntegerLocalName;
-        public static readonly XmlDictionaryString normalizedStringLocalName;
-        public static readonly XmlDictionaryString tokenLocalName;
-        public static readonly XmlDictionaryString languageLocalName;
-        public static readonly XmlDictionaryString NameLocalName;
-        public static readonly XmlDictionaryString NCNameLocalName;
-        public static readonly XmlDictionaryString XSDIDLocalName;
-        public static readonly XmlDictionaryString IDREFLocalName;
-        public static readonly XmlDictionaryString IDREFSLocalName;
-        public static readonly XmlDictionaryString ENTITYLocalName;
-        public static readonly XmlDictionaryString ENTITIESLocalName;
-        public static readonly XmlDictionaryString NMTOKENLocalName;
-        public static readonly XmlDictionaryString NMTOKENSLocalName;
-        public static readonly XmlDictionaryString AsmxTypesNamespace;
-
-        static DictionaryGlobals()
-        {
-            // Update array size when adding new strings or templates
-            XmlDictionary dictionary = new XmlDictionary(61);
-
-            try
-            {
-                // 0
-                SchemaInstanceNamespace = dictionary.Add(Globals.SchemaInstanceNamespace);
-                SerializationNamespace = dictionary.Add(Globals.SerializationNamespace);
-                SchemaNamespace = dictionary.Add(Globals.SchemaNamespace);
-                XsiTypeLocalName = dictionary.Add(Globals.XsiTypeLocalName);
-                XsiNilLocalName = dictionary.Add(Globals.XsiNilLocalName);
-
-                // 5
-                IdLocalName = dictionary.Add(Globals.IdLocalName);
-                RefLocalName = dictionary.Add(Globals.RefLocalName);
-                ArraySizeLocalName = dictionary.Add(Globals.ArraySizeLocalName);
-                EmptyString = dictionary.Add(string.Empty);
-                ISerializableFactoryTypeLocalName = dictionary.Add(Globals.ISerializableFactoryTypeLocalName);
-
-                // 10
-                XmlnsNamespace = dictionary.Add(Globals.XmlnsNamespace);
-                CharLocalName = dictionary.Add("char");
-                BooleanLocalName = dictionary.Add("boolean");
-                SignedByteLocalName = dictionary.Add("byte");
-                UnsignedByteLocalName = dictionary.Add("unsignedByte");
-
-                // 15
-                ShortLocalName = dictionary.Add("short");
-                UnsignedShortLocalName = dictionary.Add("unsignedShort");
-                IntLocalName = dictionary.Add("int");
-                UnsignedIntLocalName = dictionary.Add("unsignedInt");
-                LongLocalName = dictionary.Add("long");
-
-                // 20
-                UnsignedLongLocalName = dictionary.Add("unsignedLong");
-                FloatLocalName = dictionary.Add("float");
-                DoubleLocalName = dictionary.Add("double");
-                DecimalLocalName = dictionary.Add("decimal");
-                DateTimeLocalName = dictionary.Add("dateTime");
-
-                // 25
-                StringLocalName = dictionary.Add("string");
-                ByteArrayLocalName = dictionary.Add("base64Binary");
-                ObjectLocalName = dictionary.Add("anyType");
-                TimeSpanLocalName = dictionary.Add("duration");
-                GuidLocalName = dictionary.Add("guid");
-
-                // 30
-                UriLocalName = dictionary.Add("anyURI");
-                QNameLocalName = dictionary.Add("QName");
-                ClrTypeLocalName = dictionary.Add(Globals.ClrTypeLocalName);
-                ClrAssemblyLocalName = dictionary.Add(Globals.ClrAssemblyLocalName);
-                Space = dictionary.Add(Globals.Space);
-
-                // 35
-                timeLocalName = dictionary.Add("time");
-                dateLocalName = dictionary.Add("date");
-                hexBinaryLocalName = dictionary.Add("hexBinary");
-                gYearMonthLocalName = dictionary.Add("gYearMonth");
-                gYearLocalName = dictionary.Add("gYear");
-
-                // 40
-                gMonthDayLocalName = dictionary.Add("gMonthDay");
-                gDayLocalName = dictionary.Add("gDay");
-                gMonthLocalName = dictionary.Add("gMonth");
-                integerLocalName = dictionary.Add("integer");
-                positiveIntegerLocalName = dictionary.Add("positiveInteger");
-
-                // 45
-                negativeIntegerLocalName = dictionary.Add("negativeInteger");
-                nonPositiveIntegerLocalName = dictionary.Add("nonPositiveInteger");
-                nonNegativeIntegerLocalName = dictionary.Add("nonNegativeInteger");
-                normalizedStringLocalName = dictionary.Add("normalizedString");
-                tokenLocalName = dictionary.Add("token");
-
-                // 50
-                languageLocalName = dictionary.Add("language");
-                NameLocalName = dictionary.Add("Name");
-                NCNameLocalName = dictionary.Add("NCName");
-                XSDIDLocalName = dictionary.Add("ID");
-                IDREFLocalName = dictionary.Add("IDREF");
-
-                // 55
-                IDREFSLocalName = dictionary.Add("IDREFS");
-                ENTITYLocalName = dictionary.Add("ENTITY");
-                ENTITIESLocalName = dictionary.Add("ENTITIES");
-                NMTOKENLocalName = dictionary.Add("NMTOKEN");
-                NMTOKENSLocalName = dictionary.Add("NMTOKENS");
-
-                // 60
-                AsmxTypesNamespace = dictionary.Add("http://microsoft.com/wsdl/types/");
-
-                // Add new templates here
-            }
-            catch (Exception ex)
-            {
-                if (DiagnosticUtility.IsFatal(ex))
-                {
-                    throw;
-                }
-                throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
-            }
-        }
+        // Update array size when adding new strings or templates
+        private static readonly XmlDictionary s_dictionary = new XmlDictionary(61);
+
+        // 0
+        public static readonly XmlDictionaryString SchemaInstanceNamespace = s_dictionary.Add(Globals.SchemaInstanceNamespace);
+        public static readonly XmlDictionaryString SerializationNamespace = s_dictionary.Add(Globals.SerializationNamespace);
+        public static readonly XmlDictionaryString SchemaNamespace = s_dictionary.Add(Globals.SchemaNamespace);
+        public static readonly XmlDictionaryString XsiTypeLocalName = s_dictionary.Add(Globals.XsiTypeLocalName);
+        public static readonly XmlDictionaryString XsiNilLocalName = s_dictionary.Add(Globals.XsiNilLocalName);
+
+        // 5
+        public static readonly XmlDictionaryString IdLocalName = s_dictionary.Add(Globals.IdLocalName);
+        public static readonly XmlDictionaryString RefLocalName = s_dictionary.Add(Globals.RefLocalName);
+        public static readonly XmlDictionaryString ArraySizeLocalName = s_dictionary.Add(Globals.ArraySizeLocalName);
+        public static readonly XmlDictionaryString EmptyString = s_dictionary.Add(string.Empty);
+        public static readonly XmlDictionaryString ISerializableFactoryTypeLocalName = s_dictionary.Add(Globals.ISerializableFactoryTypeLocalName);
+
+        // 10
+        public static readonly XmlDictionaryString XmlnsNamespace = s_dictionary.Add(Globals.XmlnsNamespace);
+        public static readonly XmlDictionaryString CharLocalName = s_dictionary.Add("char");
+        public static readonly XmlDictionaryString BooleanLocalName = s_dictionary.Add("boolean");
+        public static readonly XmlDictionaryString SignedByteLocalName = s_dictionary.Add("byte");
+        public static readonly XmlDictionaryString UnsignedByteLocalName = s_dictionary.Add("unsignedByte");
+
+        // 15
+        public static readonly XmlDictionaryString ShortLocalName = s_dictionary.Add("short");
+        public static readonly XmlDictionaryString UnsignedShortLocalName = s_dictionary.Add("unsignedShort");
+        public static readonly XmlDictionaryString IntLocalName = s_dictionary.Add("int");
+        public static readonly XmlDictionaryString UnsignedIntLocalName = s_dictionary.Add("unsignedInt");
+        public static readonly XmlDictionaryString LongLocalName = s_dictionary.Add("long");
+
+        // 20
+        public static readonly XmlDictionaryString UnsignedLongLocalName = s_dictionary.Add("unsignedLong");
+        public static readonly XmlDictionaryString FloatLocalName = s_dictionary.Add("float");
+        public static readonly XmlDictionaryString DoubleLocalName = s_dictionary.Add("double");
+        public static readonly XmlDictionaryString DecimalLocalName = s_dictionary.Add("decimal");
+        public static readonly XmlDictionaryString DateTimeLocalName = s_dictionary.Add("dateTime");
+
+        // 25
+        public static readonly XmlDictionaryString StringLocalName = s_dictionary.Add("string");
+        public static readonly XmlDictionaryString ByteArrayLocalName = s_dictionary.Add("base64Binary");
+        public static readonly XmlDictionaryString ObjectLocalName = s_dictionary.Add("anyType");
+        public static readonly XmlDictionaryString TimeSpanLocalName = s_dictionary.Add("duration");
+        public static readonly XmlDictionaryString GuidLocalName = s_dictionary.Add("guid");
+
+        // 30
+        public static readonly XmlDictionaryString UriLocalName = s_dictionary.Add("anyURI");
+        public static readonly XmlDictionaryString QNameLocalName = s_dictionary.Add("QName");
+        public static readonly XmlDictionaryString ClrTypeLocalName = s_dictionary.Add(Globals.ClrTypeLocalName);
+        public static readonly XmlDictionaryString ClrAssemblyLocalName = s_dictionary.Add(Globals.ClrAssemblyLocalName);
+        public static readonly XmlDictionaryString Space = s_dictionary.Add(Globals.Space);
+
+        // 35
+        public static readonly XmlDictionaryString timeLocalName = s_dictionary.Add("time");
+        public static readonly XmlDictionaryString dateLocalName = s_dictionary.Add("date");
+        public static readonly XmlDictionaryString hexBinaryLocalName = s_dictionary.Add("hexBinary");
+        public static readonly XmlDictionaryString gYearMonthLocalName = s_dictionary.Add("gYearMonth");
+        public static readonly XmlDictionaryString gYearLocalName = s_dictionary.Add("gYear");
+        
+        // 40
+        public static readonly XmlDictionaryString gMonthDayLocalName = s_dictionary.Add("gMonthDay");
+        public static readonly XmlDictionaryString gDayLocalName = s_dictionary.Add("gDay");
+        public static readonly XmlDictionaryString gMonthLocalName = s_dictionary.Add("gMonth");
+        public static readonly XmlDictionaryString integerLocalName = s_dictionary.Add("integer");
+        public static readonly XmlDictionaryString positiveIntegerLocalName = s_dictionary.Add("positiveInteger");
+        
+        // 45
+        public static readonly XmlDictionaryString negativeIntegerLocalName = s_dictionary.Add("negativeInteger");
+        public static readonly XmlDictionaryString nonPositiveIntegerLocalName = s_dictionary.Add("nonPositiveInteger");
+        public static readonly XmlDictionaryString nonNegativeIntegerLocalName = s_dictionary.Add("nonNegativeInteger");
+        public static readonly XmlDictionaryString normalizedStringLocalName = s_dictionary.Add("normalizedString");
+        public static readonly XmlDictionaryString tokenLocalName = s_dictionary.Add("token");
+        
+        // 50
+        public static readonly XmlDictionaryString languageLocalName = s_dictionary.Add("language");
+        public static readonly XmlDictionaryString NameLocalName = s_dictionary.Add("Name");
+        public static readonly XmlDictionaryString NCNameLocalName = s_dictionary.Add("NCName");
+        public static readonly XmlDictionaryString XSDIDLocalName = s_dictionary.Add("ID");
+        public static readonly XmlDictionaryString IDREFLocalName = s_dictionary.Add("IDREF");
+
+        // 55
+        public static readonly XmlDictionaryString IDREFSLocalName = s_dictionary.Add("IDREFS");
+        public static readonly XmlDictionaryString ENTITYLocalName = s_dictionary.Add("ENTITY");
+        public static readonly XmlDictionaryString ENTITIESLocalName = s_dictionary.Add("ENTITIES");
+        public static readonly XmlDictionaryString NMTOKENLocalName = s_dictionary.Add("NMTOKEN");
+        public static readonly XmlDictionaryString NMTOKENSLocalName = s_dictionary.Add("NMTOKENS");
+        
+        // 60
+        public static readonly XmlDictionaryString AsmxTypesNamespace = s_dictionary.Add("http://microsoft.com/wsdl/types/");
     }
 }
 
index 67af292..09e48e7 100644 (file)
@@ -73,8 +73,8 @@ namespace System.Runtime.Serialization
 
         private class EnumDataContractCriticalHelper : DataContract.DataContractCriticalHelper
         {
-            private static Dictionary<Type, XmlQualifiedName> s_typeToName;
-            private static Dictionary<XmlQualifiedName, Type> s_nameToType;
+            private static readonly Dictionary<Type, XmlQualifiedName> s_typeToName = new Dictionary<Type, XmlQualifiedName>();
+            private static readonly Dictionary<XmlQualifiedName, Type> s_nameToType = new Dictionary<XmlQualifiedName, Type>();
 
             private List<DataMember> _members;
             private List<long> _values;
@@ -85,8 +85,6 @@ namespace System.Runtime.Serialization
 
             static EnumDataContractCriticalHelper()
             {
-                s_typeToName = new Dictionary<Type, XmlQualifiedName>();
-                s_nameToType = new Dictionary<XmlQualifiedName, Type>();
                 Add(typeof(sbyte), "byte");
                 Add(typeof(byte), "unsignedByte");
                 Add(typeof(short), "short");
index e4db899..994695d 100644 (file)
@@ -45,14 +45,12 @@ namespace System.Runtime.Serialization
 
         private XmlObjectSerializerReadContext _context;
 
-        private static Hashtable s_nsToPrefixTable;
+        private static readonly Hashtable s_nsToPrefixTable = new Hashtable();
 
-        private static Hashtable s_prefixToNsTable;
+        private static readonly Hashtable s_prefixToNsTable = new Hashtable();
 
         static ExtensionDataReader()
         {
-            s_nsToPrefixTable = new Hashtable();
-            s_prefixToNsTable = new Hashtable();
             AddPrefix(Globals.XsiPrefix, Globals.SchemaInstanceNamespace);
             AddPrefix(Globals.SerPrefix, Globals.SerializationNamespace);
             AddPrefix(string.Empty, string.Empty);
index 19315c6..773e72c 100644 (file)
@@ -2,14 +2,17 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+using System.ComponentModel;
+using System.Xml.Serialization;
+
 namespace System.Xml.Schema
 {
-    using System.Collections;
-    using System.ComponentModel;
-    using System.Xml.Serialization;
-
     public class XmlSchemaComplexType : XmlSchemaType
     {
+        private static readonly XmlSchemaComplexType s_anyTypeLax = CreateAnyType(XmlSchemaContentProcessing.Lax);
+        private static readonly XmlSchemaComplexType s_anyTypeSkip = CreateAnyType(XmlSchemaContentProcessing.Skip);
+        private static readonly XmlSchemaComplexType s_untypedAnyType = CreateUntypedAnyType();
+
         private XmlSchemaDerivationMethod _block = XmlSchemaDerivationMethod.None;
 
         private XmlSchemaContentModel _contentModel;
@@ -23,9 +26,6 @@ namespace System.Xml.Schema
         private XmlSchemaObjectTable _attributeUses;
         private XmlSchemaAnyAttribute _attributeWildcard;
 
-        private static XmlSchemaComplexType s_anyTypeLax;
-        private static XmlSchemaComplexType s_anyTypeSkip;
-        private static XmlSchemaComplexType s_untypedAnyType;
 
         //additional info for Partial validation
         private byte _pvFlags;
@@ -34,21 +34,21 @@ namespace System.Xml.Schema
         private const byte isAbstractMask = 0x04;
         //const byte dupDeclMask = 0x08;
 
-        static XmlSchemaComplexType()
+        private static XmlSchemaComplexType CreateUntypedAnyType()
         {
-            s_anyTypeLax = CreateAnyType(XmlSchemaContentProcessing.Lax);
-            s_anyTypeSkip = CreateAnyType(XmlSchemaContentProcessing.Skip);
-
             // Create xdt:untypedAny
-            s_untypedAnyType = new XmlSchemaComplexType();
-            s_untypedAnyType.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
-            s_untypedAnyType.IsMixed = true;
-            s_untypedAnyType.SetContentTypeParticle(s_anyTypeLax.ContentTypeParticle);
-            s_untypedAnyType.SetContentType(XmlSchemaContentType.Mixed);
-
-            s_untypedAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
-            s_untypedAnyType.ElementDecl.SchemaType = s_untypedAnyType;
-            s_untypedAnyType.ElementDecl.ContentValidator = AnyTypeContentValidator;
+            var untypedAny = new XmlSchemaComplexType();
+
+            untypedAny.SetQualifiedName(new XmlQualifiedName("untypedAny", XmlReservedNs.NsXQueryDataType));
+            untypedAny.IsMixed = true;
+            untypedAny.SetContentTypeParticle(s_anyTypeLax.ContentTypeParticle);
+            untypedAny.SetContentType(XmlSchemaContentType.Mixed);
+
+            untypedAny.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl();
+            untypedAny.ElementDecl.SchemaType = untypedAny;
+            untypedAny.ElementDecl.ContentValidator = AnyTypeContentValidator;
+
+            return untypedAny;
         }
 
         private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents)
index 3d5a9d1..a690dac 100644 (file)
@@ -397,25 +397,22 @@ namespace System.Xml.Xsl.IlGen
         // Miscellaneous
         public static readonly MethodInfo GetTypeFromHandle = GetMethod(typeof(Type), "GetTypeFromHandle");
         public static readonly MethodInfo InitializeArray = GetMethod(typeof(System.Runtime.CompilerServices.RuntimeHelpers), "InitializeArray");
-        public static readonly Dictionary<Type, XmlILStorageMethods> StorageMethods;
-
-        static XmlILMethods()
-        {
-            StorageMethods = new Dictionary<Type, XmlILStorageMethods>();
-            StorageMethods[typeof(string)] = new XmlILStorageMethods(typeof(string));
-            StorageMethods[typeof(bool)] = new XmlILStorageMethods(typeof(bool));
-            StorageMethods[typeof(int)] = new XmlILStorageMethods(typeof(int));
-            StorageMethods[typeof(long)] = new XmlILStorageMethods(typeof(long));
-            StorageMethods[typeof(decimal)] = new XmlILStorageMethods(typeof(decimal));
-            StorageMethods[typeof(double)] = new XmlILStorageMethods(typeof(double));
-            StorageMethods[typeof(float)] = new XmlILStorageMethods(typeof(float));
-            StorageMethods[typeof(DateTime)] = new XmlILStorageMethods(typeof(DateTime));
-            StorageMethods[typeof(byte[])] = new XmlILStorageMethods(typeof(byte[]));
-            StorageMethods[typeof(XmlQualifiedName)] = new XmlILStorageMethods(typeof(XmlQualifiedName));
-            StorageMethods[typeof(TimeSpan)] = new XmlILStorageMethods(typeof(TimeSpan));
-            StorageMethods[typeof(XPathItem)] = new XmlILStorageMethods(typeof(XPathItem));
-            StorageMethods[typeof(XPathNavigator)] = new XmlILStorageMethods(typeof(XPathNavigator));
-        }
+        public static readonly Dictionary<Type, XmlILStorageMethods> StorageMethods = new Dictionary<Type, XmlILStorageMethods>(13)
+        {
+            { typeof(string), new XmlILStorageMethods(typeof(string)) },
+            { typeof(bool), new XmlILStorageMethods(typeof(bool)) },
+            { typeof(int), new XmlILStorageMethods(typeof(int)) },
+            { typeof(long), new XmlILStorageMethods(typeof(long)) },
+            { typeof(decimal), new XmlILStorageMethods(typeof(decimal)) },
+            { typeof(double), new XmlILStorageMethods(typeof(double)) },
+            { typeof(float), new XmlILStorageMethods(typeof(float)) },
+            { typeof(DateTime), new XmlILStorageMethods(typeof(DateTime)) },
+            { typeof(byte[]), new XmlILStorageMethods(typeof(byte[])) },
+            { typeof(XmlQualifiedName), new XmlILStorageMethods(typeof(XmlQualifiedName)) },
+            { typeof(TimeSpan), new XmlILStorageMethods(typeof(TimeSpan)) },
+            { typeof(XPathItem), new XmlILStorageMethods(typeof(XPathItem)) },
+            { typeof(XPathNavigator), new XmlILStorageMethods(typeof(XPathNavigator)) },
+        };
 
         public static MethodInfo GetMethod(Type className, string methName)
         {
index 1ca3441..0a568e4 100644 (file)
@@ -24,7 +24,7 @@ namespace System.Xml.Xsl.IlGen
     internal class XmlILModule
     {
         private static long s_assemblyId;                                     // Unique identifier used to ensure that assembly names are unique within AppDomain
-        private static ModuleBuilder s_LREModule;                             // Module used to emit dynamic lightweight-reflection-emit (LRE) methods
+        private static ModuleBuilder s_LREModule = CreateLREModule();         // Module used to emit dynamic lightweight-reflection-emit (LRE) methods
 
         private TypeBuilder _typeBldr;
         private Hashtable _methods;
@@ -34,32 +34,21 @@ namespace System.Xml.Xsl.IlGen
         private static readonly Guid s_vendorGuid = new Guid(0x994b45c4, 0xe6e9, 0x11d2, 0x90, 0x3f, 0x00, 0xc0, 0x4f, 0xa3, 0x02, 0xa1);
         private const string RuntimeName = "{" + XmlReservedNs.NsXslDebug + "}" + "runtime";
 
-        static XmlILModule()
+        private static ModuleBuilder CreateLREModule()
         {
-            AssemblyName asmName;
-            AssemblyBuilder asmBldr;
-
-            s_assemblyId = 0;
-
             // 1. LRE assembly only needs to execute
             // 2. No temp files need be created
             // 3. Never allow assembly to Assert permissions
-            asmName = CreateAssemblyName();
-            asmBldr = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
+            AssemblyName asmName = CreateAssemblyName();
+            AssemblyBuilder asmBldr = AssemblyBuilder.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
 
-            try
-            {
-                // Add custom attribute to assembly marking it as security transparent so that Assert will not be allowed
-                // and link demands will be converted to full demands.
-                asmBldr.SetCustomAttribute(new CustomAttributeBuilder(XmlILConstructors.Transparent, Array.Empty<object>()));
+            // Add custom attribute to assembly marking it as security transparent so that Assert will not be allowed
+            // and link demands will be converted to full demands.
+            asmBldr.SetCustomAttribute(new CustomAttributeBuilder(XmlILConstructors.Transparent, Array.Empty<object>()));
 
-                // Store LREModule once.  If multiple threads are doing this, then some threads might get different
-                // modules.  This is OK, since it's not mandatory to share, just preferable.
-                s_LREModule = asmBldr.DefineDynamicModule("System.Xml.Xsl.CompiledQuery");
-            }
-            finally
-            {
-            }
+            // Store LREModule once.  If multiple threads are doing this, then some threads might get different
+            // modules.  This is OK, since it's not mandatory to share, just preferable.
+            return asmBldr.DefineDynamicModule("System.Xml.Xsl.CompiledQuery");
         }
 
         public XmlILModule(TypeBuilder typeBldr)
index 11f340c..af55c7b 100644 (file)
@@ -13,7 +13,12 @@ namespace System.Xml.Xsl.IlGen
 {
     internal class XmlILOptimizerVisitor : QilPatternVisitor
     {
-        private static readonly QilPatterns s_patternsNoOpt, s_patternsOpt;
+        private static readonly QilPatterns s_patternsNoOpt = CreatePatternsNoOpt();
+
+        // Enable all normalizations and annotations for Release code
+        // Enable all patterns for Release code
+        private static readonly QilPatterns s_patternsOpt = new QilPatterns((int)XmlILOptimization.Last_, allSet: true);
+
         private QilExpression _qil;
         private XmlILElementAnalyzer _elemAnalyzer;
         private XmlILStateAnalyzer _contentAnalyzer;
@@ -21,42 +26,40 @@ namespace System.Xml.Xsl.IlGen
         private NodeCounter _nodeCounter = new NodeCounter();
         private SubstitutionList _subs = new SubstitutionList();
 
-        static XmlILOptimizerVisitor()
+        private static QilPatterns CreatePatternsNoOpt()
         {
-            // Enable all normalizations and annotations for Release code
-            // Enable all patterns for Release code
-            s_patternsOpt = new QilPatterns((int)XmlILOptimization.Last_, true);
-
             // Only enable Required and OptimizedConstruction pattern groups
             // Only enable Required patterns
-            s_patternsNoOpt = new QilPatterns((int)XmlILOptimization.Last_, false);
-
-            s_patternsNoOpt.Add((int)XmlILOptimization.FoldNone);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminatePositionOf);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateTypeAssert);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateIsType);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateIsEmpty);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateAverage);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateSum);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateMinimum);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateMaximum);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateSort);
-            s_patternsNoOpt.Add((int)XmlILOptimization.EliminateStrConcatSingle);
-
-            s_patternsNoOpt.Add((int)XmlILOptimization.NormalizeUnion);
-            s_patternsNoOpt.Add((int)XmlILOptimization.NormalizeIntersect);
-            s_patternsNoOpt.Add((int)XmlILOptimization.NormalizeDifference);
-
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotatePositionalIterator);
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateTrackCallers);
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateDod);
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateConstruction);
+            var patterns = new QilPatterns((int)XmlILOptimization.Last_, allSet: false);
+
+            patterns.Add((int)XmlILOptimization.FoldNone);
+            patterns.Add((int)XmlILOptimization.EliminatePositionOf);
+            patterns.Add((int)XmlILOptimization.EliminateTypeAssert);
+            patterns.Add((int)XmlILOptimization.EliminateIsType);
+            patterns.Add((int)XmlILOptimization.EliminateIsEmpty);
+            patterns.Add((int)XmlILOptimization.EliminateAverage);
+            patterns.Add((int)XmlILOptimization.EliminateSum);
+            patterns.Add((int)XmlILOptimization.EliminateMinimum);
+            patterns.Add((int)XmlILOptimization.EliminateMaximum);
+            patterns.Add((int)XmlILOptimization.EliminateSort);
+            patterns.Add((int)XmlILOptimization.EliminateStrConcatSingle);
+
+            patterns.Add((int)XmlILOptimization.NormalizeUnion);
+            patterns.Add((int)XmlILOptimization.NormalizeIntersect);
+            patterns.Add((int)XmlILOptimization.NormalizeDifference);
+
+            patterns.Add((int)XmlILOptimization.AnnotatePositionalIterator);
+            patterns.Add((int)XmlILOptimization.AnnotateTrackCallers);
+            patterns.Add((int)XmlILOptimization.AnnotateDod);
+            patterns.Add((int)XmlILOptimization.AnnotateConstruction);
 
             // Enable indexes in debug mode
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateIndex1);
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateIndex2);
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateBarrier);
-            s_patternsNoOpt.Add((int)XmlILOptimization.AnnotateFilter);
+            patterns.Add((int)XmlILOptimization.AnnotateIndex1);
+            patterns.Add((int)XmlILOptimization.AnnotateIndex2);
+            patterns.Add((int)XmlILOptimization.AnnotateBarrier);
+            patterns.Add((int)XmlILOptimization.AnnotateFilter);
+
+            return patterns;
         }
 
         public XmlILOptimizerVisitor(QilExpression qil, bool optimize) : base(optimize ? s_patternsOpt : s_patternsNoOpt, qil.Factory)
index e5f4eb8..56dc311 100644 (file)
@@ -271,7 +271,7 @@ namespace System.Xml.Xsl.Qil
         /// </summary>
         sealed internal class QilPatterns
         {
-            private BitArray _bits;
+            private readonly BitArray _bits;
 
             public QilPatterns(int szBits, bool allSet)
             {
index 2e0772a..3ac5ec7 100644 (file)
@@ -135,20 +135,21 @@ namespace System.Xml.Xsl.Runtime
     /// </summary>
     internal class XmlNavTypeFilter : XmlNavigatorFilter
     {
-        private static XmlNavigatorFilter[] s_typeFilters;
+        private static readonly XmlNavigatorFilter[] s_typeFilters = CreateTypeFilters();
         private XPathNodeType _nodeType;
         private int _mask;
 
         /// <summary>
         /// There are a limited number of types, so create all possible XmlNavTypeFilter objects just once.
         /// </summary>
-        static XmlNavTypeFilter()
+        private static XmlNavigatorFilter[] CreateTypeFilters()
         {
-            s_typeFilters = new XmlNavigatorFilter[(int)XPathNodeType.Comment + 1];
-            s_typeFilters[(int)XPathNodeType.Element] = new XmlNavTypeFilter(XPathNodeType.Element);
-            s_typeFilters[(int)XPathNodeType.Text] = new XmlNavTypeFilter(XPathNodeType.Text);
-            s_typeFilters[(int)XPathNodeType.ProcessingInstruction] = new XmlNavTypeFilter(XPathNodeType.ProcessingInstruction);
-            s_typeFilters[(int)XPathNodeType.Comment] = new XmlNavTypeFilter(XPathNodeType.Comment);
+            var filters = new XmlNavigatorFilter[(int)XPathNodeType.Comment + 1];
+            filters[(int)XPathNodeType.Element] = new XmlNavTypeFilter(XPathNodeType.Element);
+            filters[(int)XPathNodeType.Text] = new XmlNavTypeFilter(XPathNodeType.Text);
+            filters[(int)XPathNodeType.ProcessingInstruction] = new XmlNavTypeFilter(XPathNodeType.ProcessingInstruction);
+            filters[(int)XPathNodeType.Comment] = new XmlNavTypeFilter(XPathNodeType.Comment);
+            return filters;
         }
 
         /// <summary>
index 6fc5f4e..f87a47d 100644 (file)
@@ -20,34 +20,8 @@ namespace System.Xml.Xsl
     /// </summary>
     internal abstract class XmlQueryType : ListBase<XmlQueryType>
     {
-        private static readonly BitMatrix s_typeCodeDerivation;
         private int _hashCode;
 
-
-        //-----------------------------------------------
-        // Static Constructor
-        //-----------------------------------------------
-        static XmlQueryType()
-        {
-            s_typeCodeDerivation = new BitMatrix(s_baseTypeCodes.Length);
-
-            // Build derivation matrix
-            for (int i = 0; i < s_baseTypeCodes.Length; i++)
-            {
-                int nextAncestor = i;
-
-                while (true)
-                {
-                    s_typeCodeDerivation[i, nextAncestor] = true;
-                    if ((int)s_baseTypeCodes[nextAncestor] == nextAncestor)
-                        break;
-
-                    nextAncestor = (int)s_baseTypeCodes[nextAncestor];
-                }
-            }
-        }
-
-
         //-----------------------------------------------
         // ItemType, OccurrenceIndicator Properties
         //-----------------------------------------------
@@ -871,6 +845,29 @@ namespace System.Xml.Xsl
             /* YearMonthDuration           */ "xdt:yearMonthDuration",
             /* DayTimeDuration             */ "xdt:dayTimeDuration",
         };
+
+        private static readonly BitMatrix s_typeCodeDerivation = CreateTypeCodeDerivation();
+
+        private static BitMatrix CreateTypeCodeDerivation()
+        {
+            var matrix = new BitMatrix(s_baseTypeCodes.Length);
+
+            for (int i = 0; i < s_baseTypeCodes.Length; i++)
+            {
+                int nextAncestor = i;
+
+                while (true)
+                {
+                    matrix[i, nextAncestor] = true;
+                    if ((int)s_baseTypeCodes[nextAncestor] == nextAncestor)
+                        break;
+
+                    nextAncestor = (int)s_baseTypeCodes[nextAncestor];
+                }
+            }
+
+            return matrix;
+        }
         #endregion
 
         /// <summary>
index f906e21..92c5660 100644 (file)
@@ -341,6 +341,7 @@ namespace System.Xml.Xsl
             private bool _isStrict;
             private bool _isNotRtf;
 
+#pragma warning disable CA1810 // explicit static cctor
             /// <summary>
             /// Construct arrays of built-in types.
             /// </summary>
@@ -415,6 +416,7 @@ namespace System.Xml.Xsl
 
                 s_specialBuiltInItemTypes = new XmlQueryType[4] { UntypedDocument, UntypedElement, UntypedAttribute, NodeNotRtf };
             }
+#pragma warning restore CA1810
 
             /// <summary>
             /// Create ItemType from XmlTypeCode.
index e77cd96..9480ee9 100644 (file)
@@ -183,6 +183,7 @@ namespace System.Reflection.Runtime.BindingFlagSupport
             return false;
         }
 
+#pragma warning disable CA1810 // explicit static cctor
         static MemberPolicies()
         {
             Type t = typeof(M);
@@ -221,6 +222,7 @@ namespace System.Reflection.Runtime.BindingFlagSupport
                 Debug.Fail("Unknown MemberInfo type.");
             }
         }
+#pragma warning restore CA1810
 
         //
         // This is a singleton class one for each MemberInfo category: Return the appropriate one. 
index 07ed012..f6a80fe 100644 (file)
@@ -10,55 +10,42 @@ namespace System.Runtime.Caching.Configuration
 {
     internal sealed class MemoryCacheElement : ConfigurationElement
     {
-        private static ConfigurationPropertyCollection s_properties;
-        private static readonly ConfigurationProperty s_propName;
-        private static readonly ConfigurationProperty s_propPhysicalMemoryLimitPercentage;
-        private static readonly ConfigurationProperty s_propCacheMemoryLimitMegabytes;
-        private static readonly ConfigurationProperty s_propPollingInterval;
-
-        static MemoryCacheElement()
+        private static readonly ConfigurationProperty s_propName =
+            new ConfigurationProperty("name",
+                typeof(string),
+                null,
+                new WhiteSpaceTrimStringConverter(),
+                new StringValidator(1),
+                ConfigurationPropertyOptions.IsRequired |
+                ConfigurationPropertyOptions.IsKey);
+        private static readonly ConfigurationProperty s_propPhysicalMemoryLimitPercentage =
+            new ConfigurationProperty("physicalMemoryLimitPercentage",
+                typeof(int),
+                (int)0,
+                null,
+                new IntegerValidator(0, 100),
+                ConfigurationPropertyOptions.None);
+        private static readonly ConfigurationProperty s_propCacheMemoryLimitMegabytes =
+            new ConfigurationProperty("cacheMemoryLimitMegabytes",
+                typeof(int),
+                (int)0,
+                null,
+                new IntegerValidator(0, int.MaxValue),
+                ConfigurationPropertyOptions.None);
+        private static readonly ConfigurationProperty s_propPollingInterval =
+            new ConfigurationProperty("pollingInterval",
+                typeof(TimeSpan),
+                TimeSpan.FromMilliseconds(ConfigUtil.DefaultPollingTimeMilliseconds),
+                new InfiniteTimeSpanConverter(),
+                new PositiveTimeSpanValidator(),
+                ConfigurationPropertyOptions.None);
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection()
         {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-
-            s_propName =
-                new ConfigurationProperty("name",
-                                          typeof(string),
-                                          null,
-                                          new WhiteSpaceTrimStringConverter(),
-                                          new StringValidator(1),
-                                          ConfigurationPropertyOptions.IsRequired |
-                                          ConfigurationPropertyOptions.IsKey);
-
-            s_propPhysicalMemoryLimitPercentage =
-                new ConfigurationProperty("physicalMemoryLimitPercentage",
-                                          typeof(int),
-                                          (int)0,
-                                          null,
-                                          new IntegerValidator(0, 100),
-                                          ConfigurationPropertyOptions.None);
-
-            s_propCacheMemoryLimitMegabytes =
-                new ConfigurationProperty("cacheMemoryLimitMegabytes",
-                                          typeof(int),
-                                          (int)0,
-                                          null,
-                                          new IntegerValidator(0, int.MaxValue),
-                                          ConfigurationPropertyOptions.None);
-
-            s_propPollingInterval =
-                new ConfigurationProperty("pollingInterval",
-                                          typeof(TimeSpan),
-                                          TimeSpan.FromMilliseconds(ConfigUtil.DefaultPollingTimeMilliseconds),
-                                          new InfiniteTimeSpanConverter(),
-                                          new PositiveTimeSpanValidator(),
-                                          ConfigurationPropertyOptions.None);
-
-            s_properties.Add(s_propName);
-            s_properties.Add(s_propPhysicalMemoryLimitPercentage);
-            s_properties.Add(s_propCacheMemoryLimitMegabytes);
-            s_properties.Add(s_propPollingInterval);
-        }
+            s_propName,
+            s_propPhysicalMemoryLimitPercentage,
+            s_propCacheMemoryLimitMegabytes,
+            s_propPollingInterval
+        };
 
         internal MemoryCacheElement()
         {
index 20b8cc6..2444fb6 100644 (file)
@@ -23,19 +23,11 @@ namespace System.Runtime.Caching.Configuration
 
     internal sealed class MemoryCacheSection : ConfigurationSection
     {
-        private static ConfigurationPropertyCollection s_properties;
-        private static readonly ConfigurationProperty s_propNamedCaches;
-
-        static MemoryCacheSection()
-        {
-            s_propNamedCaches = new ConfigurationProperty("namedCaches",
-                                            typeof(MemoryCacheSettingsCollection),
-                                            null, // defaultValue
-                                            ConfigurationPropertyOptions.None);
-
-            s_properties = new ConfigurationPropertyCollection();
-            s_properties.Add(s_propNamedCaches);
-        }
+        private static readonly ConfigurationProperty s_propNamedCaches = new ConfigurationProperty("namedCaches",
+            typeof(MemoryCacheSettingsCollection),
+            null, // defaultValue
+            ConfigurationPropertyOptions.None);
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection() { s_propNamedCaches };
 
         public MemoryCacheSection()
         {
index ba97662..785bfb0 100644 (file)
@@ -11,13 +11,7 @@ namespace System.Runtime.Caching.Configuration
     CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
     internal sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection
     {
-        private static ConfigurationPropertyCollection s_properties;
-
-        static MemoryCacheSettingsCollection()
-        {
-            // Property initialization
-            s_properties = new ConfigurationPropertyCollection();
-        }
+        private static readonly ConfigurationPropertyCollection s_properties = new ConfigurationPropertyCollection();
 
         protected override ConfigurationPropertyCollection Properties
         {
index d488206..1c384a9 100644 (file)
@@ -12,6 +12,7 @@ namespace System.Runtime.Caching
 {
     internal abstract partial class MemoryMonitor
     {
+#pragma warning disable CA1810 // explicit static cctor
         static MemoryMonitor()
         {
             Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
@@ -22,5 +23,6 @@ namespace System.Runtime.Caching
                 s_totalVirtual = (long)memoryStatusEx.ullTotalVirtual;
             }
         }
+#pragma warning restore CA1810
     }
 }
index aba3745..d741a49 100644 (file)
@@ -21,20 +21,13 @@ namespace System.Diagnostics
         // if one exists. Otherwise it will store TicksPerSecond. 
         // The frequency cannot change while the system is running,
         // so we only need to initialize it once. 
-        public static readonly long Frequency;
-        public static readonly bool IsHighResolution;
+        public static readonly long Frequency = QueryPerformanceFrequency();
+        public static readonly bool IsHighResolution = true;
 
         // performance-counter frequency, in counts per ticks.
         // This can speed up conversion from high frequency performance-counter 
         // to ticks. 
-        private static readonly double s_tickFrequency;
-
-        static Stopwatch()
-        {
-            Frequency = QueryPerformanceFrequency();
-            IsHighResolution = true;
-            s_tickFrequency = (double)TicksPerSecond / Frequency;
-        }
+        private static readonly double s_tickFrequency = (double)TicksPerSecond / Frequency;
 
         public Stopwatch()
         {
index 40eeddc..a9821ab 100644 (file)
@@ -265,42 +265,24 @@ namespace System.Security.Cryptography
 
             private static class Functions
             {
-                private static readonly Func<string, object> s_xDocumentCreate;
-                private static readonly PropertyInfo s_docRootProperty;
-                private static readonly MethodInfo s_getElementsMethod;
-                private static readonly PropertyInfo s_elementNameProperty;
-                private static readonly PropertyInfo s_nameNameProperty;
-                private static readonly PropertyInfo s_elementValueProperty;
-
-                static Functions()
-                {
-                    Type xDocument =
-                        Type.GetType(
-                            "System.Xml.Linq.XDocument, System.Private.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51");
-
-                    MethodInfo docCreateMethod = xDocument.GetMethod(
+                private static readonly Type s_xDocument = Type.GetType("System.Xml.Linq.XDocument, System.Private.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51");
+                private static readonly Func<string, object> s_xDocumentCreate =
+                    (Func<string, object>)s_xDocument.GetMethod(
                         "Parse",
                         BindingFlags.Static | BindingFlags.Public,
                         null,
                         new[] { typeof(string) },
-                        null);
-
-                    s_xDocumentCreate =
-                        (Func<string, object>)docCreateMethod.CreateDelegate(typeof(Func<string, object>));
-
-                    s_docRootProperty = xDocument.GetProperty("Root");
-
-                    s_getElementsMethod = s_docRootProperty.PropertyType.GetMethod(
+                        null).CreateDelegate(typeof(Func<string, object>));
+                private static readonly PropertyInfo s_docRootProperty = s_xDocument.GetProperty("Root");
+                private static readonly MethodInfo s_getElementsMethod = s_docRootProperty.PropertyType.GetMethod(
                         "Elements",
                         BindingFlags.Instance | BindingFlags.Public,
                         null,
                         Array.Empty<Type>(),
                         null);
-
-                    s_elementNameProperty = s_docRootProperty.PropertyType.GetProperty("Name");
-                    s_nameNameProperty = s_elementNameProperty.PropertyType.GetProperty("LocalName");
-                    s_elementValueProperty = s_docRootProperty.PropertyType.GetProperty("Value");
-                }
+                private static readonly PropertyInfo s_elementNameProperty = s_docRootProperty.PropertyType.GetProperty("Name");
+                private static readonly PropertyInfo s_nameNameProperty = s_elementNameProperty.PropertyType.GetProperty("LocalName");
+                private static readonly PropertyInfo s_elementValueProperty = s_docRootProperty.PropertyType.GetProperty("Value");
 
                 internal static object ParseDocument(string xmlString) =>
                     s_docRootProperty.GetValue(s_xDocumentCreate(xmlString));
index b59f294..1ca63ef 100644 (file)
@@ -15,10 +15,6 @@ namespace System.Text.RegularExpressions
         // During static initialisation of Regex we check
         private const string DefaultMatchTimeout_ConfigKeyName = "REGEX_DEFAULT_MATCH_TIMEOUT";
 
-        // DefaultMatchTimeout specifies the match timeout to use if no other timeout was specified
-        // by one means or another. Typically, it is set to InfiniteMatchTimeout.
-        internal static readonly TimeSpan s_defaultMatchTimeout;
-
         // InfiniteMatchTimeout specifies that match timeout is switched OFF. It allows for faster code paths
         // compared to simply having a very large timeout.
         // We do not want to ask users to use System.Threading.Timeout.InfiniteTimeSpan as a parameter because:
@@ -29,14 +25,13 @@ namespace System.Text.RegularExpressions
         // value as Timeout.InfiniteTimeSpan creating an implementation detail dependency only.
         public static readonly TimeSpan InfiniteMatchTimeout = Timeout.InfiniteTimeSpan;
 
+        // DefaultMatchTimeout specifies the match timeout to use if no other timeout was specified
+        // by one means or another. Typically, it is set to InfiniteMatchTimeout.
+        internal static readonly TimeSpan s_defaultMatchTimeout = InitDefaultMatchTimeout();
+
         // timeout for the execution of this regex
         protected internal TimeSpan internalMatchTimeout;
 
-        static Regex()
-        {
-            s_defaultMatchTimeout = InitDefaultMatchTimeout();
-        }
-
         /// <summary>
         /// The match timeout used by this Regex instance.
         /// </summary>
index 84cd50f..bc66ba6 100644 (file)
@@ -25,36 +25,36 @@ namespace System.Text.RegularExpressions
      */
     internal abstract class RegexCompiler
     {
-        // fields that never change (making them saves about 6% overall running time)
-        private static FieldInfo s_textbegF;
-        private static FieldInfo s_textendF;
-        private static FieldInfo s_textstartF;
-        private static FieldInfo s_textposF;
-        private static FieldInfo s_textF;
-        private static FieldInfo s_trackposF;
-        private static FieldInfo s_trackF;
-        private static FieldInfo s_stackposF;
-        private static FieldInfo s_stackF;
-        private static FieldInfo s_trackcountF;
-
-        private static MethodInfo s_ensurestorageM;
-        private static MethodInfo s_captureM;
-        private static MethodInfo s_transferM;
-        private static MethodInfo s_uncaptureM;
-        private static MethodInfo s_ismatchedM;
-        private static MethodInfo s_matchlengthM;
-        private static MethodInfo s_matchindexM;
-        private static MethodInfo s_isboundaryM;
-        private static MethodInfo s_isECMABoundaryM;
-        private static MethodInfo s_chartolowerM;
-        private static MethodInfo s_getcharM;
-        private static MethodInfo s_crawlposM;
-        private static MethodInfo s_charInSetM;
-        private static MethodInfo s_getCurrentCulture;
-        private static MethodInfo s_getInvariantCulture;
-        private static MethodInfo s_checkTimeoutM;
+        // fields that never change
+        private static readonly FieldInfo s_textbegF = RegexRunnerField("runtextbeg");
+        private static readonly FieldInfo s_textendF = RegexRunnerField("runtextend");
+        private static readonly FieldInfo s_textstartF = RegexRunnerField("runtextstart");
+        private static readonly FieldInfo s_textposF = RegexRunnerField("runtextpos");
+        private static readonly FieldInfo s_textF = RegexRunnerField("runtext");
+        private static readonly FieldInfo s_trackposF = RegexRunnerField("runtrackpos");
+        private static readonly FieldInfo s_trackF = RegexRunnerField("runtrack");
+        private static readonly FieldInfo s_stackposF = RegexRunnerField("runstackpos");
+        private static readonly FieldInfo s_stackF = RegexRunnerField("runstack");
+        private static readonly FieldInfo s_trackcountF = RegexRunnerField("runtrackcount");
+
+        private static readonly MethodInfo s_ensurestorageM = RegexRunnerMethod("EnsureStorage");
+        private static readonly MethodInfo s_captureM = RegexRunnerMethod("Capture");
+        private static readonly MethodInfo s_transferM = RegexRunnerMethod("TransferCapture");
+        private static readonly MethodInfo s_uncaptureM = RegexRunnerMethod("Uncapture");
+        private static readonly MethodInfo s_ismatchedM = RegexRunnerMethod("IsMatched");
+        private static readonly MethodInfo s_matchlengthM = RegexRunnerMethod("MatchLength");
+        private static readonly MethodInfo s_matchindexM = RegexRunnerMethod("MatchIndex");
+        private static readonly MethodInfo s_isboundaryM = RegexRunnerMethod("IsBoundary");
+        private static readonly MethodInfo s_isECMABoundaryM = RegexRunnerMethod("IsECMABoundary");
+        private static readonly MethodInfo s_chartolowerM = typeof(char).GetMethod("ToLower", new Type[] { typeof(char), typeof(CultureInfo) });
+        private static readonly MethodInfo s_getcharM = typeof(string).GetMethod("get_Chars", new Type[] { typeof(int) });
+        private static readonly MethodInfo s_crawlposM = RegexRunnerMethod("Crawlpos");
+        private static readonly MethodInfo s_charInSetM = RegexRunnerMethod("CharInClass");
+        private static readonly MethodInfo s_getCurrentCulture = typeof(CultureInfo).GetMethod("get_CurrentCulture");
+        private static readonly MethodInfo s_getInvariantCulture = typeof(CultureInfo).GetMethod("get_InvariantCulture");
+        private static readonly MethodInfo s_checkTimeoutM = RegexRunnerMethod("CheckTimeout");
 #if DEBUG
-        private static MethodInfo s_dumpstateM;
+        private static readonly MethodInfo s_dumpstateM = RegexRunnerMethod("DumpState");
 #endif
 
         protected ILGenerator _ilg;
@@ -114,44 +114,6 @@ namespace System.Text.RegularExpressions
         private const int Uniquecount = 10;
         private const int LoopTimeoutCheckCount = 2048; // A conservative value to guarantee the correct timeout handling.
 
-        static RegexCompiler()
-        {
-            // fields
-            s_textbegF = RegexRunnerField("runtextbeg");
-            s_textendF = RegexRunnerField("runtextend");
-            s_textstartF = RegexRunnerField("runtextstart");
-            s_textposF = RegexRunnerField("runtextpos");
-            s_textF = RegexRunnerField("runtext");
-            s_trackposF = RegexRunnerField("runtrackpos");
-            s_trackF = RegexRunnerField("runtrack");
-            s_stackposF = RegexRunnerField("runstackpos");
-            s_stackF = RegexRunnerField("runstack");
-            s_trackcountF = RegexRunnerField("runtrackcount");
-
-            // methods
-            s_ensurestorageM = RegexRunnerMethod("EnsureStorage");
-            s_captureM = RegexRunnerMethod("Capture");
-            s_transferM = RegexRunnerMethod("TransferCapture");
-            s_uncaptureM = RegexRunnerMethod("Uncapture");
-            s_ismatchedM = RegexRunnerMethod("IsMatched");
-            s_matchlengthM = RegexRunnerMethod("MatchLength");
-            s_matchindexM = RegexRunnerMethod("MatchIndex");
-            s_isboundaryM = RegexRunnerMethod("IsBoundary");
-            s_charInSetM = RegexRunnerMethod("CharInClass");
-            s_isECMABoundaryM = RegexRunnerMethod("IsECMABoundary");
-            s_crawlposM = RegexRunnerMethod("Crawlpos");
-            s_checkTimeoutM = RegexRunnerMethod("CheckTimeout");
-
-            s_chartolowerM = typeof(char).GetMethod("ToLower", new Type[] { typeof(char), typeof(CultureInfo) });
-            s_getcharM = typeof(string).GetMethod("get_Chars", new Type[] { typeof(int) });
-            s_getCurrentCulture = typeof(CultureInfo).GetMethod("get_CurrentCulture");
-            s_getInvariantCulture = typeof(CultureInfo).GetMethod("get_InvariantCulture");
-                
-#if DEBUG
-            s_dumpstateM = RegexRunnerMethod("DumpState");
-#endif
-        }
-
         private static FieldInfo RegexRunnerField(string fieldname)
         {
             return typeof(RegexRunner).GetField(fieldname, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);