<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 -->
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);
kCFProxyUsernameKey = LoadSymbol(lib, "kCFProxyUsernameKey");
}
}
+#pragma warning restore CA1810
public CFProxy(SafeCFDictionaryHandle dictionary)
{
/// </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)
{
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)
/// </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()
{
{
get
{
- return _properties;
+ return s_properties;
}
}
{
get
{
- return (SettingElementCollection)base[_propSettings];
+ return (SettingElementCollection)base[s_propSettings];
}
}
}
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);
Completed
};
}
-}
\ No newline at end of file
+}
{
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,
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() { }
return ConnectionString;
}
}
-}
\ No newline at end of file
+}
[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)
{
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;
return this; // return the read only object
}
}
-}
\ No newline at end of file
+}
[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;
return ((DateTimeConfigurationElement)element).Value;
}
}
-}
\ No newline at end of file
+}
{
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)
}
}
}
-}
\ No newline at end of file
+}
[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)
return ((KeyValueConfigurationElement)element).Key;
}
}
-}
\ No newline at end of file
+}
{
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);
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)
}
}
}
-}
\ No newline at end of file
+}
[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;
return ((NameValueConfigurationElement)element).Name;
}
}
-}
\ No newline at end of file
+}
{
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() { }
set { base[s_propValue] = value; }
}
}
-}
\ No newline at end of file
+}
{
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),
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(){}
[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)
return ((ProviderSettings)element).Name;
}
}
-}
\ No newline at end of file
+}
{
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)]
{
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()
{
{
get
{
- return _properties;
+ return s_properties;
}
}
{
get
{
- return (string)base[_propName];
+ return (string)base[s_propName];
}
set
{
- base[_propName] = value;
+ base[s_propName] = value;
}
}
{
get
{
- return (SettingsSerializeAs)base[_propSerializeAs];
+ return (SettingsSerializeAs)base[s_propSerializeAs];
}
set
{
- base[_propSerializeAs] = value;
+ base[s_propSerializeAs] = value;
}
}
{
get
{
- return (SettingValueElement)base[_propValue];
+ return (SettingValueElement)base[s_propValue];
}
set
{
- base[_propValue] = value;
+ base[s_propValue] = value;
}
}
}
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;
}
}
}
-}
\ No newline at end of file
+}
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;
}
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)
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)
{
}
{
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);
_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
{
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));
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]);
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;
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()
ADP.CheckArgumentNull(keyword, "keyword");
object value;
Keywords index;
- if (_keywords.TryGetValue(keyword, out index))
+ if (s_keywords.TryGetValue(keyword, out index))
{
value = GetAt(index);
}
{
ADP.CheckArgumentNull(keyword, "keyword");
Keywords index;
- if (_keywords.TryGetValue(keyword, out index))
+ if (s_keywords.TryGetValue(keyword, out index))
{
switch (index)
{
case Keywords.FileName:
FileName = ConvertToString(value);
break;
- // case Keywords.NamedConnection: NamedConnection = ConvertToString(value); break;
case Keywords.Provider:
Provider = ConvertToString(value);
break;
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;
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)
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)
return DataSource;
case Keywords.FileName:
return FileName;
- // case Keywords.NamedConnection: return NamedConnection;
case Keywords.OleDbServices:
return OleDbServices;
case Keywords.PersistSecurityInfo:
return Provider;
default:
Debug.Assert(false, "unexpected keyword");
- throw ADP.KeywordNotSupported(_validKeywords[(int)index]);
+ throw ADP.KeywordNotSupported(s_validKeywords[(int)index]);
}
}
bool value = base.Remove(keyword);
Keywords index;
- if (_keywords.TryGetValue(keyword, out index))
+ if (s_keywords.TryGetValue(keyword, out index))
{
Reset(index);
}
break;
default:
Debug.Assert(false, "unexpected keyword");
- throw ADP.KeywordNotSupported(_validKeywords[(int)index]);
+ throw ADP.KeywordNotSupported(s_validKeywords[(int)index]);
}
}
{
ADP.CheckArgumentNull(keyword, "keyword");
Keywords index;
- if (_keywords.TryGetValue(keyword, out index))
+ if (s_keywords.TryGetValue(keyword, out index))
{
value = GetAt(index);
return true;
{
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) ||
<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>
<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>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Reference Include="System.ComponentModel.Primitives" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
//
//
-
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();
}
}
-
{
#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
/// <summary>
/// Do a cups call to check if it is installed
/// </summary>
- private static void CheckCupsInstalled()
+ private static bool CheckCupsInstalled()
{
try
{
#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>
{
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;
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
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.
MakeBackgroundAlphaZero(bitmap);
s_defaultComponent = new ToolboxBitmapAttribute(bitmap, null);
}
+#pragma warning restore CA1810
}
}
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;
internal static int debug_threshold = 1;
#endif
- static MacSupport()
+ private static Delegate GetHwndDelegate()
{
#if !NETSTANDARD1_6
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
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)
#endregion
+#pragma warning disable CA1810 // explicit static cctor
static CurlHandler()
{
// curl_global_init call handled by Interop.LibCurl's cctor
s_singletonSharedAgent = new MultiAgent(null);
}
}
+#pragma warning restore CA1810
public CurlHandler()
{
Receive = 2,
}
+#pragma warning disable CA1810 // explicit static cctor
static WebSocketProtocolComponent()
{
s_webSocketDllHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.WebSocket, IntPtr.Zero, 0);
};
}
}
+#pragma warning restore CA1810
internal static string SupportedVersion
{
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Diagnostics;
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)
using System.Collections;
using System.Collections.Generic;
-using System.Collections.Specialized;
+using System.Diagnostics;
using System.Linq;
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)
{
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]
// 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;
// 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
{
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/");
}
}
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;
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");
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);
// 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;
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;
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)
// 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)
{
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;
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)
{
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;
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)
/// </summary>
sealed internal class QilPatterns
{
- private BitArray _bits;
+ private readonly BitArray _bits;
public QilPatterns(int szBits, bool allSet)
{
/// </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>
/// </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
//-----------------------------------------------
/* 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>
private bool _isStrict;
private bool _isNotRtf;
+#pragma warning disable CA1810 // explicit static cctor
/// <summary>
/// Construct arrays of built-in types.
/// </summary>
s_specialBuiltInItemTypes = new XmlQueryType[4] { UntypedDocument, UntypedElement, UntypedAttribute, NodeNotRtf };
}
+#pragma warning restore CA1810
/// <summary>
/// Create ItemType from XmlTypeCode.
return false;
}
+#pragma warning disable CA1810 // explicit static cctor
static MemberPolicies()
{
Type t = typeof(M);
Debug.Fail("Unknown MemberInfo type.");
}
}
+#pragma warning restore CA1810
//
// This is a singleton class one for each MemberInfo category: Return the appropriate one.
{
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()
{
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()
{
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
{
{
internal abstract partial class MemoryMonitor
{
+#pragma warning disable CA1810 // explicit static cctor
static MemoryMonitor()
{
Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
s_totalVirtual = (long)memoryStatusEx.ullTotalVirtual;
}
}
+#pragma warning restore CA1810
}
}
// 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()
{
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));
// 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:
// 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>
*/
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;
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);