diff options
313 files changed, 2770 insertions, 2826 deletions
diff --git a/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs b/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs index 118c69b8b7..254b2f6e9e 100644 --- a/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs +++ b/src/mscorlib/src/Microsoft/Win32/OAVariantLib.cs @@ -77,9 +77,9 @@ namespace Microsoft.Win32 { internal static Variant ChangeType(Variant source, Type targetClass, short options, CultureInfo culture) { if (targetClass == null) - throw new ArgumentNullException("targetClass"); + throw new ArgumentNullException(nameof(targetClass)); if (culture == null) - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); Variant result = new Variant (); ChangeTypeEx(ref result, ref source, #if FEATURE_USE_LCID diff --git a/src/mscorlib/src/Microsoft/Win32/Registry.cs b/src/mscorlib/src/Microsoft/Win32/Registry.cs index 4faf29da7f..a8ec83f250 100644 --- a/src/mscorlib/src/Microsoft/Win32/Registry.cs +++ b/src/mscorlib/src/Microsoft/Win32/Registry.cs @@ -84,7 +84,7 @@ namespace Microsoft.Win32 { [System.Security.SecurityCritical] // auto-generated private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName) { if( keyName == null) { - throw new ArgumentNullException("keyName"); + throw new ArgumentNullException(nameof(keyName)); } string basekeyName; @@ -122,7 +122,7 @@ namespace Microsoft.Win32 { break; #endif default: - throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", "keyName")); + throw new ArgumentException(Environment.GetResourceString("Arg_RegInvalidKeyName", nameof(keyName))); } if( i == -1 || i == keyName.Length) { subKeyName = string.Empty; diff --git a/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs b/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs index 0d6a447e1c..dd75310020 100644 --- a/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs +++ b/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs @@ -644,7 +644,7 @@ namespace Microsoft.Win32 { [ComVisible(false)] public static RegistryKey OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view) { if (machineName==null) - throw new ArgumentNullException("machineName"); + throw new ArgumentNullException(nameof(machineName)); int index = (int)hKey & 0x0FFFFFFF; if (index < 0 || index >= hkeyNames.Length || ((int)hKey & 0xFFFFFFF0) != 0x80000000) { throw new ArgumentException(Environment.GetResourceString("Arg_RegKeyOutOfRange")); @@ -898,7 +898,7 @@ namespace Microsoft.Win32 { [ComVisible(false)] [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public static RegistryKey FromHandle(SafeRegistryHandle handle, RegistryView view) { - if (handle == null) throw new ArgumentNullException("handle"); + if (handle == null) throw new ArgumentNullException(nameof(handle)); ValidateKeyView(view); return new RegistryKey(handle, true /* isWritable */, view); @@ -1107,7 +1107,7 @@ namespace Microsoft.Win32 { [ComVisible(false)] public Object GetValue(String name, Object defaultValue, RegistryValueOptions options) { if( options < RegistryValueOptions.None || options > RegistryValueOptions.DoNotExpandEnvironmentNames) { - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options), "options"); + throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options), nameof(options)); } bool doNotExpand = (options == RegistryValueOptions.DoNotExpandEnvironmentNames); CheckPermission(RegistryInternalCheck.CheckValueReadPermission, name, false, RegistryKeyPermissionCheck.Default); @@ -1409,7 +1409,7 @@ namespace Microsoft.Win32 { } if (!Enum.IsDefined(typeof(RegistryValueKind), valueKind)) - throw new ArgumentException(Environment.GetResourceString("Arg_RegBadKeyKind"), "valueKind"); + throw new ArgumentException(Environment.GetResourceString("Arg_RegBadKeyKind"), nameof(valueKind)); EnsureWriteable(); @@ -1591,7 +1591,7 @@ namespace Microsoft.Win32 { public void SetAccessControl(RegistrySecurity registrySecurity) { EnsureWriteable(); if (registrySecurity == null) - throw new ArgumentNullException("registrySecurity"); + throw new ArgumentNullException(nameof(registrySecurity)); registrySecurity.Persist(hkey, keyName); } diff --git a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs index 6373f97be7..01fab53a3f 100644 --- a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs +++ b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs @@ -327,7 +327,7 @@ namespace Microsoft.Win32 { // } REG_TZI_FORMAT; // if (bytes == null || bytes.Length != 44) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidREG_TZI_FORMAT"), "bytes"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidREG_TZI_FORMAT"), nameof(bytes)); } Bias = BitConverter.ToInt32(bytes, 0); StandardBias = BitConverter.ToInt32(bytes, 4); diff --git a/src/mscorlib/src/System/Activator.cs b/src/mscorlib/src/System/Activator.cs index 48fedc02ba..f35745fea8 100644 --- a/src/mscorlib/src/System/Activator.cs +++ b/src/mscorlib/src/System/Activator.cs @@ -70,7 +70,7 @@ namespace System { Object[] activationAttributes) { if ((object)type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); if (type is System.Reflection.Emit.TypeBuilder) @@ -102,7 +102,7 @@ namespace System { RuntimeType rt = type.UnderlyingSystemType as RuntimeType; if (rt == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(type)); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return rt.CreateInstanceImpl(bindingAttr,binder,args,culture,activationAttributes, ref stackMark); @@ -182,13 +182,13 @@ namespace System { static public Object CreateInstance(Type type, bool nonPublic) { if ((object)type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); RuntimeType rt = type.UnderlyingSystemType as RuntimeType; if (rt == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(type)); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return rt.CreateInstanceDefaultCtor(!nonPublic, false, true, ref stackMark); @@ -441,7 +441,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public static ObjectHandle CreateInstance (AppDomain domain, string assemblyName, string typeName) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); return domain.InternalCreateInstanceWithNoSecurity(assemblyName, typeName); } @@ -459,7 +459,7 @@ namespace System { Object[] activationAttributes, Evidence securityAttributes) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); #if FEATURE_CAS_POLICY @@ -484,7 +484,7 @@ namespace System { object[] activationAttributes) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); return domain.InternalCreateInstanceWithNoSecurity(assemblyName, @@ -508,7 +508,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public static ObjectHandle CreateInstanceFrom (AppDomain domain, string assemblyFile, string typeName) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); return domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile, typeName); } @@ -526,7 +526,7 @@ namespace System { Object[] activationAttributes, Evidence securityAttributes) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); #if FEATURE_CAS_POLICY @@ -551,7 +551,7 @@ namespace System { object[] activationAttributes) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); return domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile, @@ -647,7 +647,7 @@ namespace System { static public Object GetObject(Type type, String url, Object state) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); return RemotingServices.Connect(type, url, state); } diff --git a/src/mscorlib/src/System/AggregateException.cs b/src/mscorlib/src/System/AggregateException.cs index 064432aaaa..07523e13c0 100644 --- a/src/mscorlib/src/System/AggregateException.cs +++ b/src/mscorlib/src/System/AggregateException.cs @@ -69,7 +69,7 @@ namespace System { if (innerException == null) { - throw new ArgumentNullException("innerException"); + throw new ArgumentNullException(nameof(innerException)); } m_innerExceptions = new ReadOnlyCollection<Exception>(new Exception[] { innerException }); @@ -149,7 +149,7 @@ namespace System { if (innerExceptions == null) { - throw new ArgumentNullException("innerExceptions"); + throw new ArgumentNullException(nameof(innerExceptions)); } // Copy exceptions to our internal array and validate them. We must copy them, @@ -227,7 +227,7 @@ namespace System { if (innerExceptionInfos == null) { - throw new ArgumentNullException("innerExceptionInfos"); + throw new ArgumentNullException(nameof(innerExceptionInfos)); } // Copy exceptions to our internal array and validate them. We must copy them, @@ -264,7 +264,7 @@ namespace System { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Exception[] innerExceptions = info.GetValue("InnerExceptions", typeof(Exception[])) as Exception[]; @@ -290,7 +290,7 @@ namespace System { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } base.GetObjectData(info, context); @@ -351,7 +351,7 @@ namespace System { if (predicate == null) { - throw new ArgumentNullException("predicate"); + throw new ArgumentNullException(nameof(predicate)); } List<Exception> unhandledExceptions = null; diff --git a/src/mscorlib/src/System/AppContext/AppContext.cs b/src/mscorlib/src/System/AppContext/AppContext.cs index 5e78f8d370..de6405a8a0 100644 --- a/src/mscorlib/src/System/AppContext/AppContext.cs +++ b/src/mscorlib/src/System/AppContext/AppContext.cs @@ -114,9 +114,9 @@ namespace System public static bool TryGetSwitch(string switchName, out bool isEnabled) { if (switchName == null) - throw new ArgumentNullException("switchName"); + throw new ArgumentNullException(nameof(switchName)); if (switchName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "switchName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(switchName)); // By default, the switch is not enabled. isEnabled = false; @@ -210,9 +210,9 @@ namespace System public static void SetSwitch(string switchName, bool isEnabled) { if (switchName == null) - throw new ArgumentNullException("switchName"); + throw new ArgumentNullException(nameof(switchName)); if (switchName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "switchName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(switchName)); SwitchValueState switchValue = (isEnabled ? SwitchValueState.HasTrueValue : SwitchValueState.HasFalseValue) | SwitchValueState.HasLookedForOverride; diff --git a/src/mscorlib/src/System/AppDomain.cs b/src/mscorlib/src/System/AppDomain.cs index 814a4d4f06..475fdd76f4 100644 --- a/src/mscorlib/src/System/AppDomain.cs +++ b/src/mscorlib/src/System/AppDomain.cs @@ -1516,7 +1516,7 @@ namespace System { throw new NullReferenceException(); if (assemblyName == null) - throw new ArgumentNullException("assemblyName"); + throw new ArgumentNullException(nameof(assemblyName)); Contract.EndContractBlock(); return Activator.CreateInstance(assemblyName, @@ -1591,7 +1591,7 @@ namespace System { throw new NullReferenceException(); if (assemblyName == null) - throw new ArgumentNullException("assemblyName"); + throw new ArgumentNullException(nameof(assemblyName)); Contract.EndContractBlock(); return Activator.CreateInstance(assemblyName, @@ -1630,7 +1630,7 @@ namespace System { throw new NullReferenceException(); if (assemblyName == null) - throw new ArgumentNullException("assemblyName"); + throw new ArgumentNullException(nameof(assemblyName)); Contract.EndContractBlock(); #if FEATURE_CAS_POLICY @@ -1667,7 +1667,7 @@ namespace System { throw new NullReferenceException(); if (assemblyName == null) - throw new ArgumentNullException("assemblyName"); + throw new ArgumentNullException(nameof(assemblyName)); Contract.EndContractBlock(); return Activator.CreateInstance(assemblyName, @@ -2258,7 +2258,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated private void SetDataHelper (string name, object data, IPermission permission) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); // @@ -2372,7 +2372,7 @@ namespace System { public Object GetData(string name) { if(name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); int key = AppDomainSetup.Locate(name); @@ -2477,7 +2477,7 @@ namespace System { public static void Unload(AppDomain domain) { if (domain == null) - throw new ArgumentNullException("domain"); + throw new ArgumentNullException(nameof(domain)); Contract.EndContractBlock(); try { @@ -2502,7 +2502,7 @@ namespace System { public void SetAppDomainPolicy(PolicyLevel domainPolicy) { if (domainPolicy == null) - throw new ArgumentNullException("domainPolicy"); + throw new ArgumentNullException(nameof(domainPolicy)); Contract.EndContractBlock(); if (!IsLegacyCasPolicyEnabled) @@ -2566,7 +2566,7 @@ namespace System { public void SetThreadPrincipal(IPrincipal principal) { if (principal == null) - throw new ArgumentNullException("principal"); + throw new ArgumentNullException(nameof(principal)); Contract.EndContractBlock(); lock (this) { @@ -2606,7 +2606,7 @@ namespace System { public void DoCallBack(CrossAppDomainDelegate callBackDelegate) { if (callBackDelegate == null) - throw new ArgumentNullException("callBackDelegate"); + throw new ArgumentNullException(nameof(callBackDelegate)); Contract.EndContractBlock(); callBackDelegate(); @@ -3282,7 +3282,7 @@ namespace System { AppDomainSetup info) { if (friendlyName == null) - throw new ArgumentNullException("friendlyName", Environment.GetResourceString("ArgumentNull_String")); + throw new ArgumentNullException(nameof(friendlyName), Environment.GetResourceString("ArgumentNull_String")); Contract.EndContractBlock(); @@ -3326,7 +3326,7 @@ namespace System { params StrongName[] fullTrustAssemblies) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); if (info.ApplicationBase == null) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AppDomainSandboxAPINeedsExplicitAppBase")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/AppDomainManager.cs b/src/mscorlib/src/System/AppDomainManager.cs index dc9fae4ced..bc5e5dcb28 100644 --- a/src/mscorlib/src/System/AppDomainManager.cs +++ b/src/mscorlib/src/System/AppDomainManager.cs @@ -55,7 +55,7 @@ namespace System { Evidence securityInfo, AppDomainSetup appDomainInfo) { if (friendlyName == null) - throw new ArgumentNullException("friendlyName", Environment.GetResourceString("ArgumentNull_String")); + throw new ArgumentNullException(nameof(friendlyName), Environment.GetResourceString("ArgumentNull_String")); Contract.EndContractBlock(); // If evidence is provided, we check to make sure that is allowed. diff --git a/src/mscorlib/src/System/AppDomainSetup.cs b/src/mscorlib/src/System/AppDomainSetup.cs index f1057da082..43c85838a9 100644 --- a/src/mscorlib/src/System/AppDomainSetup.cs +++ b/src/mscorlib/src/System/AppDomainSetup.cs @@ -233,7 +233,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated public AppDomainSetup (ActivationArguments activationArguments) { if (activationArguments == null) - throw new ArgumentNullException("activationArguments"); + throw new ArgumentNullException(nameof(activationArguments)); Contract.EndContractBlock(); _LoaderOptimization = LoaderOptimization.NotSpecified; @@ -677,17 +677,17 @@ namespace System { { if(functionName == null) { - throw new ArgumentNullException("functionName"); + throw new ArgumentNullException(nameof(functionName)); } if(functionPointer == IntPtr.Zero) { - throw new ArgumentNullException("functionPointer"); + throw new ArgumentNullException(nameof(functionPointer)); } if(String.IsNullOrWhiteSpace(functionName)) { - throw new ArgumentException(Environment.GetResourceString("Argument_NPMSInvalidName"), "functionName"); + throw new ArgumentException(Environment.GetResourceString("Argument_NPMSInvalidName"), nameof(functionName)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/ApplicationId.cs b/src/mscorlib/src/System/ApplicationId.cs index fa8be957e2..93fc37dd99 100644 --- a/src/mscorlib/src/System/ApplicationId.cs +++ b/src/mscorlib/src/System/ApplicationId.cs @@ -33,13 +33,13 @@ namespace System { public ApplicationId (byte[] publicKeyToken, string name, Version version, string processorArchitecture, string culture) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyApplicationName")); if (version == null) - throw new ArgumentNullException("version"); + throw new ArgumentNullException(nameof(version)); if (publicKeyToken == null) - throw new ArgumentNullException("publicKeyToken"); + throw new ArgumentNullException(nameof(publicKeyToken)); Contract.EndContractBlock(); m_publicKeyToken = new byte[publicKeyToken.Length]; diff --git a/src/mscorlib/src/System/ArgumentException.cs b/src/mscorlib/src/System/ArgumentException.cs index 8edb7e4279..0afa56f19d 100644 --- a/src/mscorlib/src/System/ArgumentException.cs +++ b/src/mscorlib/src/System/ArgumentException.cs @@ -85,7 +85,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/ArgumentOutOfRangeException.cs b/src/mscorlib/src/System/ArgumentOutOfRangeException.cs index a54380b39d..0b1ed4d560 100644 --- a/src/mscorlib/src/System/ArgumentOutOfRangeException.cs +++ b/src/mscorlib/src/System/ArgumentOutOfRangeException.cs @@ -92,7 +92,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/Attribute.cs b/src/mscorlib/src/System/Attribute.cs index f21d527cfa..66aa48c0be 100644 --- a/src/mscorlib/src/System/Attribute.cs +++ b/src/mscorlib/src/System/Attribute.cs @@ -456,10 +456,10 @@ namespace System { public static Attribute[] GetCustomAttributes(MemberInfo element, Type type, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (!type.IsSubclassOf(typeof(Attribute)) && type != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); @@ -486,7 +486,7 @@ namespace System { public static Attribute[] GetCustomAttributes(MemberInfo element, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); Contract.EndContractBlock(); switch (element.MemberType) @@ -511,10 +511,10 @@ namespace System { { // Returns true if a custom attribute subclass of attributeType class/interface with inheritance walk if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); @@ -568,16 +568,16 @@ namespace System { public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attributeType, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); if (element.Member == null) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParameterInfo"), "element"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParameterInfo"), nameof(element)); Contract.EndContractBlock(); @@ -591,10 +591,10 @@ namespace System { public static Attribute[] GetCustomAttributes(ParameterInfo element, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (element.Member == null) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParameterInfo"), "element"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParameterInfo"), nameof(element)); Contract.EndContractBlock(); @@ -614,10 +614,10 @@ namespace System { { // Returns true is a custom attribute subclass of attributeType class/interface with inheritance walk if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); @@ -681,7 +681,7 @@ namespace System { public static Attribute[] GetCustomAttributes(Module element, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); Contract.EndContractBlock(); return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit); @@ -690,10 +690,10 @@ namespace System { public static Attribute[] GetCustomAttributes(Module element, Type attributeType, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); @@ -711,10 +711,10 @@ namespace System { { // Returns true is a custom attribute subclass of attributeType class/interface with no inheritance walk if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); @@ -754,10 +754,10 @@ namespace System { public static Attribute[] GetCustomAttributes(Assembly element, Type attributeType, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); @@ -774,7 +774,7 @@ namespace System { public static Attribute[] GetCustomAttributes(Assembly element, bool inherit) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); Contract.EndContractBlock(); return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit); @@ -789,10 +789,10 @@ namespace System { { // Returns true is a custom attribute subclass of attributeType class/interface with no inheritance walk if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute)) throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass")); diff --git a/src/mscorlib/src/System/BitConverter.cs b/src/mscorlib/src/System/BitConverter.cs index 8be545c67e..5adbd8fe3f 100644 --- a/src/mscorlib/src/System/BitConverter.cs +++ b/src/mscorlib/src/System/BitConverter.cs @@ -358,15 +358,15 @@ namespace System { // Converts an array of bytes into a String. public static String ToString (byte[] value, int startIndex, int length) { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (startIndex < 0 || startIndex >= value.Length && startIndex > 0) { // Don't throw for a 0 length array. - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if (startIndex > value.Length - length) { @@ -380,7 +380,7 @@ namespace System { if (length > (Int32.MaxValue / 3)) { // (Int32.MaxValue / 3) == 715,827,882 Bytes == 699 MB - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_LengthTooLarge", (Int32.MaxValue / 3))); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_LengthTooLarge", (Int32.MaxValue / 3))); } int chArrayLength = length * 3; @@ -402,7 +402,7 @@ namespace System { // Converts an array of bytes into a String. public static String ToString(byte [] value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); return ToString(value, 0, value.Length); @@ -411,7 +411,7 @@ namespace System { // Converts an array of bytes into a String. public static String ToString (byte [] value, int startIndex) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); return ToString(value, startIndex, value.Length - startIndex); @@ -428,11 +428,11 @@ namespace System { // Converts an array of bytes into a boolean. public static bool ToBoolean(byte[] value, int startIndex) { if (value==null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (startIndex > value.Length - 1) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return (value[startIndex]==0)?false:true; diff --git a/src/mscorlib/src/System/Boolean.cs b/src/mscorlib/src/System/Boolean.cs index c5cd45a428..9aaec9a345 100644 --- a/src/mscorlib/src/System/Boolean.cs +++ b/src/mscorlib/src/System/Boolean.cs @@ -151,7 +151,7 @@ namespace System { // Determines whether a String represents true or false. // public static Boolean Parse (String value) { - if (value==null) throw new ArgumentNullException("value"); + if (value==null) throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); Boolean result = false; if (!TryParse(value, out result)) { diff --git a/src/mscorlib/src/System/Buffer.cs b/src/mscorlib/src/System/Buffer.cs index ea647f1e9a..72cbe0125c 100644 --- a/src/mscorlib/src/System/Buffer.cs +++ b/src/mscorlib/src/System/Buffer.cs @@ -141,15 +141,15 @@ namespace System { { // Is the array present? if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); // Is it of primitive types? if (!IsPrimitiveTypeArray(array)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePrimArray"), "array"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePrimArray"), nameof(array)); // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); return _GetByte(array, index); } @@ -169,15 +169,15 @@ namespace System { { // Is the array present? if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); // Is it of primitive types? if (!IsPrimitiveTypeArray(array)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePrimArray"), "array"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePrimArray"), nameof(array)); // Is the index in valid range of the array? if (index < 0 || index >= _ByteLength(array)) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); // Make the FCall to do the work _SetByte(array, index, value); @@ -199,11 +199,11 @@ namespace System { { // Is the array present? if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); // Is it of primitive types? if (!IsPrimitiveTypeArray(array)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePrimArray"), "array"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePrimArray"), nameof(array)); return _ByteLength(array); } diff --git a/src/mscorlib/src/System/CfgParser.cs b/src/mscorlib/src/System/CfgParser.cs index ef368a9020..1996f8d444 100644 --- a/src/mscorlib/src/System/CfgParser.cs +++ b/src/mscorlib/src/System/CfgParser.cs @@ -249,7 +249,7 @@ namespace System internal ConfigNode Parse(String fileName, String configPath, bool skipSecurityStuff) { if (fileName == null) - throw new ArgumentNullException("fileName"); + throw new ArgumentNullException(nameof(fileName)); Contract.EndContractBlock(); this.fileName = fileName; if (configPath[0] == '/'){ diff --git a/src/mscorlib/src/System/Char.cs b/src/mscorlib/src/System/Char.cs index ff936c6618..650b15907c 100644 --- a/src/mscorlib/src/System/Char.cs +++ b/src/mscorlib/src/System/Char.cs @@ -167,7 +167,7 @@ namespace System { public static char Parse(String s) { if (s==null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } Contract.EndContractBlock(); @@ -364,7 +364,7 @@ namespace System { // <;<;Not fully implemented>;>; public static char ToUpper(char c, CultureInfo culture) { if (culture==null) - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); Contract.EndContractBlock(); return culture.TextInfo.ToUpper(c); } @@ -393,7 +393,7 @@ namespace System { // <;<;Not fully implemented>;>; public static char ToLower(char c, CultureInfo culture) { if (culture==null) - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); Contract.EndContractBlock(); return culture.TextInfo.ToLower(c); } @@ -508,9 +508,9 @@ namespace System { public static bool IsControl(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -524,9 +524,9 @@ namespace System { public static bool IsDigit(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -539,9 +539,9 @@ namespace System { public static bool IsLetter(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -558,9 +558,9 @@ namespace System { public static bool IsLetterOrDigit(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -573,9 +573,9 @@ namespace System { public static bool IsLower(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -617,9 +617,9 @@ namespace System { public static bool IsNumber(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -643,9 +643,9 @@ namespace System { public static bool IsPunctuation (String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -688,9 +688,9 @@ namespace System { public static bool IsSeparator(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -710,10 +710,10 @@ namespace System { public static bool IsSurrogate(String s, int index) { if (s==null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); return (IsSurrogate(s[index])); @@ -745,9 +745,9 @@ namespace System { public static bool IsSymbol(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); if (IsLatin1(s[index])) { @@ -760,9 +760,9 @@ namespace System { public static bool IsUpper(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); char c = s[index]; @@ -779,9 +779,9 @@ namespace System { public static bool IsWhiteSpace(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); @@ -803,9 +803,9 @@ namespace System { public static UnicodeCategory GetUnicodeCategory(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); if (IsLatin1(s[index])) { @@ -822,9 +822,9 @@ namespace System { public static double GetNumericValue(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); return CharUnicodeInfo.GetNumericValue(s, index); @@ -842,10 +842,10 @@ namespace System { [Pure] public static bool IsHighSurrogate(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); return (IsHighSurrogate(s[index])); @@ -862,10 +862,10 @@ namespace System { [Pure] public static bool IsLowSurrogate(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); return (IsLowSurrogate(s[index])); @@ -877,10 +877,10 @@ namespace System { [Pure] public static bool IsSurrogatePair(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); if (index + 1 < s.Length) { @@ -917,7 +917,7 @@ namespace System { // For UTF32 values from U+00D800 ~ U+00DFFF, we should throw. They // are considered as irregular code unit sequence, but they are not illegal. if ((utf32 < 0 || utf32 > UNICODE_PLANE16_END) || (utf32 >= HIGH_SURROGATE_START && utf32 <= LOW_SURROGATE_END)) { - throw new ArgumentOutOfRangeException("utf32", Environment.GetResourceString("ArgumentOutOfRange_InvalidUTF32")); + throw new ArgumentOutOfRangeException(nameof(utf32), Environment.GetResourceString("ArgumentOutOfRange_InvalidUTF32")); } Contract.EndContractBlock(); @@ -945,10 +945,10 @@ namespace System { public static int ConvertToUtf32(char highSurrogate, char lowSurrogate) { if (!IsHighSurrogate(highSurrogate)) { - throw new ArgumentOutOfRangeException("highSurrogate", Environment.GetResourceString("ArgumentOutOfRange_InvalidHighSurrogate")); + throw new ArgumentOutOfRangeException(nameof(highSurrogate), Environment.GetResourceString("ArgumentOutOfRange_InvalidHighSurrogate")); } if (!IsLowSurrogate(lowSurrogate)) { - throw new ArgumentOutOfRangeException("lowSurrogate", Environment.GetResourceString("ArgumentOutOfRange_InvalidLowSurrogate")); + throw new ArgumentOutOfRangeException(nameof(lowSurrogate), Environment.GetResourceString("ArgumentOutOfRange_InvalidLowSurrogate")); } Contract.EndContractBlock(); return (((highSurrogate - CharUnicodeInfo.HIGH_SURROGATE_START) * 0x400) + (lowSurrogate - CharUnicodeInfo.LOW_SURROGATE_START) + UNICODE_PLANE01_START); @@ -964,11 +964,11 @@ namespace System { public static int ConvertToUtf32(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); // Check if the character at index is a high surrogate. @@ -983,15 +983,15 @@ namespace System { // Found a low surrogate. return ((temp1 * 0x400) + temp2 + UNICODE_PLANE01_START); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", index), "s"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", index), nameof(s)); } } else { // Found a high surrogate at the end of the string. - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", index), "s"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", index), nameof(s)); } } else { // Find a low surrogate at the character pointed by index. - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidLowSurrogate", index), "s"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidLowSurrogate", index), nameof(s)); } } // Not a high-surrogate or low-surrogate. Genereate the UTF32 value for the BMP characters. diff --git a/src/mscorlib/src/System/Collections/ArrayList.cs b/src/mscorlib/src/System/Collections/ArrayList.cs index 94f4dc74e8..8874033211 100644 --- a/src/mscorlib/src/System/Collections/ArrayList.cs +++ b/src/mscorlib/src/System/Collections/ArrayList.cs @@ -68,7 +68,7 @@ namespace System.Collections { // before any reallocations are required. // public ArrayList(int capacity) { - if (capacity < 0) throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "capacity")); + if (capacity < 0) throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "capacity")); Contract.EndContractBlock(); if (capacity == 0) @@ -83,7 +83,7 @@ namespace System.Collections { // public ArrayList(ICollection c) { if (c==null) - throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection")); + throw new ArgumentNullException(nameof(c), Environment.GetResourceString("ArgumentNull_Collection")); Contract.EndContractBlock(); int count = c.Count; @@ -108,7 +108,7 @@ namespace System.Collections { } set { if (value < _size) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); } Contract.Ensures(Capacity >= 0); Contract.EndContractBlock(); @@ -166,12 +166,12 @@ namespace System.Collections { // public virtual Object this[int index] { get { - if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return _items[index]; } set { - if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); _items[index] = value; _version++; @@ -188,7 +188,7 @@ namespace System.Collections { // public static ArrayList Adapter(IList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<ArrayList>() != null); Contract.EndContractBlock(); return new IListWrapper(list); @@ -236,9 +236,9 @@ namespace System.Collections { // public virtual int BinarySearch(int index, int count, Object value, IComparer comparer) { if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (_size - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.Ensures(Contract.Result<int>() < Count); @@ -356,7 +356,7 @@ namespace System.Collections { // public static IList FixedSize(IList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<IList>() != null); Contract.EndContractBlock(); return new FixedSizeList(list); @@ -367,7 +367,7 @@ namespace System.Collections { // public static ArrayList FixedSize(ArrayList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<ArrayList>() != null); Contract.EndContractBlock(); return new FixedSizeArrayList(list); @@ -390,9 +390,9 @@ namespace System.Collections { // public virtual IEnumerator GetEnumerator(int index, int count) { if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (_size - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.Ensures(Contract.Result<IEnumerator>() != null); @@ -425,7 +425,7 @@ namespace System.Collections { // public virtual int IndexOf(Object value, int startIndex) { if (startIndex > _size) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.Ensures(Contract.Result<int>() < Count); Contract.EndContractBlock(); return Array.IndexOf((Array)_items, value, startIndex, _size - startIndex); @@ -442,8 +442,8 @@ namespace System.Collections { // public virtual int IndexOf(Object value, int startIndex, int count) { if (startIndex > _size) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); - if (count <0 || startIndex > _size - count) throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (count <0 || startIndex > _size - count) throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); Contract.Ensures(Contract.Result<int>() < Count); Contract.EndContractBlock(); return Array.IndexOf((Array)_items, value, startIndex, count); @@ -455,7 +455,7 @@ namespace System.Collections { // public virtual void Insert(int index, Object value) { // Note that insertions at the end are legal. - if (index < 0 || index > _size) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_ArrayListInsert")); + if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_ArrayListInsert")); //Contract.Ensures(Count == Contract.OldValue(Count) + 1); Contract.EndContractBlock(); @@ -475,8 +475,8 @@ namespace System.Collections { // public virtual void InsertRange(int index, ICollection c) { if (c==null) - throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection")); - if (index < 0 || index > _size) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentNullException(nameof(c), Environment.GetResourceString("ArgumentNull_Collection")); + if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); //Contract.Ensures(Count == Contract.OldValue(Count) + c.Count); Contract.EndContractBlock(); @@ -522,7 +522,7 @@ namespace System.Collections { public virtual int LastIndexOf(Object value, int startIndex) { if (startIndex >= _size) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.Ensures(Contract.Result<int>() < Count); Contract.EndContractBlock(); return LastIndexOf(value, startIndex, startIndex + 1); @@ -559,7 +559,7 @@ namespace System.Collections { #endif public static IList ReadOnly(IList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<IList>() != null); Contract.EndContractBlock(); return new ReadOnlyList(list); @@ -569,7 +569,7 @@ namespace System.Collections { // public static ArrayList ReadOnly(ArrayList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<ArrayList>() != null); Contract.EndContractBlock(); return new ReadOnlyArrayList(list); @@ -591,7 +591,7 @@ namespace System.Collections { // decreased by one. // public virtual void RemoveAt(int index) { - if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.Ensures(Count >= 0); //Contract.Ensures(Count == Contract.OldValue(Count) - 1); Contract.EndContractBlock(); @@ -608,9 +608,9 @@ namespace System.Collections { // public virtual void RemoveRange(int index, int count) { if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (_size - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.Ensures(Count >= 0); @@ -632,7 +632,7 @@ namespace System.Collections { // public static ArrayList Repeat(Object value, int count) { if (count < 0) - throw new ArgumentOutOfRangeException("count",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.Ensures(Contract.Result<ArrayList>() != null); Contract.EndContractBlock(); @@ -657,9 +657,9 @@ namespace System.Collections { // public virtual void Reverse(int index, int count) { if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (_size - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -671,10 +671,10 @@ namespace System.Collections { // given collection. // public virtual void SetRange(int index, ICollection c) { - if (c==null) throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection")); + if (c==null) throw new ArgumentNullException(nameof(c), Environment.GetResourceString("ArgumentNull_Collection")); Contract.EndContractBlock(); int count = c.Count; - if (index < 0 || index > _size - count) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index > _size - count) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count > 0) { c.CopyTo(_items, index); @@ -716,9 +716,9 @@ namespace System.Collections { // public virtual void Sort(int index, int count, IComparer comparer) { if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (_size - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -732,7 +732,7 @@ namespace System.Collections { [HostProtection(Synchronization=true)] public static IList Synchronized(IList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<IList>() != null); Contract.EndContractBlock(); return new SyncIList(list); @@ -743,7 +743,7 @@ namespace System.Collections { [HostProtection(Synchronization=true)] public static ArrayList Synchronized(ArrayList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.Ensures(Contract.Result<ArrayList>() != null); Contract.EndContractBlock(); return new SyncArrayList(list); @@ -767,7 +767,7 @@ namespace System.Collections { [SecuritySafeCritical] public virtual Array ToArray(Type type) { if (type==null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.Ensures(Contract.Result<Array>() != null); Contract.EndContractBlock(); Array array = Array.UnsafeCreateInstance(type, _size); @@ -804,7 +804,7 @@ namespace System.Collections { public override int Capacity { get { return _list.Count; } set { - if (value < Count) throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + if (value < Count) throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); Contract.EndContractBlock(); } } @@ -906,11 +906,11 @@ namespace System.Collections { public override void CopyTo(int index, Array array, int arrayIndex, int count) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0 || arrayIndex < 0) throw new ArgumentOutOfRangeException((index < 0) ? "index" : "arrayIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if( count < 0) - throw new ArgumentOutOfRangeException( "count" , Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException( nameof(count) , Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - arrayIndex < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); if (array.Rank != 1) @@ -948,8 +948,8 @@ namespace System.Collections { } public override int IndexOf(Object value, int startIndex, int count) { - if (startIndex < 0 || startIndex > this.Count) throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); - if (count < 0 || startIndex > this.Count - count) throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + if (startIndex < 0 || startIndex > this.Count) throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (count < 0 || startIndex > this.Count - count) throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); Contract.EndContractBlock(); int endIndex = startIndex + count; @@ -973,8 +973,8 @@ namespace System.Collections { public override void InsertRange(int index, ICollection c) { if (c==null) - throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection")); - if (index < 0 || index > this.Count) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentNullException(nameof(c), Environment.GetResourceString("ArgumentNull_Collection")); + if (index < 0 || index > this.Count) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); if( c.Count > 0) { @@ -1009,8 +1009,8 @@ namespace System.Collections { if (_list.Count == 0) return -1; - if (startIndex < 0 || startIndex >= _list.Count) throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); - if (count < 0 || count > startIndex + 1) throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + if (startIndex < 0 || startIndex >= _list.Count) throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (count < 0 || count > startIndex + 1) throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); int endIndex = startIndex - count + 1; if (value == null) { @@ -1073,12 +1073,12 @@ namespace System.Collections { public override void SetRange(int index, ICollection c) { if (c==null) { - throw new ArgumentNullException("c", Environment.GetResourceString("ArgumentNull_Collection")); + throw new ArgumentNullException(nameof(c), Environment.GetResourceString("ArgumentNull_Collection")); } Contract.EndContractBlock(); if (index < 0 || index > _list.Count - c.Count) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if( c.Count > 0) { @@ -1126,7 +1126,7 @@ namespace System.Collections { public override Array ToArray(Type type) { if (type==null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); Array array = Array.UnsafeCreateInstance(type, _list.Count); _list.CopyTo(array, 0); @@ -2191,7 +2191,7 @@ namespace System.Collections { public override void AddRange(ICollection c) { if( c == null ) { - throw new ArgumentNullException("c"); + throw new ArgumentNullException(nameof(c)); } Contract.EndContractBlock(); @@ -2224,7 +2224,7 @@ namespace System.Collections { } set { - if (value < Count) throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + if (value < Count) throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); Contract.EndContractBlock(); } } @@ -2265,11 +2265,11 @@ namespace System.Collections { public override void CopyTo(Array array, int index) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - index < _baseSize) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -2280,7 +2280,7 @@ namespace System.Collections { public override void CopyTo(int index, Array array, int arrayIndex, int count) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0 || count < 0) @@ -2356,9 +2356,9 @@ namespace System.Collections { public override int IndexOf(Object value, int startIndex) { if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (startIndex > _baseSize) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); InternalUpdateRange(); @@ -2369,10 +2369,10 @@ namespace System.Collections { public override int IndexOf(Object value, int startIndex, int count) { if (startIndex < 0 || startIndex > _baseSize) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count < 0 || (startIndex > _baseSize - count)) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); Contract.EndContractBlock(); InternalUpdateRange(); @@ -2382,7 +2382,7 @@ namespace System.Collections { } public override void Insert(int index, Object value) { - if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); InternalUpdateRange(); @@ -2392,9 +2392,9 @@ namespace System.Collections { } public override void InsertRange(int index, ICollection c) { - if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index > _baseSize) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); if( c == null) { - throw new ArgumentNullException("c"); + throw new ArgumentNullException(nameof(c)); } Contract.EndContractBlock(); @@ -2426,9 +2426,9 @@ namespace System.Collections { return -1; if (startIndex >= _baseSize) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); int i = _baseList.LastIndexOf(value, _baseIndex + startIndex, count); if (i >= 0) return i - _baseIndex; @@ -2438,7 +2438,7 @@ namespace System.Collections { // Don't need to override Remove public override void RemoveAt(int index) { - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); InternalUpdateRange(); @@ -2479,7 +2479,7 @@ namespace System.Collections { [SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems. public override void SetRange(int index, ICollection c) { InternalUpdateRange(); - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); _baseList.SetRange(_baseIndex + index, c); if( c.Count > 0) { InternalUpdateVersion(); @@ -2501,12 +2501,12 @@ namespace System.Collections { public override Object this[int index] { get { InternalUpdateRange(); - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); return _baseList[_baseIndex + index]; } set { InternalUpdateRange(); - if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= _baseSize) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); _baseList[_baseIndex + index] = value; InternalUpdateVersion(); } @@ -2522,7 +2522,7 @@ namespace System.Collections { [SecuritySafeCritical] public override Array ToArray(Type type) { if (type==null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); InternalUpdateRange(); @@ -2619,7 +2619,7 @@ namespace System.Collections { public ArrayListDebugView( ArrayList arrayList) { if( arrayList == null) - throw new ArgumentNullException("arrayList"); + throw new ArgumentNullException(nameof(arrayList)); this.arrayList = arrayList; } diff --git a/src/mscorlib/src/System/Collections/CollectionBase.cs b/src/mscorlib/src/System/Collections/CollectionBase.cs index 1bb08af27a..ae0c0d302d 100644 --- a/src/mscorlib/src/System/Collections/CollectionBase.cs +++ b/src/mscorlib/src/System/Collections/CollectionBase.cs @@ -62,7 +62,7 @@ namespace System.Collections { public void RemoveAt(int index) { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); Object temp = InnerList[index]; OnValidate(temp); @@ -101,13 +101,13 @@ namespace System.Collections { Object IList.this[int index] { get { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return InnerList[index]; } set { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); OnValidate(value); Object temp = InnerList[index]; @@ -163,7 +163,7 @@ namespace System.Collections { void IList.Insert(int index, Object value) { if (index < 0 || index > Count) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); OnValidate(value); OnInsert(index, value); @@ -194,7 +194,7 @@ namespace System.Collections { } protected virtual void OnValidate(Object value) { - if (value == null) throw new ArgumentNullException("value"); + if (value == null) throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); } diff --git a/src/mscorlib/src/System/Collections/Comparer.cs b/src/mscorlib/src/System/Collections/Comparer.cs index 11e26252a8..d905a6eb4a 100644 --- a/src/mscorlib/src/System/Collections/Comparer.cs +++ b/src/mscorlib/src/System/Collections/Comparer.cs @@ -36,7 +36,7 @@ namespace System.Collections { public Comparer(CultureInfo culture) { if (culture==null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.EndContractBlock(); m_compareInfo = culture.CompareInfo; @@ -86,7 +86,7 @@ namespace System.Collections { [System.Security.SecurityCritical] // auto-generated_required public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/CompatibleComparer.cs b/src/mscorlib/src/System/Collections/CompatibleComparer.cs index 85e6c3f0f3..e5d3961245 100644 --- a/src/mscorlib/src/System/Collections/CompatibleComparer.cs +++ b/src/mscorlib/src/System/Collections/CompatibleComparer.cs @@ -39,7 +39,7 @@ namespace System.Collections { public int GetHashCode(Object obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs index 9164eadad1..d815ae9422 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs @@ -103,7 +103,7 @@ namespace System.Collections.Concurrent { if (collection == null) { - throw new ArgumentNullException("collection"); + throw new ArgumentNullException(nameof(collection)); } InitializeFromCollection(collection); @@ -160,7 +160,7 @@ namespace System.Collections.Concurrent // Validate arguments. if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } // We must be careful not to corrupt the array, so we will first accumulate an @@ -441,7 +441,7 @@ namespace System.Collections.Concurrent { if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } // We must be careful not to corrupt the array, so we will first accumulate an diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs index 15d4176cff..c418aa0994 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs @@ -101,7 +101,7 @@ namespace System.Collections.Concurrent { if (collection == null) { - throw new ArgumentNullException("collection"); + throw new ArgumentNullException(nameof(collection)); } InitializeFromCollection(collection); } @@ -293,7 +293,7 @@ namespace System.Collections.Concurrent // Validate arguments. if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } // We must be careful not to corrupt the array, so we will first accumulate an @@ -327,7 +327,7 @@ namespace System.Collections.Concurrent { if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } // We must be careful not to corrupt the array, so we will first accumulate an @@ -379,7 +379,7 @@ namespace System.Collections.Concurrent { if (items == null) { - throw new ArgumentNullException("items"); + throw new ArgumentNullException(nameof(items)); } PushRange(items, 0, items.Length); } @@ -471,16 +471,16 @@ namespace System.Collections.Concurrent { if (items == null) { - throw new ArgumentNullException("items"); + throw new ArgumentNullException(nameof(items)); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ConcurrentStack_PushPopRange_CountOutOfRange")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ConcurrentStack_PushPopRange_CountOutOfRange")); } int length = items.Length; if (startIndex >= length || startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ConcurrentStack_PushPopRange_StartOutOfRange")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ConcurrentStack_PushPopRange_StartOutOfRange")); } if (length - count < startIndex) //instead of (startIndex + count > items.Length) to prevent overflow { @@ -584,7 +584,7 @@ namespace System.Collections.Concurrent { if (items == null) { - throw new ArgumentNullException("items"); + throw new ArgumentNullException(nameof(items)); } return TryPopRange(items, 0, items.Length); diff --git a/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs b/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs index a74f69069a..56be7759c9 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs @@ -97,7 +97,7 @@ namespace System.Collections.Concurrent { if (collection == null) { - throw new ArgumentNullException("collection"); + throw new ArgumentNullException(nameof(collection)); } m_collection = collection; diff --git a/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs index 2169c6dee7..5568f9b402 100644 --- a/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs +++ b/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs @@ -91,7 +91,7 @@ namespace System.Collections.Concurrent { if (list == null) { - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); } if (loadBalance) { @@ -122,7 +122,7 @@ namespace System.Collections.Concurrent if (array == null) { - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); } if (loadBalance) { @@ -172,11 +172,11 @@ namespace System.Collections.Concurrent { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if ((partitionerOptions & (~EnumerablePartitionerOptions.NoBuffering)) != 0) - throw new ArgumentOutOfRangeException("partitionerOptions"); + throw new ArgumentOutOfRangeException(nameof(partitionerOptions)); return (new DynamicPartitionerForIEnumerable<TSource>(source, partitionerOptions)); } @@ -194,7 +194,7 @@ namespace System.Collections.Concurrent // load balancing on a busy system if you make it higher than 1. int coreOversubscriptionRate = 3; - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); + if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive)); long rangeSize = (toExclusive - fromInclusive) / (PlatformHelper.ProcessorCount * coreOversubscriptionRate); if (rangeSize == 0) rangeSize = 1; @@ -212,8 +212,8 @@ namespace System.Collections.Concurrent /// less than or equal to 0.</exception> public static OrderablePartitioner<Tuple<long, long>> Create(long fromInclusive, long toExclusive, long rangeSize) { - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); - if (rangeSize <= 0) throw new ArgumentOutOfRangeException("rangeSize"); + if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive)); + if (rangeSize <= 0) throw new ArgumentOutOfRangeException(nameof(rangeSize)); return Partitioner.Create(CreateRanges(fromInclusive, toExclusive, rangeSize), EnumerablePartitionerOptions.NoBuffering); // chunk one range at a time } @@ -251,7 +251,7 @@ namespace System.Collections.Concurrent // load balancing on a busy system if you make it higher than 1. int coreOversubscriptionRate = 3; - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); + if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive)); int rangeSize = (toExclusive - fromInclusive) / (PlatformHelper.ProcessorCount * coreOversubscriptionRate); if (rangeSize == 0) rangeSize = 1; @@ -269,8 +269,8 @@ namespace System.Collections.Concurrent /// less than or equal to 0.</exception> public static OrderablePartitioner<Tuple<int, int>> Create(int fromInclusive, int toExclusive, int rangeSize) { - if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive"); - if (rangeSize <= 0) throw new ArgumentOutOfRangeException("rangeSize"); + if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive)); + if (rangeSize <= 0) throw new ArgumentOutOfRangeException(nameof(rangeSize)); return Partitioner.Create(CreateRanges(fromInclusive, toExclusive, rangeSize), EnumerablePartitionerOptions.NoBuffering); // chunk one range at a time } @@ -517,7 +517,7 @@ namespace System.Collections.Concurrent { if (partitionCount <= 0) { - throw new ArgumentOutOfRangeException("partitionCount"); + throw new ArgumentOutOfRangeException(nameof(partitionCount)); } IEnumerator<KeyValuePair<long, TSource>>[] partitions = new IEnumerator<KeyValuePair<long, TSource>>[partitionCount]; @@ -1053,7 +1053,7 @@ namespace System.Collections.Concurrent { if (partitionCount <= 0) { - throw new ArgumentOutOfRangeException("partitionCount"); + throw new ArgumentOutOfRangeException(nameof(partitionCount)); } IEnumerator<KeyValuePair<long, TSource>>[] partitions = new IEnumerator<KeyValuePair<long, TSource>>[partitionCount]; @@ -1417,7 +1417,7 @@ namespace System.Collections.Concurrent { if (partitionCount <= 0) { - throw new ArgumentOutOfRangeException("partitionCount"); + throw new ArgumentOutOfRangeException(nameof(partitionCount)); } int quotient, remainder; diff --git a/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs b/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs index 6e28493ef8..a610fce016 100644 --- a/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs +++ b/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs @@ -36,16 +36,16 @@ namespace System.Collections { public void CopyTo(Array array, int index) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if ( array.Length - index < this.Count ) - throw new ArgumentException( Environment.GetResourceString("ArgumentOutOfRange_Index"), "index"); + throw new ArgumentException( Environment.GetResourceString("ArgumentOutOfRange_Index"), nameof(index)); Contract.EndContractBlock(); // the actual copy is a NOP @@ -74,21 +74,21 @@ namespace System.Collections { public Object this[Object key] { get { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); return null; } set { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } if (!key.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "key"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(key)); if( (value != null) && (!value.GetType().IsSerializable ) ) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(value)); Contract.EndContractBlock(); throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); @@ -113,14 +113,14 @@ namespace System.Collections { public void Add(Object key, Object value) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } if (!key.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "key" ); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(key) ); if( (value != null) && (!value.GetType().IsSerializable) ) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(value)); Contract.EndContractBlock(); throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); diff --git a/src/mscorlib/src/System/Collections/Generic/Comparer.cs b/src/mscorlib/src/System/Collections/Generic/Comparer.cs index e209c16eea..6e65dafbef 100644 --- a/src/mscorlib/src/System/Collections/Generic/Comparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/Comparer.cs @@ -33,7 +33,7 @@ namespace System.Collections.Generic Contract.Ensures(Contract.Result<Comparer<T>>() != null); if (comparison == null) - throw new ArgumentNullException("comparison"); + throw new ArgumentNullException(nameof(comparison)); return new ComparisonComparer<T>(comparison); } diff --git a/src/mscorlib/src/System/Collections/Generic/DebugView.cs b/src/mscorlib/src/System/Collections/Generic/DebugView.cs index 57b91eff51..d0711e551e 100644 --- a/src/mscorlib/src/System/Collections/Generic/DebugView.cs +++ b/src/mscorlib/src/System/Collections/Generic/DebugView.cs @@ -110,7 +110,7 @@ namespace System.Collections.Generic { public Mscorlib_KeyedCollectionDebugView(KeyedCollection<K, T> keyedCollection) { if (keyedCollection == null) { - throw new ArgumentNullException("keyedCollection"); + throw new ArgumentNullException(nameof(keyedCollection)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index 9624d848f3..1a23b801ee 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -340,11 +340,11 @@ namespace System.Collections.Generic [System.Security.SecuritySafeCritical] // auto-generated internal unsafe override int IndexOf(byte[] array, byte value, int startIndex, int count) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); if (count > array.Length - startIndex) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/Hashtable.cs b/src/mscorlib/src/System/Collections/Hashtable.cs index 262ccedea6..8d74c8f24e 100644 --- a/src/mscorlib/src/System/Collections/Hashtable.cs +++ b/src/mscorlib/src/System/Collections/Hashtable.cs @@ -271,9 +271,9 @@ namespace System.Collections { // public Hashtable(int capacity, float loadFactor) { if (capacity < 0) - throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (!(loadFactor >= 0.1f && loadFactor <= 1.0f)) - throw new ArgumentOutOfRangeException("loadFactor", Environment.GetResourceString("ArgumentOutOfRange_HashtableLoadFactor", .1, 1.0)); + throw new ArgumentOutOfRangeException(nameof(loadFactor), Environment.GetResourceString("ArgumentOutOfRange_HashtableLoadFactor", .1, 1.0)); Contract.EndContractBlock(); // Based on perf work, .72 is the optimal load factor for this table. @@ -375,7 +375,7 @@ namespace System.Collections { public Hashtable(IDictionary d, float loadFactor, IHashCodeProvider hcp, IComparer comparer) : this((d != null ? d.Count : 0), loadFactor, hcp, comparer) { if (d==null) - throw new ArgumentNullException("d", Environment.GetResourceString("ArgumentNull_Dictionary")); + throw new ArgumentNullException(nameof(d), Environment.GetResourceString("ArgumentNull_Dictionary")); Contract.EndContractBlock(); IDictionaryEnumerator e = d.GetEnumerator(); @@ -385,7 +385,7 @@ namespace System.Collections { public Hashtable(IDictionary d, float loadFactor, IEqualityComparer equalityComparer) : this((d != null ? d.Count : 0), loadFactor, equalityComparer) { if (d==null) - throw new ArgumentNullException("d", Environment.GetResourceString("ArgumentNull_Dictionary")); + throw new ArgumentNullException(nameof(d), Environment.GetResourceString("ArgumentNull_Dictionary")); Contract.EndContractBlock(); IDictionaryEnumerator e = d.GetEnumerator(); @@ -501,7 +501,7 @@ namespace System.Collections { // public virtual bool ContainsKey(Object key) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); @@ -590,11 +590,11 @@ namespace System.Collections { public virtual void CopyTo(Array array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(array), Environment.GetResourceString("ArgumentNull_Array")); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - arrayIndex < Count) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayPlusOffTooSmall")); Contract.EndContractBlock(); @@ -643,7 +643,7 @@ namespace System.Collections { public virtual Object this[Object key] { get { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); @@ -872,7 +872,7 @@ namespace System.Collections { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] private void Insert (Object key, Object nvalue, bool add) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); if (count >= loadsize) { @@ -1069,7 +1069,7 @@ namespace System.Collections { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public virtual void Remove(Object key) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); Contract.Assert(!isWriterInProgress, "Race condition detected in usages of Hashtable - multiple threads appear to be writing to a Hashtable instance simultaneously! Don't do that - use Hashtable.Synchronized."); @@ -1134,7 +1134,7 @@ namespace System.Collections { [HostProtection(Synchronization=true)] public static Hashtable Synchronized(Hashtable table) { if (table==null) - throw new ArgumentNullException("table"); + throw new ArgumentNullException(nameof(table)); Contract.EndContractBlock(); return new SyncHashtable(table); } @@ -1146,7 +1146,7 @@ namespace System.Collections { [System.Security.SecurityCritical] public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); // This is imperfect - it only works well if all other writes are @@ -1302,11 +1302,11 @@ namespace System.Collections { public virtual void CopyTo(Array array, int arrayIndex) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (array.Length - arrayIndex < _hashtable.count) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayPlusOffTooSmall")); @@ -1343,11 +1343,11 @@ namespace System.Collections { public virtual void CopyTo(Array array, int arrayIndex) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (array.Length - arrayIndex < _hashtable.count) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayPlusOffTooSmall")); @@ -1402,7 +1402,7 @@ namespace System.Collections { [System.Security.SecurityCritical] // auto-generated public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); // Our serialization code hasn't been fully tweaked to be safe @@ -1461,7 +1461,7 @@ namespace System.Collections { public override bool ContainsKey(Object key) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); return _table.ContainsKey(key); @@ -1630,7 +1630,7 @@ namespace System.Collections { public HashtableDebugView( Hashtable hashtable) { if( hashtable == null) { - throw new ArgumentNullException( "hashtable"); + throw new ArgumentNullException(nameof(hashtable)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/ListDictionaryInternal.cs b/src/mscorlib/src/System/Collections/ListDictionaryInternal.cs index 944523c475..be5490b194 100644 --- a/src/mscorlib/src/System/Collections/ListDictionaryInternal.cs +++ b/src/mscorlib/src/System/Collections/ListDictionaryInternal.cs @@ -30,7 +30,7 @@ namespace System.Collections { public Object this[Object key] { get { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); DictionaryNode node = head; @@ -45,16 +45,16 @@ namespace System.Collections { } set { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); #if FEATURE_SERIALIZATION if (!key.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "key"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(key)); if( (value != null) && (!value.GetType().IsSerializable ) ) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(value)); #endif version++; @@ -132,16 +132,16 @@ namespace System.Collections { public void Add(Object key, Object value) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); #if FEATURE_SERIALIZATION if (!key.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "key" ); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(key) ); if( (value != null) && (!value.GetType().IsSerializable) ) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSerializable"), nameof(value)); #endif version++; @@ -179,7 +179,7 @@ namespace System.Collections { public bool Contains(Object key) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); for (DictionaryNode node = head; node != null; node = node.next) { @@ -192,16 +192,16 @@ namespace System.Collections { public void CopyTo(Array array, int index) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if ( array.Length - index < this.Count ) - throw new ArgumentException( Environment.GetResourceString("ArgumentOutOfRange_Index"), "index"); + throw new ArgumentException( Environment.GetResourceString("ArgumentOutOfRange_Index"), nameof(index)); Contract.EndContractBlock(); for (DictionaryNode node = head; node != null; node = node.next) { @@ -220,7 +220,7 @@ namespace System.Collections { public void Remove(Object key) { if (key == null) { - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); } Contract.EndContractBlock(); version++; @@ -328,14 +328,14 @@ namespace System.Collections { void ICollection.CopyTo(Array array, int index) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (array.Length - index < list.Count) - throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Index"), "index"); + throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Index"), nameof(index)); for (DictionaryNode node = list.head; node != null; node = node.next) { array.SetValue(isKeys ? node.key : node.value, index); index++; diff --git a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index 57dd34dc62..5c9e8c44c6 100644 --- a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -34,7 +34,7 @@ namespace System.Collections.ObjectModel public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) { - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); } Contract.EndContractBlock(); m_dictionary = dictionary; diff --git a/src/mscorlib/src/System/Collections/SortedList.cs b/src/mscorlib/src/System/Collections/SortedList.cs index 8e3926af01..658dc48a26 100644 --- a/src/mscorlib/src/System/Collections/SortedList.cs +++ b/src/mscorlib/src/System/Collections/SortedList.cs @@ -107,7 +107,7 @@ namespace System.Collections { // public SortedList(int initialCapacity) { if (initialCapacity < 0) - throw new ArgumentOutOfRangeException("initialCapacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(initialCapacity), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); keys = new Object[initialCapacity]; values = new Object[initialCapacity]; @@ -164,7 +164,7 @@ namespace System.Collections { public SortedList(IDictionary d, IComparer comparer) : this(comparer, (d != null ? d.Count : 0)) { if (d==null) - throw new ArgumentNullException("d", Environment.GetResourceString("ArgumentNull_Dictionary")); + throw new ArgumentNullException(nameof(d), Environment.GetResourceString("ArgumentNull_Dictionary")); Contract.EndContractBlock(); d.Keys.CopyTo(keys, 0); d.Values.CopyTo(values, 0); @@ -176,7 +176,7 @@ namespace System.Collections { // ArgumentException is thrown if the key is already present in the sorted list. // public virtual void Add(Object key, Object value) { - if (key == null) throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + if (key == null) throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); Contract.EndContractBlock(); int i = Array.BinarySearch(keys, 0, _size, key, comparer); if (i >= 0) @@ -196,7 +196,7 @@ namespace System.Collections { } set { if (value < Count) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); } Contract.EndContractBlock(); @@ -325,11 +325,11 @@ namespace System.Collections { // Copies the values in this SortedList to an array. public virtual void CopyTo(Array array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(array), Environment.GetResourceString("ArgumentNull_Array")); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(arrayIndex), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - arrayIndex < Count) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayPlusOffTooSmall")); Contract.EndContractBlock(); @@ -368,7 +368,7 @@ namespace System.Collections { // public virtual Object GetByIndex(int index) { if (index < 0 || index >= Count) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return values[index]; } @@ -394,7 +394,7 @@ namespace System.Collections { // Returns the key of the entry at the given index. // public virtual Object GetKey(int index) { - if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return keys[index]; } @@ -442,7 +442,7 @@ namespace System.Collections { return null; } set { - if (key == null) throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + if (key == null) throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); Contract.EndContractBlock(); int i = Array.BinarySearch(keys, 0, _size, key, comparer); if (i >= 0) { @@ -463,7 +463,7 @@ namespace System.Collections { // public virtual int IndexOfKey(Object key) { if (key == null) - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); Contract.EndContractBlock(); int ret = Array.BinarySearch(keys, 0, _size, key, comparer); return ret >=0 ? ret : -1; @@ -496,7 +496,7 @@ namespace System.Collections { // decreased by one. // public virtual void RemoveAt(int index) { - if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); _size--; if (index < _size) { @@ -522,7 +522,7 @@ namespace System.Collections { // the given entry is overwritten. // public virtual void SetByIndex(int index, Object value) { - if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); values[index] = value; version++; @@ -533,7 +533,7 @@ namespace System.Collections { [HostProtection(Synchronization=true)] public static SortedList Synchronized(SortedList list) { if (list==null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.EndContractBlock(); return new SyncSortedList(list); } @@ -677,7 +677,7 @@ namespace System.Collections { public override int IndexOfKey(Object key) { if (key == null) - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); Contract.EndContractBlock(); lock(_root) { @@ -888,7 +888,7 @@ namespace System.Collections { public virtual int IndexOf(Object key) { if (key==null) - throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); Contract.EndContractBlock(); int i = Array.BinarySearch(sortedList.keys, 0, @@ -993,7 +993,7 @@ namespace System.Collections { public SortedListDebugView( SortedList sortedList) { if( sortedList == null) { - throw new ArgumentNullException("sortedList"); + throw new ArgumentNullException(nameof(sortedList)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Collections/Stack.cs b/src/mscorlib/src/System/Collections/Stack.cs index 0384a4ee81..d36c8e93cb 100644 --- a/src/mscorlib/src/System/Collections/Stack.cs +++ b/src/mscorlib/src/System/Collections/Stack.cs @@ -44,7 +44,7 @@ namespace System.Collections { // must be a non-negative number. public Stack(int initialCapacity) { if (initialCapacity < 0) - throw new ArgumentOutOfRangeException("initialCapacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(initialCapacity), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (initialCapacity < _defaultCapacity) initialCapacity = _defaultCapacity; // Simplify doubling logic in Push. @@ -59,7 +59,7 @@ namespace System.Collections { public Stack(ICollection col) : this((col==null ? 32 : col.Count)) { if (col==null) - throw new ArgumentNullException("col"); + throw new ArgumentNullException(nameof(col)); Contract.EndContractBlock(); IEnumerator en = col.GetEnumerator(); while(en.MoveNext()) @@ -121,11 +121,11 @@ namespace System.Collections { // Copies the stack into an array. public virtual void CopyTo(Array array, int index) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - index < _size) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -192,7 +192,7 @@ namespace System.Collections { [HostProtection(Synchronization=true)] public static Stack Synchronized(Stack stack) { if (stack==null) - throw new ArgumentNullException("stack"); + throw new ArgumentNullException(nameof(stack)); Contract.Ensures(Contract.Result<Stack>() != null); Contract.EndContractBlock(); return new SyncStack(stack); @@ -363,7 +363,7 @@ namespace System.Collections { public StackDebugView( Stack stack) { if( stack == null) - throw new ArgumentNullException("stack"); + throw new ArgumentNullException(nameof(stack)); Contract.EndContractBlock(); this.stack = stack; diff --git a/src/mscorlib/src/System/Convert.cs b/src/mscorlib/src/System/Convert.cs index d1468314f2..50ebba029f 100644 --- a/src/mscorlib/src/System/Convert.cs +++ b/src/mscorlib/src/System/Convert.cs @@ -259,7 +259,7 @@ namespace System { internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) { Contract.Requires(value != null, "[Convert.DefaultToType]value!=null"); if (targetType==null) { - throw new ArgumentNullException("targetType"); + throw new ArgumentNullException(nameof(targetType)); } Contract.EndContractBlock(); @@ -322,7 +322,7 @@ namespace System { public static Object ChangeType(Object value, Type conversionType, IFormatProvider provider) { if( conversionType == null) { - throw new ArgumentNullException("conversionType"); + throw new ArgumentNullException(nameof(conversionType)); } Contract.EndContractBlock(); @@ -575,7 +575,7 @@ namespace System { public static char ToChar(String value, IFormatProvider provider) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); if (value.Length != 1) @@ -2155,7 +2155,7 @@ namespace System { public static String ToBase64String(byte[] inArray) { if (inArray==null) { - throw new ArgumentNullException("inArray"); + throw new ArgumentNullException(nameof(inArray)); } Contract.Ensures(Contract.Result<string>() != null); Contract.EndContractBlock(); @@ -2165,7 +2165,7 @@ namespace System { [System.Runtime.InteropServices.ComVisible(false)] public static String ToBase64String(byte[] inArray, Base64FormattingOptions options) { if (inArray==null) { - throw new ArgumentNullException("inArray"); + throw new ArgumentNullException(nameof(inArray)); } Contract.Ensures(Contract.Result<string>() != null); Contract.EndContractBlock(); @@ -2181,11 +2181,11 @@ namespace System { public static unsafe String ToBase64String(byte[] inArray, int offset, int length, Base64FormattingOptions options) { //Do data verfication if (inArray==null) - throw new ArgumentNullException("inArray"); + throw new ArgumentNullException(nameof(inArray)); if (length<0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (offset<0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if (options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks) throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options)); Contract.Ensures(Contract.Result<string>() != null); @@ -2196,7 +2196,7 @@ namespace System { inArrayLength = inArray.Length; if (offset > (inArrayLength - length)) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); if (inArrayLength == 0) return String.Empty; @@ -2228,15 +2228,15 @@ namespace System { public static unsafe int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut, Base64FormattingOptions options) { //Do data verfication if (inArray==null) - throw new ArgumentNullException("inArray"); + throw new ArgumentNullException(nameof(inArray)); if (outArray==null) - throw new ArgumentNullException("outArray"); + throw new ArgumentNullException(nameof(outArray)); if (length<0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (offsetIn<0) - throw new ArgumentOutOfRangeException("offsetIn", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(offsetIn), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if (offsetOut<0) - throw new ArgumentOutOfRangeException("offsetOut", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(offsetOut), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if( options < Base64FormattingOptions.None || options > Base64FormattingOptions.InsertLineBreaks) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options)); @@ -2255,7 +2255,7 @@ namespace System { inArrayLength = inArray.Length; if (offsetIn > (int)(inArrayLength - length)) - throw new ArgumentOutOfRangeException("offsetIn", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); + throw new ArgumentOutOfRangeException(nameof(offsetIn), Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); if (inArrayLength == 0) return 0; @@ -2268,7 +2268,7 @@ namespace System { numElementsToCopy = ToBase64_CalculateAndValidateOutputLength(length, insertLineBreaks); if (offsetOut > (int)(outArrayLength - numElementsToCopy)) - throw new ArgumentOutOfRangeException("offsetOut", Environment.GetResourceString("ArgumentOutOfRange_OffsetOut")); + throw new ArgumentOutOfRangeException(nameof(offsetOut), Environment.GetResourceString("ArgumentOutOfRange_OffsetOut")); fixed (char* outChars = &outArray[offsetOut]) { fixed (byte* inData = inArray) { @@ -2372,7 +2372,7 @@ namespace System { // "s" is an unfortunate parameter name, but we need to keep it for backward compat. if (s == null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); Contract.EndContractBlock(); @@ -2396,16 +2396,16 @@ namespace System { public static Byte[] FromBase64CharArray(Char[] inArray, Int32 offset, Int32 length) { if (inArray == null) - throw new ArgumentNullException("inArray"); + throw new ArgumentNullException(nameof(inArray)); if (length < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if (offset > inArray.Length - length) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/CurrentTimeZone.cs b/src/mscorlib/src/System/CurrentTimeZone.cs index f015c05b33..59decb5c05 100644 --- a/src/mscorlib/src/System/CurrentTimeZone.cs +++ b/src/mscorlib/src/System/CurrentTimeZone.cs @@ -169,7 +169,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated public override DaylightTime GetDaylightChanges(int year) { if (year < 1 || year > 9999) { - throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 9999)); + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 9999)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/DateTime.cs b/src/mscorlib/src/System/DateTime.cs index ff8ad295da..788f1ca1e2 100644 --- a/src/mscorlib/src/System/DateTime.cs +++ b/src/mscorlib/src/System/DateTime.cs @@ -143,7 +143,7 @@ namespace System { // public DateTime(long ticks) { if (ticks < MinTicks || ticks > MaxTicks) - throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks")); + throw new ArgumentOutOfRangeException(nameof(ticks), Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks")); Contract.EndContractBlock(); dateData = (UInt64)ticks; } @@ -154,10 +154,10 @@ namespace System { public DateTime(long ticks, DateTimeKind kind) { if (ticks < MinTicks || ticks > MaxTicks) { - throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks")); + throw new ArgumentOutOfRangeException(nameof(ticks), Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks")); } if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), nameof(kind)); } Contract.EndContractBlock(); this.dateData = ((UInt64)ticks | ((UInt64)kind << KindShift)); @@ -165,7 +165,7 @@ namespace System { internal DateTime(long ticks, DateTimeKind kind, Boolean isAmbiguousDst) { if (ticks < MinTicks || ticks > MaxTicks) { - throw new ArgumentOutOfRangeException("ticks", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks")); + throw new ArgumentOutOfRangeException(nameof(ticks), Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadTicks")); } Contract.Requires(kind == DateTimeKind.Local, "Internal Constructor is for local times only"); Contract.EndContractBlock(); @@ -196,7 +196,7 @@ namespace System { public DateTime(int year, int month, int day, int hour, int minute, int second, DateTimeKind kind) { if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), nameof(kind)); } Contract.EndContractBlock(); Int64 ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); @@ -208,7 +208,7 @@ namespace System { // public DateTime(int year, int month, int day, int hour, int minute, int second, Calendar calendar) { if (calendar == null) - throw new ArgumentNullException("calendar"); + throw new ArgumentNullException(nameof(calendar)); Contract.EndContractBlock(); this.dateData = (UInt64)calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; } @@ -218,7 +218,7 @@ namespace System { // public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond) { if (millisecond < 0 || millisecond >= MillisPerSecond) { - throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); + throw new ArgumentOutOfRangeException(nameof(millisecond), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); } Contract.EndContractBlock(); Int64 ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); @@ -230,10 +230,10 @@ namespace System { public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, DateTimeKind kind) { if (millisecond < 0 || millisecond >= MillisPerSecond) { - throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); + throw new ArgumentOutOfRangeException(nameof(millisecond), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); } if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), nameof(kind)); } Contract.EndContractBlock(); Int64 ticks = DateToTicks(year, month, day) + TimeToTicks(hour, minute, second); @@ -248,9 +248,9 @@ namespace System { // public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar) { if (calendar == null) - throw new ArgumentNullException("calendar"); + throw new ArgumentNullException(nameof(calendar)); if (millisecond < 0 || millisecond >= MillisPerSecond) { - throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); + throw new ArgumentOutOfRangeException(nameof(millisecond), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); } Contract.EndContractBlock(); Int64 ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; @@ -262,12 +262,12 @@ namespace System { public DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, DateTimeKind kind) { if (calendar == null) - throw new ArgumentNullException("calendar"); + throw new ArgumentNullException(nameof(calendar)); if (millisecond < 0 || millisecond >= MillisPerSecond) { - throw new ArgumentOutOfRangeException("millisecond", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); + throw new ArgumentOutOfRangeException(nameof(millisecond), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, MillisPerSecond - 1)); } if (kind < DateTimeKind.Unspecified || kind > DateTimeKind.Local) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), "kind"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidDateTimeKind"), nameof(kind)); } Contract.EndContractBlock(); Int64 ticks = calendar.ToDateTime(year, month, day, hour, minute, second, 0).Ticks; @@ -279,7 +279,7 @@ namespace System { private DateTime(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); Boolean foundTicks = false; @@ -346,7 +346,7 @@ namespace System { private DateTime Add(double value, int scale) { long millis = (long)(value * scale + (value >= 0? 0.5: -0.5)); if (millis <= -MaxMillis || millis >= MaxMillis) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_AddValue")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_AddValue")); return AddTicks(millis * TicksPerMillisecond); } @@ -408,7 +408,7 @@ namespace System { // y1. // public DateTime AddMonths(int months) { - if (months < -120000 || months > 120000) throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadMonths")); + if (months < -120000 || months > 120000) throw new ArgumentOutOfRangeException(nameof(months), Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadMonths")); Contract.EndContractBlock(); int y = GetDatePart(DatePartYear); int m = GetDatePart(DatePartMonth); @@ -423,7 +423,7 @@ namespace System { y = y + (i - 11) / 12; } if (y < 1 || y > 9999) { - throw new ArgumentOutOfRangeException("months", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); + throw new ArgumentOutOfRangeException(nameof(months), Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); } int days = DaysInMonth(y, m); if (d > days) d = days; @@ -447,7 +447,7 @@ namespace System { public DateTime AddTicks(long value) { long ticks = InternalTicks; if (value > MaxTicks - ticks || value < MinTicks - ticks) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); } return new DateTime((UInt64)(ticks + value) | InternalKind); } @@ -460,10 +460,10 @@ namespace System { // DateTime becomes 2/28. Otherwise, the month, day, and time-of-day // parts of the result are the same as those of this DateTime. // - public DateTime AddYears(int value) { - if (value < -10000 || value > 10000) throw new ArgumentOutOfRangeException("years", Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadYears")); + public DateTime AddYears(int years) { + if (years < -10000 || years > 10000) throw new ArgumentOutOfRangeException(nameof(years), Environment.GetResourceString("ArgumentOutOfRange_DateTimeBadYears")); Contract.EndContractBlock(); - return AddMonths(value * 12); + return AddMonths(years * 12); } // Compares two DateTime values, returning an integer that indicates @@ -527,7 +527,7 @@ namespace System { // month arguments. // public static int DaysInMonth(int year, int month) { - if (month < 1 || month > 12) throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + if (month < 1 || month > 12) throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); Contract.EndContractBlock(); // IsLeapYear checks the year argument int[] days = IsLeapYear(year)? DaysToMonth366: DaysToMonth365; @@ -629,7 +629,7 @@ namespace System { ticks += TicksPerDay; } if (ticks < MinTicks || ticks > MaxTicks) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), "dateData"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), nameof(dateData)); } return new DateTime(ticks, DateTimeKind.Local, isAmbiguousLocalDst); } @@ -643,7 +643,7 @@ namespace System { internal static DateTime FromBinaryRaw(Int64 dateData) { Int64 ticks = dateData & (Int64)TicksMask; if (ticks < MinTicks || ticks > MaxTicks) - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), "dateData"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeBadBinaryData"), nameof(dateData)); return new DateTime((UInt64)dateData); } @@ -657,7 +657,7 @@ namespace System { public static DateTime FromFileTimeUtc(long fileTime) { if (fileTime < 0 || fileTime > MaxTicks - FileTimeOffset) { - throw new ArgumentOutOfRangeException("fileTime", Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid")); + throw new ArgumentOutOfRangeException(nameof(fileTime), Environment.GetResourceString("ArgumentOutOfRange_FileTimeInvalid")); } Contract.EndContractBlock(); @@ -675,7 +675,7 @@ namespace System { [System.Security.SecurityCritical /*auto-generated_required*/] void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -985,7 +985,7 @@ namespace System { // public static bool IsLeapYear(int year) { if (year < 1 || year > 9999) { - throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_Year")); + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_Year")); } Contract.EndContractBlock(); return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); @@ -1042,7 +1042,7 @@ namespace System { long ticks = InternalTicks; long valueTicks = value._ticks; if (ticks - MinTicks < valueTicks || ticks - MaxTicks > valueTicks) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); } return new DateTime((UInt64)(ticks - valueTicks) | InternalKind); } @@ -1184,7 +1184,7 @@ namespace System { long ticks = d.InternalTicks; long valueTicks = t._ticks; if (valueTicks > MaxTicks - ticks || valueTicks < MinTicks - ticks) { - throw new ArgumentOutOfRangeException("t", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); + throw new ArgumentOutOfRangeException(nameof(t), Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); } return new DateTime((UInt64)(ticks + valueTicks) | d.InternalKind); } @@ -1193,7 +1193,7 @@ namespace System { long ticks = d.InternalTicks; long valueTicks = t._ticks; if (ticks - MinTicks < valueTicks || ticks - MaxTicks > valueTicks) { - throw new ArgumentOutOfRangeException("t", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); + throw new ArgumentOutOfRangeException(nameof(t), Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic")); } return new DateTime((UInt64)(ticks - valueTicks) | d.InternalKind); } diff --git a/src/mscorlib/src/System/DateTimeOffset.cs b/src/mscorlib/src/System/DateTimeOffset.cs index 3e63c76124..4176304ffa 100644 --- a/src/mscorlib/src/System/DateTimeOffset.cs +++ b/src/mscorlib/src/System/DateTimeOffset.cs @@ -87,12 +87,12 @@ namespace System { public DateTimeOffset(DateTime dateTime, TimeSpan offset) { if (dateTime.Kind == DateTimeKind.Local) { if (offset != TimeZoneInfo.GetLocalUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime)) { - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetLocalMismatch"), "offset"); + throw new ArgumentException(Environment.GetResourceString("Argument_OffsetLocalMismatch"), nameof(offset)); } } else if (dateTime.Kind == DateTimeKind.Utc) { if (offset != TimeSpan.Zero) { - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetUtcMismatch"), "offset"); + throw new ArgumentException(Environment.GetResourceString("Argument_OffsetUtcMismatch"), nameof(offset)); } } m_offsetMinutes = ValidateOffset(offset); @@ -479,7 +479,7 @@ namespace System { public static DateTimeOffset FromUnixTimeSeconds(long seconds) { if (seconds < UnixMinSeconds || seconds > UnixMaxSeconds) { - throw new ArgumentOutOfRangeException("seconds", + throw new ArgumentOutOfRangeException(nameof(seconds), string.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), UnixMinSeconds, UnixMaxSeconds)); } @@ -492,7 +492,7 @@ namespace System { const long MaxMilliseconds = DateTime.MaxTicks / TimeSpan.TicksPerMillisecond - UnixEpochMilliseconds; if (milliseconds < MinMilliseconds || milliseconds > MaxMilliseconds) { - throw new ArgumentOutOfRangeException("milliseconds", + throw new ArgumentOutOfRangeException(nameof(milliseconds), string.Format(Environment.GetResourceString("ArgumentOutOfRange_Range"), MinMilliseconds, MaxMilliseconds)); } @@ -516,7 +516,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -528,7 +528,7 @@ namespace System { DateTimeOffset(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } m_dateTime = (DateTime)info.GetValue("DateTime", typeof(DateTime)); @@ -739,10 +739,10 @@ namespace System { private static Int16 ValidateOffset(TimeSpan offset) { Int64 ticks = offset.Ticks; if (ticks % TimeSpan.TicksPerMinute != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetPrecision"), "offset"); + throw new ArgumentException(Environment.GetResourceString("Argument_OffsetPrecision"), nameof(offset)); } if (ticks < MinOffset || ticks > MaxOffset) { - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("Argument_OffsetOutOfRange")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("Argument_OffsetOutOfRange")); } return (Int16)(offset.Ticks / TimeSpan.TicksPerMinute); } @@ -756,7 +756,7 @@ namespace System { // 14 hours and the DateTime instance is more than that distance from the boundaries of Int64. Int64 utcTicks = dateTime.Ticks - offset.Ticks; if (utcTicks < DateTime.MinTicks || utcTicks > DateTime.MaxTicks) { - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("Argument_UTCOutOfRange")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("Argument_UTCOutOfRange")); } // make sure the Kind is set to Unspecified // diff --git a/src/mscorlib/src/System/Decimal.cs b/src/mscorlib/src/System/Decimal.cs index 8a2c30ffa8..0fb2bd1746 100644 --- a/src/mscorlib/src/System/Decimal.cs +++ b/src/mscorlib/src/System/Decimal.cs @@ -264,7 +264,7 @@ namespace System { private void SetBits(int[] bits) { if (bits==null) - throw new ArgumentNullException("bits"); + throw new ArgumentNullException(nameof(bits)); Contract.EndContractBlock(); if (bits.Length == 4) { int f = bits[3]; @@ -283,7 +283,7 @@ namespace System { // public Decimal(int lo, int mid, int hi, bool isNegative, byte scale) { if (scale > 28) - throw new ArgumentOutOfRangeException("scale", Environment.GetResourceString("ArgumentOutOfRange_DecimalScale")); + throw new ArgumentOutOfRangeException(nameof(scale), Environment.GetResourceString("ArgumentOutOfRange_DecimalScale")); Contract.EndContractBlock(); this.lo = lo; this.mid = mid; @@ -760,9 +760,9 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated public static Decimal Round(Decimal d, int decimals, MidpointRounding mode) { if ((decimals < 0) || (decimals > 28)) - throw new ArgumentOutOfRangeException("decimals", Environment.GetResourceString("ArgumentOutOfRange_DecimalRound")); + throw new ArgumentOutOfRangeException(nameof(decimals), Environment.GetResourceString("ArgumentOutOfRange_DecimalRound")); if (mode < MidpointRounding.ToEven || mode > MidpointRounding.AwayFromZero) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidEnumValue", mode, "MidpointRounding"), "mode"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidEnumValue", mode, nameof(MidpointRounding)), nameof(mode)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/DefaultBinder.cs b/src/mscorlib/src/System/DefaultBinder.cs index 405055e844..de0433daf6 100644 --- a/src/mscorlib/src/System/DefaultBinder.cs +++ b/src/mscorlib/src/System/DefaultBinder.cs @@ -39,7 +39,7 @@ namespace System { ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, out Object state) { if (match == null || match.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); + throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof(match)); Contract.EndContractBlock(); MethodBase[] candidates = (MethodBase[]) match.Clone(); @@ -441,7 +441,7 @@ namespace System { public override FieldInfo BindToField(BindingFlags bindingAttr,FieldInfo[] match, Object value,CultureInfo cultureInfo) { if (match == null) { - throw new ArgumentNullException("match"); + throw new ArgumentNullException(nameof(match)); } int i; @@ -524,13 +524,13 @@ namespace System { for (i=0;i<types.Length;i++) { realTypes[i] = types[i].UnderlyingSystemType; if (!(realTypes[i] is RuntimeType)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"types"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(types)); } types = realTypes; // We don't automatically jump out on exact match. if (match == null || match.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); + throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof(match)); MethodBase[] candidates = (MethodBase[]) match.Clone(); @@ -596,10 +596,10 @@ namespace System { // Allow a null indexes array. But if it is not null, every element must be non-null as well. if (indexes != null && !Contract.ForAll(indexes, delegate(Type t) { return t != null; })) { - throw new ArgumentNullException("indexes"); + throw new ArgumentNullException(nameof(indexes)); } if (match == null || match.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match"); + throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof(match)); Contract.EndContractBlock(); PropertyInfo[] candidates = (PropertyInfo[]) match.Clone(); @@ -732,7 +732,7 @@ namespace System { public static MethodBase ExactBinding(MethodBase[] match,Type[] types,ParameterModifier[] modifiers) { if (match==null) - throw new ArgumentNullException("match"); + throw new ArgumentNullException(nameof(match)); Contract.EndContractBlock(); MethodBase[] aExactMatches = new MethodBase[match.Length]; int cExactMatches = 0; @@ -772,7 +772,7 @@ namespace System { public static PropertyInfo ExactPropertyBinding(PropertyInfo[] match,Type returnType,Type[] types,ParameterModifier[] modifiers) { if (match==null) - throw new ArgumentNullException("match"); + throw new ArgumentNullException(nameof(match)); Contract.EndContractBlock(); PropertyInfo bestMatch = null; diff --git a/src/mscorlib/src/System/Delegate.cs b/src/mscorlib/src/System/Delegate.cs index 110555423c..347607f6f5 100644 --- a/src/mscorlib/src/System/Delegate.cs +++ b/src/mscorlib/src/System/Delegate.cs @@ -46,10 +46,10 @@ namespace System { protected Delegate(Object target,String method) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); // This API existed in v1/v1.1 and only expected to create closed @@ -71,18 +71,18 @@ namespace System { protected unsafe Delegate(Type target,String method) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); if (target.IsGenericType && target.ContainsGenericParameters) - throw new ArgumentException(Environment.GetResourceString("Arg_UnboundGenParam"), "target"); + throw new ArgumentException(Environment.GetResourceString("Arg_UnboundGenParam"), nameof(target)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); RuntimeType rtTarget = target as RuntimeType; if (rtTarget == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "target"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(target)); // This API existed in v1/v1.1 and only expected to create open // static delegates. Constrain the call to BindToMethodName to such @@ -354,18 +354,18 @@ namespace System { public static Delegate CreateDelegate(Type type, Object target, String method, bool ignoreCase, bool throwOnBindFailure) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); RuntimeType rtType = type as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(type)); if (!rtType.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),"type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),nameof(type)); Delegate d = InternalAlloc(rtType); // This API existed in v1/v1.1 and only expected to create closed @@ -406,23 +406,23 @@ namespace System { public static Delegate CreateDelegate(Type type, Type target, String method, bool ignoreCase, bool throwOnBindFailure) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); if (target.IsGenericType && target.ContainsGenericParameters) - throw new ArgumentException(Environment.GetResourceString("Arg_UnboundGenParam"), "target"); + throw new ArgumentException(Environment.GetResourceString("Arg_UnboundGenParam"), nameof(target)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); RuntimeType rtType = type as RuntimeType; RuntimeType rtTarget = target as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(type)); if (rtTarget == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "target"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(target)); if (!rtType.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),"type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),nameof(type)); Delegate d = InternalAlloc(rtType); // This API existed in v1/v1.1 and only expected to create open @@ -449,21 +449,21 @@ namespace System { { // Validate the parameters. if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); RuntimeType rtType = type as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(type)); RuntimeMethodInfo rmi = method as RuntimeMethodInfo; if (rmi == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "method"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(method)); if (!rtType.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(type)); // This API existed in v1/v1.1 and only expected to create closed // instance delegates. Constrain the call to BindToMethodInfo to @@ -500,21 +500,21 @@ namespace System { { // Validate the parameters. if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); RuntimeType rtType = type as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(type)); RuntimeMethodInfo rmi = method as RuntimeMethodInfo; if (rmi == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "method"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(method)); if (!rtType.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(type)); // This API is new in Whidbey and allows the full range of delegate // flexability (open or closed delegates binding to static or @@ -571,18 +571,18 @@ namespace System { { // Validate the parameters. if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); if (method.IsNullHandle()) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); RuntimeType rtType = type as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(type)); if (!rtType.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),"type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(type)); // Initialize the method... Delegate d = InternalAlloc(rtType); @@ -605,18 +605,18 @@ namespace System { { // Validate the parameters. if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); RuntimeMethodInfo rtMethod = method as RuntimeMethodInfo; if (rtMethod == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "method"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(method)); if (!type.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"),"type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(type)); // This API is used by the formatters when deserializing a delegate. // They pass us the specific target method (that was already the diff --git a/src/mscorlib/src/System/DelegateSerializationHolder.cs b/src/mscorlib/src/System/DelegateSerializationHolder.cs index a6280333db..9313dfd4dd 100644 --- a/src/mscorlib/src/System/DelegateSerializationHolder.cs +++ b/src/mscorlib/src/System/DelegateSerializationHolder.cs @@ -24,7 +24,7 @@ namespace System // Used for MulticastDelegate if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); if (!method.IsPublic || (method.DeclaringType != null && !method.DeclaringType.IsVisible)) @@ -120,7 +120,7 @@ namespace System private DelegateSerializationHolder(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); bool bNewWire = true; @@ -182,7 +182,7 @@ namespace System private DelegateEntry OldDelegateWireFormat(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); String delegateType = info.GetString("DelegateType"); diff --git a/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs b/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs index e002e6a5c1..057d40f7ca 100644 --- a/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs +++ b/src/mscorlib/src/System/Diagnostics/Contracts/Contracts.cs @@ -654,7 +654,7 @@ namespace System.Diagnostics.Contracts { throw new ArgumentException("fromInclusive must be less than or equal to toExclusive."); #endif if (predicate == null) - throw new ArgumentNullException("predicate"); + throw new ArgumentNullException(nameof(predicate)); Contract.EndContractBlock(); for (int i = fromInclusive; i < toExclusive; i++) @@ -679,9 +679,9 @@ namespace System.Diagnostics.Contracts { public static bool ForAll<T>(IEnumerable<T> collection, Predicate<T> predicate) { if (collection == null) - throw new ArgumentNullException("collection"); + throw new ArgumentNullException(nameof(collection)); if (predicate == null) - throw new ArgumentNullException("predicate"); + throw new ArgumentNullException(nameof(predicate)); Contract.EndContractBlock(); foreach (T t in collection) @@ -716,7 +716,7 @@ namespace System.Diagnostics.Contracts { throw new ArgumentException("fromInclusive must be less than or equal to toExclusive."); #endif if (predicate == null) - throw new ArgumentNullException("predicate"); + throw new ArgumentNullException(nameof(predicate)); Contract.EndContractBlock(); for (int i = fromInclusive; i < toExclusive; i++) @@ -740,9 +740,9 @@ namespace System.Diagnostics.Contracts { public static bool Exists<T>(IEnumerable<T> collection, Predicate<T> predicate) { if (collection == null) - throw new ArgumentNullException("collection"); + throw new ArgumentNullException(nameof(collection)); if (predicate == null) - throw new ArgumentNullException("predicate"); + throw new ArgumentNullException(nameof(predicate)); Contract.EndContractBlock(); foreach (T t in collection) diff --git a/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs b/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs index 804318e702..8434447c5c 100644 --- a/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs +++ b/src/mscorlib/src/System/Diagnostics/Contracts/ContractsBCL.cs @@ -99,7 +99,7 @@ namespace System.Diagnostics.Contracts { static partial void ReportFailure(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException) { if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume) - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", failureKind), "failureKind"); + throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", failureKind), nameof(failureKind)); Contract.EndContractBlock(); // displayMessage == null means: yes we handled it. Otherwise it is the localized failure message @@ -331,7 +331,7 @@ namespace System.Runtime.CompilerServices static partial void RaiseContractFailedEventImplementation(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException, ref string resultFailureMessage) { if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume) - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", failureKind), "failureKind"); + throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", failureKind), nameof(failureKind)); Contract.EndContractBlock(); string returnValue; diff --git a/src/mscorlib/src/System/Diagnostics/DebuggerAttributes.cs b/src/mscorlib/src/System/Diagnostics/DebuggerAttributes.cs index 6adcf34eda..e75b653a0b 100644 --- a/src/mscorlib/src/System/Diagnostics/DebuggerAttributes.cs +++ b/src/mscorlib/src/System/Diagnostics/DebuggerAttributes.cs @@ -142,7 +142,7 @@ namespace System.Diagnostics { public DebuggerBrowsableAttribute(DebuggerBrowsableState state) { if( state < DebuggerBrowsableState.Never || state > DebuggerBrowsableState.RootHidden) - throw new ArgumentOutOfRangeException("state"); + throw new ArgumentOutOfRangeException(nameof(state)); Contract.EndContractBlock(); this.state = state; @@ -166,7 +166,7 @@ namespace System.Diagnostics { public DebuggerTypeProxyAttribute(Type type) { if (type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); @@ -186,7 +186,7 @@ namespace System.Diagnostics { { set { if( value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); @@ -257,7 +257,7 @@ namespace System.Diagnostics { { set { if( value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); @@ -302,7 +302,7 @@ namespace System.Diagnostics { public DebuggerVisualizerAttribute(string visualizerTypeName, Type visualizerObjectSource) { if (visualizerObjectSource == null) { - throw new ArgumentNullException("visualizerObjectSource"); + throw new ArgumentNullException(nameof(visualizerObjectSource)); } Contract.EndContractBlock(); this.visualizerName = visualizerTypeName; @@ -311,7 +311,7 @@ namespace System.Diagnostics { public DebuggerVisualizerAttribute(Type visualizer) { if (visualizer == null) { - throw new ArgumentNullException("visualizer"); + throw new ArgumentNullException(nameof(visualizer)); } Contract.EndContractBlock(); this.visualizerName = visualizer.AssemblyQualifiedName; @@ -319,10 +319,10 @@ namespace System.Diagnostics { public DebuggerVisualizerAttribute(Type visualizer, Type visualizerObjectSource) { if (visualizer == null) { - throw new ArgumentNullException("visualizer"); + throw new ArgumentNullException(nameof(visualizer)); } if (visualizerObjectSource == null) { - throw new ArgumentNullException("visualizerObjectSource"); + throw new ArgumentNullException(nameof(visualizerObjectSource)); } Contract.EndContractBlock(); this.visualizerName = visualizer.AssemblyQualifiedName; @@ -331,7 +331,7 @@ namespace System.Diagnostics { public DebuggerVisualizerAttribute(Type visualizer, string visualizerObjectSourceTypeName) { if (visualizer == null) { - throw new ArgumentNullException("visualizer"); + throw new ArgumentNullException(nameof(visualizer)); } Contract.EndContractBlock(); this.visualizerName = visualizer.AssemblyQualifiedName; @@ -356,7 +356,7 @@ namespace System.Diagnostics { { set { if( value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs b/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs index e08d04ede6..ce61234779 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/EventSource.cs @@ -3239,7 +3239,7 @@ namespace System.Diagnostics.Tracing return null; #else // ES_BUILD_PCL && PROJECTN - throw new ArgumentException(Resources.GetResourceString("EventSource", "EventSource_PCLPlatformNotSupportedReflection")); + throw new ArgumentException(Resources.GetResourceString("EventSource", nameof(EventSource_PCLPlatformNotSupportedReflection))); #endif } diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventPayload.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventPayload.cs index be97447301..a894d89d2b 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventPayload.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventPayload.cs @@ -40,7 +40,7 @@ namespace System.Diagnostics.Tracing get { if (key == null) - throw new System.ArgumentNullException("key"); + throw new System.ArgumentNullException(nameof(key)); int position = 0; foreach(var name in m_names) @@ -83,7 +83,7 @@ namespace System.Diagnostics.Tracing public bool ContainsKey(string key) { if (key == null) - throw new System.ArgumentNullException("key"); + throw new System.ArgumentNullException(nameof(key)); foreach (var item in m_names) { @@ -129,7 +129,7 @@ namespace System.Diagnostics.Tracing public bool TryGetValue(string key, out object value) { if (key == null) - throw new System.ArgumentNullException("key"); + throw new System.ArgumentNullException(nameof(key)); int position = 0; foreach (var name in m_names) diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventSourceActivity.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventSourceActivity.cs index fccfd48721..38c1767462 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventSourceActivity.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/EventSourceActivity.cs @@ -35,7 +35,7 @@ namespace System.Diagnostics.Tracing public EventSourceActivity(EventSource eventSource) { if (eventSource == null) - throw new ArgumentNullException("eventSource"); + throw new ArgumentNullException(nameof(eventSource)); Contract.EndContractBlock(); this.eventSource = eventSource; diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/FieldMetadata.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/FieldMetadata.cs index 45673f7ab5..309226b84d 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/FieldMetadata.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/FieldMetadata.cs @@ -108,7 +108,7 @@ namespace System.Diagnostics.Tracing if (name == null) { throw new ArgumentNullException( - "name", + nameof(name), "This usually means that the object passed to Write is of a type that" + " does not support being used as the top-level object in an event," + " e.g. a primitive or built-in type."); diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/Statics.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/Statics.cs index fa0f79f58f..516c8ba19a 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/Statics.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/Statics.cs @@ -175,7 +175,7 @@ namespace System.Diagnostics.Tracing { if (name != null && 0 <= name.IndexOf('\0')) { - throw new ArgumentOutOfRangeException("name"); + throw new ArgumentOutOfRangeException(nameof(name)); } } diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventSource.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventSource.cs index 963c492419..a34ed7bf0b 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventSource.cs @@ -100,7 +100,7 @@ namespace System.Diagnostics.Tracing { if (eventSourceName == null) { - throw new ArgumentNullException("eventSourceName"); + throw new ArgumentNullException(nameof(eventSourceName)); } Contract.EndContractBlock(); } @@ -115,7 +115,7 @@ namespace System.Diagnostics.Tracing { if (eventName == null) { - throw new ArgumentNullException("eventName"); + throw new ArgumentNullException(nameof(eventName)); } Contract.EndContractBlock(); @@ -143,7 +143,7 @@ namespace System.Diagnostics.Tracing { if (eventName == null) { - throw new ArgumentNullException("eventName"); + throw new ArgumentNullException(nameof(eventName)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventTypes.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventTypes.cs index 4e33e58a82..c2239671bb 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventTypes.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingEventTypes.cs @@ -94,7 +94,7 @@ namespace System.Diagnostics.Tracing { if (name == null) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } Contract.EndContractBlock(); @@ -132,7 +132,7 @@ namespace System.Diagnostics.Tracing { if (defaultName == null) { - throw new ArgumentNullException("defaultName"); + throw new ArgumentNullException(nameof(defaultName)); } Contract.EndContractBlock(); @@ -212,7 +212,7 @@ namespace System.Diagnostics.Tracing { if (paramInfos == null) { - throw new ArgumentNullException("paramInfos"); + throw new ArgumentNullException(nameof(paramInfos)); } Contract.EndContractBlock(); @@ -231,7 +231,7 @@ namespace System.Diagnostics.Tracing { if (types == null) { - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); } Contract.EndContractBlock(); @@ -251,7 +251,7 @@ namespace System.Diagnostics.Tracing { if (typeInfos == null) { - throw new ArgumentNullException("typeInfos"); + throw new ArgumentNullException(nameof(typeInfos)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingMetadataCollector.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingMetadataCollector.cs index 0467ec43e5..41225c8626 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingMetadataCollector.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingMetadataCollector.cs @@ -156,7 +156,7 @@ namespace System.Diagnostics.Tracing size = 16; break; default: - throw new ArgumentOutOfRangeException("type"); + throw new ArgumentOutOfRangeException(nameof(type)); } this.impl.AddScalar(size); @@ -183,7 +183,7 @@ namespace System.Diagnostics.Tracing case TraceLoggingDataType.CountedUtf16String: break; default: - throw new ArgumentOutOfRangeException("type"); + throw new ArgumentOutOfRangeException(nameof(type)); } this.impl.AddScalar(2); @@ -227,7 +227,7 @@ namespace System.Diagnostics.Tracing case TraceLoggingDataType.Char8: break; default: - throw new ArgumentOutOfRangeException("type"); + throw new ArgumentOutOfRangeException(nameof(type)); } if (this.BeginningBufferedArray) diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingTypeInfo.cs b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingTypeInfo.cs index 5815d12fb0..d68e106b0b 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingTypeInfo.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/TraceLogging/TraceLoggingTypeInfo.cs @@ -36,7 +36,7 @@ namespace System.Diagnostics.Tracing { if (dataType == null) { - throw new ArgumentNullException("dataType"); + throw new ArgumentNullException(nameof(dataType)); } Contract.EndContractBlock(); @@ -56,12 +56,12 @@ namespace System.Diagnostics.Tracing { if (dataType == null) { - throw new ArgumentNullException("dataType"); + throw new ArgumentNullException(nameof(dataType)); } if (name == null) { - throw new ArgumentNullException("eventName"); + throw new ArgumentNullException(nameof(name)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Diagnostics/LogSwitch.cs b/src/mscorlib/src/System/Diagnostics/LogSwitch.cs index e3e2b867c4..4f9e815cd9 100644 --- a/src/mscorlib/src/System/Diagnostics/LogSwitch.cs +++ b/src/mscorlib/src/System/Diagnostics/LogSwitch.cs @@ -37,7 +37,7 @@ namespace System.Diagnostics { public LogSwitch(String name, String description, LogSwitch parent) { if (name != null && name.Length == 0) - throw new ArgumentOutOfRangeException("Name", Environment.GetResourceString("Argument_StringZeroLength")); + throw new ArgumentOutOfRangeException(nameof(Name), Environment.GetResourceString("Argument_StringZeroLength")); Contract.EndContractBlock(); if ((name != null) && (parent != null)) diff --git a/src/mscorlib/src/System/Diagnostics/Stacktrace.cs b/src/mscorlib/src/System/Diagnostics/Stacktrace.cs index 047a60f328..06f38c46f2 100644 --- a/src/mscorlib/src/System/Diagnostics/Stacktrace.cs +++ b/src/mscorlib/src/System/Diagnostics/Stacktrace.cs @@ -312,7 +312,7 @@ namespace System.Diagnostics { { if (skipFrames < 0) - throw new ArgumentOutOfRangeException("skipFrames", + throw new ArgumentOutOfRangeException(nameof(skipFrames), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -332,7 +332,7 @@ namespace System.Diagnostics { { if (skipFrames < 0) - throw new ArgumentOutOfRangeException("skipFrames", + throw new ArgumentOutOfRangeException(nameof(skipFrames), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -347,7 +347,7 @@ namespace System.Diagnostics { public StackTrace(Exception e) { if (e == null) - throw new ArgumentNullException("e"); + throw new ArgumentNullException(nameof(e)); Contract.EndContractBlock(); m_iNumOfFrames = 0; @@ -363,7 +363,7 @@ namespace System.Diagnostics { public StackTrace(Exception e, bool fNeedFileInfo) { if (e == null) - throw new ArgumentNullException("e"); + throw new ArgumentNullException(nameof(e)); Contract.EndContractBlock(); m_iNumOfFrames = 0; @@ -380,10 +380,10 @@ namespace System.Diagnostics { public StackTrace(Exception e, int skipFrames) { if (e == null) - throw new ArgumentNullException("e"); + throw new ArgumentNullException(nameof(e)); if (skipFrames < 0) - throw new ArgumentOutOfRangeException("skipFrames", + throw new ArgumentOutOfRangeException(nameof(skipFrames), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -402,10 +402,10 @@ namespace System.Diagnostics { public StackTrace(Exception e, int skipFrames, bool fNeedFileInfo) { if (e == null) - throw new ArgumentNullException("e"); + throw new ArgumentNullException(nameof(e)); if (skipFrames < 0) - throw new ArgumentOutOfRangeException("skipFrames", + throw new ArgumentOutOfRangeException(nameof(skipFrames), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Diagnostics/log.cs b/src/mscorlib/src/System/Diagnostics/log.cs index 1c68aad161..f600da8172 100644 --- a/src/mscorlib/src/System/Diagnostics/log.cs +++ b/src/mscorlib/src/System/Diagnostics/log.cs @@ -140,7 +140,7 @@ namespace System.Diagnostics { throw new ArgumentNullException ("LogSwitch"); if (level < 0) - throw new ArgumentOutOfRangeException("level", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(level), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); // Is logging for this level for this switch enabled? diff --git a/src/mscorlib/src/System/Empty.cs b/src/mscorlib/src/System/Empty.cs index f7e7486014..c54c99adf6 100644 --- a/src/mscorlib/src/System/Empty.cs +++ b/src/mscorlib/src/System/Empty.cs @@ -28,7 +28,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); UnitySerializationHolder.GetUnitySerializationInfo(info, UnitySerializationHolder.EmptyUnity, null, null); diff --git a/src/mscorlib/src/System/Enum.cs b/src/mscorlib/src/System/Enum.cs index cb6df00c12..ef6b19ee04 100644 --- a/src/mscorlib/src/System/Enum.cs +++ b/src/mscorlib/src/System/Enum.cs @@ -399,15 +399,15 @@ namespace System private static bool TryParseEnum(Type enumType, String value, bool ignoreCase, ref EnumResult parseResult) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); if (value == null) { parseResult.SetFailure(ParseFailureKind.ArgumentNull, "value"); @@ -534,7 +534,7 @@ namespace System public static Type GetUnderlyingType(Type enumType) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); Contract.Ensures(Contract.Result<Type>() != null); Contract.EndContractBlock(); @@ -545,7 +545,7 @@ namespace System public static Array GetValues(Type enumType) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); Contract.Ensures(Contract.Result<Array>() != null); Contract.EndContractBlock(); @@ -562,7 +562,7 @@ namespace System public static String GetName(Type enumType, Object value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); Contract.EndContractBlock(); return enumType.GetEnumName(value); @@ -572,7 +572,7 @@ namespace System public static String[] GetNames(Type enumType) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -589,7 +589,7 @@ namespace System public static Object ToObject(Type enumType, Object value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Delegate rest of error checking to the other functions @@ -629,7 +629,7 @@ namespace System default: // All unsigned types will be directly cast - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), nameof(value)); } } @@ -638,7 +638,7 @@ namespace System public static bool IsDefined(Type enumType, Object value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); Contract.EndContractBlock(); return enumType.IsEnumDefined(value); @@ -648,21 +648,21 @@ namespace System public static String Format(Type enumType, Object value, String format) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (format == null) - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); // Check if both of them are of the same type Type valueType = value.GetType(); @@ -976,7 +976,7 @@ namespace System [System.Security.SecuritySafeCritical] public Boolean HasFlag(Enum flag) { if (flag == null) - throw new ArgumentNullException("flag"); + throw new ArgumentNullException(nameof(flag)); Contract.EndContractBlock(); if (!this.GetType().IsEquivalentTo(flag.GetType())) { @@ -1146,13 +1146,13 @@ namespace System public static Object ToObject(Type enumType, sbyte value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1161,13 +1161,13 @@ namespace System public static Object ToObject(Type enumType, short value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1176,13 +1176,13 @@ namespace System public static Object ToObject(Type enumType, int value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1191,13 +1191,13 @@ namespace System public static Object ToObject(Type enumType, byte value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1207,13 +1207,13 @@ namespace System public static Object ToObject(Type enumType, ushort value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1223,13 +1223,13 @@ namespace System public static Object ToObject(Type enumType, uint value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1238,13 +1238,13 @@ namespace System public static Object ToObject(Type enumType, long value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1254,13 +1254,13 @@ namespace System public static Object ToObject(Type enumType, ulong value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, unchecked((long)value)); } @@ -1268,13 +1268,13 @@ namespace System private static Object ToObject(Type enumType, char value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value); } @@ -1282,13 +1282,13 @@ namespace System private static Object ToObject(Type enumType, bool value) { if (enumType == null) - throw new ArgumentNullException("enumType"); + throw new ArgumentNullException(nameof(enumType)); if (!enumType.IsEnum) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), nameof(enumType)); Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(enumType)); return InternalBoxEnum(rtType, value ? 1 : 0); } #endregion diff --git a/src/mscorlib/src/System/Environment.cs b/src/mscorlib/src/System/Environment.cs index 199ce07167..aa192b9c2a 100644 --- a/src/mscorlib/src/System/Environment.cs +++ b/src/mscorlib/src/System/Environment.cs @@ -403,7 +403,7 @@ namespace System { public static String ExpandEnvironmentVariables(String name) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); if (name.Length == 0) { @@ -627,7 +627,7 @@ namespace System { public static String GetEnvironmentVariable(String variable) { if (variable == null) - throw new ArgumentNullException("variable"); + throw new ArgumentNullException(nameof(variable)); Contract.EndContractBlock(); if (AppDomain.IsAppXModel() && !AppDomain.IsAppXDesignMode()) { @@ -663,7 +663,7 @@ namespace System { { if (variable == null) { - throw new ArgumentNullException("variable"); + throw new ArgumentNullException(nameof(variable)); } Contract.EndContractBlock(); @@ -931,15 +931,15 @@ namespace System { private static void CheckEnvironmentVariableName(string variable) { if (variable == null) { - throw new ArgumentNullException("variable"); + throw new ArgumentNullException(nameof(variable)); } if( variable.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_StringZeroLength"), "variable"); + throw new ArgumentException(Environment.GetResourceString("Argument_StringZeroLength"), nameof(variable)); } if( variable[0] == '\0') { - throw new ArgumentException(Environment.GetResourceString("Argument_StringFirstCharIsZero"), "variable"); + throw new ArgumentException(Environment.GetResourceString("Argument_StringFirstCharIsZero"), nameof(variable)); } // Make sure the environment variable name isn't longer than the diff --git a/src/mscorlib/src/System/Exception.cs b/src/mscorlib/src/System/Exception.cs index 306878527f..07e34c23fd 100644 --- a/src/mscorlib/src/System/Exception.cs +++ b/src/mscorlib/src/System/Exception.cs @@ -77,7 +77,7 @@ namespace System { protected Exception(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); _className = info.GetString("ClassName"); @@ -549,7 +549,7 @@ namespace System { { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/FormattableString.cs b/src/mscorlib/src/System/FormattableString.cs index ef56bcf3e0..294b2c1846 100644 --- a/src/mscorlib/src/System/FormattableString.cs +++ b/src/mscorlib/src/System/FormattableString.cs @@ -67,7 +67,7 @@ namespace System { if (formattable == null) { - throw new ArgumentNullException("formattable"); + throw new ArgumentNullException(nameof(formattable)); } return formattable.ToString(Globalization.CultureInfo.InvariantCulture); diff --git a/src/mscorlib/src/System/GC.cs b/src/mscorlib/src/System/GC.cs index 73c676df7d..9b6ef39023 100644 --- a/src/mscorlib/src/System/GC.cs +++ b/src/mscorlib/src/System/GC.cs @@ -127,12 +127,12 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public static void AddMemoryPressure (long bytesAllocated) { if( bytesAllocated <= 0) { - throw new ArgumentOutOfRangeException("bytesAllocated", + throw new ArgumentOutOfRangeException(nameof(bytesAllocated), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } if( (4 == IntPtr.Size) && (bytesAllocated > Int32.MaxValue) ) { - throw new ArgumentOutOfRangeException("pressure", + throw new ArgumentOutOfRangeException(nameof(bytesAllocated), Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegInt32")); } Contract.EndContractBlock(); @@ -143,12 +143,12 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public static void RemoveMemoryPressure (long bytesAllocated) { if( bytesAllocated <= 0) { - throw new ArgumentOutOfRangeException("bytesAllocated", + throw new ArgumentOutOfRangeException(nameof(bytesAllocated), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } if( (4 == IntPtr.Size) && (bytesAllocated > Int32.MaxValue) ) { - throw new ArgumentOutOfRangeException("bytesAllocated", + throw new ArgumentOutOfRangeException(nameof(bytesAllocated), Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegInt32")); } Contract.EndContractBlock(); @@ -195,12 +195,12 @@ namespace System { { if (generation<0) { - throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(generation), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if ((mode < GCCollectionMode.Default) || (mode > GCCollectionMode.Optimized)) { - throw new ArgumentOutOfRangeException("mode", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(mode), Environment.GetResourceString("ArgumentOutOfRange_Enum")); } Contract.EndContractBlock(); @@ -233,7 +233,7 @@ namespace System { { if (generation<0) { - throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(generation), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } Contract.EndContractBlock(); return _CollectionCount(generation, 0); @@ -246,7 +246,7 @@ namespace System { { if (generation<0) { - throw new ArgumentOutOfRangeException("generation", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(generation), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } Contract.EndContractBlock(); return _CollectionCount(generation, (getSpecialGCCount ? 1 : 0)); @@ -331,7 +331,7 @@ namespace System { [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static void SuppressFinalize(Object obj) { if (obj == null) - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); Contract.EndContractBlock(); _SuppressFinalize(obj); } @@ -347,7 +347,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated public static void ReRegisterForFinalize(Object obj) { if (obj == null) - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); Contract.EndContractBlock(); _ReRegisterForFinalize(obj); } @@ -406,7 +406,7 @@ namespace System { { if ((maxGenerationThreshold <= 0) || (maxGenerationThreshold >= 100)) { - throw new ArgumentOutOfRangeException("maxGenerationThreshold", + throw new ArgumentOutOfRangeException(nameof(maxGenerationThreshold), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"), @@ -416,7 +416,7 @@ namespace System { if ((largeObjectHeapThreshold <= 0) || (largeObjectHeapThreshold >= 100)) { - throw new ArgumentOutOfRangeException("largeObjectHeapThreshold", + throw new ArgumentOutOfRangeException(nameof(largeObjectHeapThreshold), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"), @@ -449,7 +449,7 @@ namespace System { public static GCNotificationStatus WaitForFullGCApproach(int millisecondsTimeout) { if (millisecondsTimeout < -1) - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); return (GCNotificationStatus)_WaitForFullGCApproach(millisecondsTimeout); } @@ -464,7 +464,7 @@ namespace System { public static GCNotificationStatus WaitForFullGCComplete(int millisecondsTimeout) { if (millisecondsTimeout < -1) - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); return (GCNotificationStatus)_WaitForFullGCComplete(millisecondsTimeout); } @@ -489,7 +489,7 @@ namespace System { { StartNoGCRegionStatus status = (StartNoGCRegionStatus)_StartNoGCRegion(totalSize, hasLohSize, lohSize, disallowFullBlockingGC); if (status == StartNoGCRegionStatus.AmountTooLarge) - throw new ArgumentOutOfRangeException("totalSize", + throw new ArgumentOutOfRangeException(nameof(totalSize), "totalSize is too large. For more information about setting the maximum size, see \"Latency Modes\" in http://go.microsoft.com/fwlink/?LinkId=522706"); else if (status == StartNoGCRegionStatus.AlreadyInProgress) throw new InvalidOperationException("The NoGCRegion mode was already in progress"); diff --git a/src/mscorlib/src/System/Globalization/Calendar.cs b/src/mscorlib/src/System/Globalization/Calendar.cs index d6dfdc9f4b..a79a2328db 100644 --- a/src/mscorlib/src/System/Globalization/Calendar.cs +++ b/src/mscorlib/src/System/Globalization/Calendar.cs @@ -192,7 +192,7 @@ namespace System.Globalization { [System.Runtime.InteropServices.ComVisible(false)] public static Calendar ReadOnly(Calendar calendar) { - if (calendar == null) { throw new ArgumentNullException("calendar"); } + if (calendar == null) { throw new ArgumentNullException(nameof(calendar)); } Contract.EndContractBlock(); if (calendar.IsReadOnly) { return (calendar); } @@ -262,7 +262,7 @@ namespace System.Globalization { double tempMillis = (value * scale + (value >= 0 ? 0.5 : -0.5)); if (!((tempMillis > -(double)MaxMillis) && (tempMillis < (double)MaxMillis))) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_AddValue")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_AddValue")); } long millis = (long)tempMillis; @@ -651,7 +651,7 @@ namespace System.Globalization { { if ((int)firstDayOfWeek < 0 || (int)firstDayOfWeek > 6) { throw new ArgumentOutOfRangeException( - "firstDayOfWeek", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(firstDayOfWeek), Environment.GetResourceString("ArgumentOutOfRange_Range", DayOfWeek.Sunday, DayOfWeek.Saturday)); } Contract.EndContractBlock(); @@ -664,7 +664,7 @@ namespace System.Globalization { return (GetWeekOfYearFullDays(time, (int)firstDayOfWeek, 4)); } throw new ArgumentOutOfRangeException( - "rule", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(rule), Environment.GetResourceString("ArgumentOutOfRange_Range", CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek)); } @@ -815,7 +815,7 @@ namespace System.Globalization { public virtual int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -835,7 +835,7 @@ namespace System.Globalization { { if (millisecond < 0 || millisecond >= MillisPerSecond) { throw new ArgumentOutOfRangeException( - "millisecond", + nameof(millisecond), String.Format( CultureInfo.InvariantCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, MillisPerSecond - 1)); diff --git a/src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs b/src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs index 63151951f9..04c10657c1 100644 --- a/src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs +++ b/src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs @@ -326,10 +326,10 @@ namespace System.Globalization { public static double GetNumericValue(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); return (InternalGetNumericValue(InternalConvertToUtf32(s, index))); @@ -361,10 +361,10 @@ namespace System.Globalization { public static int GetDecimalDigitValue(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); @@ -398,10 +398,10 @@ namespace System.Globalization { public static int GetDigitValue(String s, int index) { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } if (index < 0 || index >= s.Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); return (InternalGetDigitValue(InternalConvertToUtf32(s, index))); @@ -415,9 +415,9 @@ namespace System.Globalization { public static UnicodeCategory GetUnicodeCategory(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); return InternalGetUnicodeCategory(s, index); @@ -467,9 +467,9 @@ namespace System.Globalization { internal static BidiCategory GetBidiCategory(String s, int index) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); if (((uint)index)>=((uint)s.Length)) { - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); } Contract.EndContractBlock(); return ((BidiCategory)InternalGetCategoryValue(InternalConvertToUtf32(s, index), BIDI_CATEGORY_OFFSET)); diff --git a/src/mscorlib/src/System/Globalization/ChineseLunisolarCalendar.cs b/src/mscorlib/src/System/Globalization/ChineseLunisolarCalendar.cs index a5cf37f712..6479152e09 100644 --- a/src/mscorlib/src/System/Globalization/ChineseLunisolarCalendar.cs +++ b/src/mscorlib/src/System/Globalization/ChineseLunisolarCalendar.cs @@ -331,12 +331,12 @@ namespace System.Globalization { internal override int GetGregorianYear(int year, int era) { if (era != CurrentEra && era != ChineseEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } if (year < MIN_LUNISOLAR_YEAR || year > MAX_LUNISOLAR_YEAR) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), MIN_LUNISOLAR_YEAR, MAX_LUNISOLAR_YEAR)); diff --git a/src/mscorlib/src/System/Globalization/CompareInfo.cs b/src/mscorlib/src/System/Globalization/CompareInfo.cs index ec33b18bfb..a121154b5c 100644 --- a/src/mscorlib/src/System/Globalization/CompareInfo.cs +++ b/src/mscorlib/src/System/Globalization/CompareInfo.cs @@ -135,7 +135,7 @@ namespace System.Globalization { public static CompareInfo GetCompareInfo(int culture, Assembly assembly){ // Parameter checking. if (assembly == null) { - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); } if (assembly!=typeof(Object).Module.Assembly) { throw new ArgumentException(Environment.GetResourceString("Argument_OnlyMscorlib")); @@ -161,7 +161,7 @@ namespace System.Globalization { // Assembly constructor should be deprecated, we don't act on the assembly information any more public static CompareInfo GetCompareInfo(String name, Assembly assembly){ if (name == null || assembly == null) { - throw new ArgumentNullException(name == null ? "name" : "assembly"); + throw new ArgumentNullException(name == null ? nameof(name) : nameof(assembly)); } Contract.EndContractBlock(); @@ -189,7 +189,7 @@ namespace System.Globalization { if (CultureData.IsCustomCultureId(culture)) { // Customized culture cannot be created by the LCID. - throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", "culture")); + throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", nameof(culture))); } return CultureInfo.GetCultureInfo(culture).CompareInfo; @@ -209,7 +209,7 @@ namespace System.Globalization { { if (name == null) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } Contract.EndContractBlock(); @@ -226,7 +226,7 @@ namespace System.Globalization { public static bool IsSortable(String text) { if (text == null) { // A null param is invalid here. - throw new ArgumentNullException("text"); + throw new ArgumentNullException(nameof(text)); } if (0 == text.Length) { @@ -413,14 +413,14 @@ namespace System.Globalization { { if (options != CompareOptions.Ordinal) { - throw new ArgumentException(Environment.GetResourceString("Argument_CompareOptionOrdinal"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_CompareOptionOrdinal"), nameof(options)); } return String.CompareOrdinal(string1, string2); } if ((options & ValidCompareMaskOffFlags) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); } //Our paradigm is that null sorts less than any other string and @@ -493,23 +493,23 @@ namespace System.Globalization { } if (offset1 > (string1 == null ? 0 : string1.Length) - length1) { - throw new ArgumentOutOfRangeException("string1", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); + throw new ArgumentOutOfRangeException(nameof(string1), Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); } if (offset2 > (string2 == null ? 0 : string2.Length) - length2) { - throw new ArgumentOutOfRangeException("string2", Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); + throw new ArgumentOutOfRangeException(nameof(string2), Environment.GetResourceString("ArgumentOutOfRange_OffsetLength")); } if ((options & CompareOptions.Ordinal) != 0) { if (options != CompareOptions.Ordinal) { throw new ArgumentException(Environment.GetResourceString("Argument_CompareOptionOrdinal"), - "options"); + nameof(options)); } } else if ((options & ValidCompareMaskOffFlags) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); } // @@ -552,7 +552,7 @@ namespace System.Globalization { public unsafe virtual bool IsPrefix(String source, String prefix, CompareOptions options) { if (source == null || prefix == null) { - throw new ArgumentNullException((source == null ? "source" : "prefix"), + throw new ArgumentNullException((source == null ? nameof(source) : nameof(prefix)), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -574,7 +574,7 @@ namespace System.Globalization { } if ((options & ValidIndexMaskOffFlags) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); } @@ -607,7 +607,7 @@ namespace System.Globalization { public unsafe virtual bool IsSuffix(String source, String suffix, CompareOptions options) { if (source == null || suffix == null) { - throw new ArgumentNullException((source == null ? "source" : "suffix"), + throw new ArgumentNullException((source == null ? nameof(source) : nameof(suffix)), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -627,7 +627,7 @@ namespace System.Globalization { } if ((options & ValidIndexMaskOffFlags) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); } // to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to @@ -661,7 +661,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, char value) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, 0, source.Length, CompareOptions.None); @@ -671,7 +671,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, String value) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, 0, source.Length, CompareOptions.None); @@ -681,7 +681,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, char value, CompareOptions options) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, 0, source.Length, options); @@ -691,7 +691,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, String value, CompareOptions options) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, 0, source.Length, options); @@ -701,7 +701,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, char value, int startIndex) { if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None); @@ -711,7 +711,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, String value, int startIndex) { if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, startIndex, source.Length - startIndex, CompareOptions.None); @@ -721,7 +721,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, char value, int startIndex, CompareOptions options) { if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, startIndex, source.Length - startIndex, options); @@ -731,7 +731,7 @@ namespace System.Globalization { public unsafe virtual int IndexOf(String source, String value, int startIndex, CompareOptions options) { if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); return IndexOf(source, value, startIndex, source.Length - startIndex, options); @@ -754,13 +754,13 @@ namespace System.Globalization { { // Validate inputs if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); if (startIndex < 0 || startIndex > source.Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count < 0 || startIndex > source.Length - count) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); Contract.EndContractBlock(); if (options == CompareOptions.OrdinalIgnoreCase) @@ -771,7 +771,7 @@ namespace System.Globalization { // Validate CompareOptions // Ordinal can't be selected with other flags if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal)) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); // to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to // the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString. @@ -787,13 +787,13 @@ namespace System.Globalization { { // Validate inputs if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex > source.Length) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); @@ -810,11 +810,11 @@ namespace System.Globalization { if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (count < 0 || startIndex > source.Length - count) - throw new ArgumentOutOfRangeException("count",Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count),Environment.GetResourceString("ArgumentOutOfRange_Count")); if (options == CompareOptions.OrdinalIgnoreCase) { @@ -824,7 +824,7 @@ namespace System.Globalization { // Validate CompareOptions // Ordinal can't be selected with other flags if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal)) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); // to let the sorting DLL do the call optimization in case of Ascii strings, we check if the strings are in Ascii and then send the flag RESERVED_FIND_ASCII_STRING to // the sorting DLL API SortFindString so sorting DLL don't have to check if the string is Ascii with every call to SortFindString. @@ -851,7 +851,7 @@ namespace System.Globalization { public unsafe virtual int LastIndexOf(String source, char value) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); // Can't start at negative index, so make sure we check for the length == 0 case. @@ -863,7 +863,7 @@ namespace System.Globalization { public virtual int LastIndexOf(String source, String value) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); // Can't start at negative index, so make sure we check for the length == 0 case. @@ -875,7 +875,7 @@ namespace System.Globalization { public virtual int LastIndexOf(String source, char value, CompareOptions options) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); // Can't start at negative index, so make sure we check for the length == 0 case. @@ -886,7 +886,7 @@ namespace System.Globalization { public unsafe virtual int LastIndexOf(String source, String value, CompareOptions options) { if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); // Can't start at negative index, so make sure we check for the length == 0 case. @@ -936,7 +936,7 @@ namespace System.Globalization { { // Verify Arguments if (source==null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); Contract.EndContractBlock(); // Validate CompareOptions @@ -944,7 +944,7 @@ namespace System.Globalization { if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal) && (options != CompareOptions.OrdinalIgnoreCase)) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); // Special case for 0 length input strings if (source.Length == 0 && (startIndex == -1 || startIndex == 0)) @@ -952,7 +952,7 @@ namespace System.Globalization { // Make sure we're not out of range if (startIndex < 0 || startIndex > source.Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); // Make sure that we allow startIndex == source.Length if (startIndex == source.Length) @@ -964,7 +964,7 @@ namespace System.Globalization { // 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); if (options == CompareOptions.OrdinalIgnoreCase) { @@ -985,9 +985,9 @@ namespace System.Globalization { { // Verify Arguments if (source == null) - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Validate CompareOptions @@ -995,7 +995,7 @@ namespace System.Globalization { if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal) && (options != CompareOptions.OrdinalIgnoreCase)) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); // Special case for 0 length input strings if (source.Length == 0 && (startIndex == -1 || startIndex == 0)) @@ -1003,7 +1003,7 @@ namespace System.Globalization { // Make sure we're not out of range if (startIndex < 0 || startIndex > source.Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); // Make sure that we allow startIndex == source.Length if (startIndex == source.Length) @@ -1019,7 +1019,7 @@ namespace System.Globalization { // 2nd half of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); if (options == CompareOptions.OrdinalIgnoreCase) { @@ -1056,7 +1056,7 @@ namespace System.Globalization { [System.Security.SecuritySafeCritical] private SortKey CreateSortKey(String source, CompareOptions options) { - if (source==null) { throw new ArgumentNullException("source"); } + if (source==null) { throw new ArgumentNullException(nameof(source)); } Contract.EndContractBlock(); // Mask used to check if we have the right flags. @@ -1069,7 +1069,7 @@ namespace System.Globalization { if ((options & ValidSortkeyCtorMaskOffFlags) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); } byte[] keyData = null; // The OS doesn't have quite the same behavior so we have to test for empty inputs @@ -1090,7 +1090,7 @@ namespace System.Globalization { // If there was an error, return an error if (length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "source"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(source)); } // If input was empty, return the empty byte[] we made earlier and skip this @@ -1159,7 +1159,7 @@ namespace System.Globalization { { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (options == CompareOptions.Ordinal) @@ -1217,12 +1217,12 @@ namespace System.Globalization { // if(null == source) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if ((options & ValidHashCodeOfStringMaskOffFlags) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), "options"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"), nameof(options)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/CultureData.cs b/src/mscorlib/src/System/Globalization/CultureData.cs index 6f543f4926..35195cce4f 100644 --- a/src/mscorlib/src/System/Globalization/CultureData.cs +++ b/src/mscorlib/src/System/Globalization/CultureData.cs @@ -906,7 +906,7 @@ namespace System.Globalization // If not successful, throw if (retVal == null) throw new CultureNotFoundException( - "culture", culture, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(culture), culture, Environment.GetResourceString("Argument_CultureNotSupported")); // Return the one we found return retVal; @@ -933,7 +933,7 @@ namespace System.Globalization CultureTypes.FrameworkCultures)) != 0) { throw new ArgumentOutOfRangeException( - "types", + nameof(types), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), CultureTypes.NeutralCultures, CultureTypes.FrameworkCultures)); diff --git a/src/mscorlib/src/System/Globalization/CultureInfo.cs b/src/mscorlib/src/System/Globalization/CultureInfo.cs index d620d2dc24..46ff38d4b3 100644 --- a/src/mscorlib/src/System/Globalization/CultureInfo.cs +++ b/src/mscorlib/src/System/Globalization/CultureInfo.cs @@ -323,7 +323,7 @@ namespace System.Globalization { public CultureInfo(String name, bool useUserOverride) { if (name==null) { - throw new ArgumentNullException("name", + throw new ArgumentNullException(nameof(name), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -332,7 +332,7 @@ namespace System.Globalization { this.m_cultureData = CultureData.GetCultureData(name, useUserOverride); if (this.m_cultureData == null) { - throw new CultureNotFoundException("name", name, Environment.GetResourceString("Argument_CultureNotSupported")); + throw new CultureNotFoundException(nameof(name), name, Environment.GetResourceString("Argument_CultureNotSupported")); } this.m_name = this.m_cultureData.CultureName; @@ -347,7 +347,7 @@ namespace System.Globalization { public CultureInfo(int culture, bool useUserOverride) { // We don't check for other invalid LCIDS here... if (culture < 0) { - throw new ArgumentOutOfRangeException("culture", + throw new ArgumentOutOfRangeException(nameof(culture), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } Contract.EndContractBlock(); @@ -367,7 +367,7 @@ namespace System.Globalization { // Can't support unknown custom cultures and we do not support neutral or // non-custom user locales. throw new CultureNotFoundException( - "culture", culture, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(culture), culture, Environment.GetResourceString("Argument_CultureNotSupported")); default: // Now see if this LCID is supported in the system default CultureData table. @@ -424,7 +424,7 @@ namespace System.Globalization { this.m_cultureData = CultureData.GetCultureData(m_name, m_useUserOverride); if (this.m_cultureData == null) throw new CultureNotFoundException( - "m_name", m_name, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(m_name), m_name, Environment.GetResourceString("Argument_CultureNotSupported")); #if FEATURE_USE_LCID } @@ -540,7 +540,7 @@ namespace System.Globalization { internal CultureInfo(String cultureName, String textAndCompareCultureName) { if (cultureName==null) { - throw new ArgumentNullException("cultureName", + throw new ArgumentNullException(nameof(cultureName), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -548,7 +548,7 @@ namespace System.Globalization { this.m_cultureData = CultureData.GetCultureData(cultureName, false); if (this.m_cultureData == null) throw new CultureNotFoundException( - "cultureName", cultureName, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(cultureName), cultureName, Environment.GetResourceString("Argument_CultureNotSupported")); this.m_name = this.m_cultureData.CultureName; @@ -701,7 +701,7 @@ namespace System.Globalization { set { #if FEATURE_APPX if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (AppDomain.IsAppXModel()) { @@ -799,7 +799,7 @@ namespace System.Globalization { set { #if FEATURE_APPX if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (AppDomain.IsAppXModel()) { @@ -1357,7 +1357,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -1393,7 +1393,7 @@ namespace System.Globalization { set { if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -1595,7 +1595,7 @@ namespace System.Globalization { public static CultureInfo ReadOnly(CultureInfo ci) { if (ci == null) { - throw new ArgumentNullException("ci"); + throw new ArgumentNullException(nameof(ci)); } Contract.Ensures(Contract.Result<CultureInfo>() != null); Contract.EndContractBlock(); @@ -1827,7 +1827,7 @@ namespace System.Globalization { // the altCulture code path for SQL Server. // Also check for zero as this would fail trying to add as a key to the hash. if (culture <= 0) { - throw new ArgumentOutOfRangeException("culture", + throw new ArgumentOutOfRangeException(nameof(culture), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } Contract.Ensures(Contract.Result<CultureInfo>() != null); @@ -1836,7 +1836,7 @@ namespace System.Globalization { if (null == retval) { throw new CultureNotFoundException( - "culture", culture, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(culture), culture, Environment.GetResourceString("Argument_CultureNotSupported")); } return retval; } @@ -1849,7 +1849,7 @@ namespace System.Globalization { // Make sure we have a valid, non-zero length string as name if (name == null) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } Contract.Ensures(Contract.Result<CultureInfo>() != null); Contract.EndContractBlock(); @@ -1858,7 +1858,7 @@ namespace System.Globalization { if (retval == null) { throw new CultureNotFoundException( - "name", name, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(name), name, Environment.GetResourceString("Argument_CultureNotSupported")); } return retval; @@ -1871,12 +1871,12 @@ namespace System.Globalization { // Make sure we have a valid, non-zero length string as name if (null == name) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } if (null == altName) { - throw new ArgumentNullException("altName"); + throw new ArgumentNullException(nameof(altName)); } Contract.Ensures(Contract.Result<CultureInfo>() != null); Contract.EndContractBlock(); @@ -1884,7 +1884,7 @@ namespace System.Globalization { CultureInfo retval = GetCultureInfoHelper(-1, name, altName); if (retval == null) { - throw new CultureNotFoundException("name or altName", + throw new CultureNotFoundException(nameof(name) + " or " + nameof(altName), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_OneOfCulturesNotSupported"), @@ -1904,7 +1904,7 @@ namespace System.Globalization { if (name == "zh-CHT" || name == "zh-CHS") { throw new CultureNotFoundException( - "name", + nameof(name), String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_CultureIetfNotSupported"), name) ); } @@ -1915,7 +1915,7 @@ namespace System.Globalization { if (ci.LCID > 0xffff || ci.LCID == 0x040a) { throw new CultureNotFoundException( - "name", + nameof(name), String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_CultureIetfNotSupported"), name) ); } diff --git a/src/mscorlib/src/System/Globalization/CultureNotFoundException.cs b/src/mscorlib/src/System/Globalization/CultureNotFoundException.cs index 0486cc9d17..9b5264f6c2 100644 --- a/src/mscorlib/src/System/Globalization/CultureNotFoundException.cs +++ b/src/mscorlib/src/System/Globalization/CultureNotFoundException.cs @@ -69,7 +69,7 @@ namespace System.Globalization { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs b/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs index 00c2d1f439..3fb32e0d94 100644 --- a/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs +++ b/src/mscorlib/src/System/Globalization/DateTimeFormatInfo.cs @@ -411,7 +411,7 @@ namespace System.Globalization { if (this.m_cultureData == null) throw new CultureNotFoundException( - "m_name", m_name, Environment.GetResourceString("Argument_CultureNotSupported")); + nameof(m_name), m_name, Environment.GetResourceString("Argument_CultureNotSupported")); } // Note: This is for Everett compatibility @@ -582,7 +582,7 @@ namespace System.Globalization { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -604,7 +604,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -694,7 +694,7 @@ namespace System.Globalization { } // The assigned calendar is not a valid calendar for this culture, throw - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("Argument_InvalidCalendar")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("Argument_InvalidCalendar")); } } @@ -718,7 +718,7 @@ namespace System.Globalization { public int GetEra(String eraName) { if (eraName == null) { - throw new ArgumentNullException("eraName", + throw new ArgumentNullException(nameof(eraName), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -795,7 +795,7 @@ namespace System.Globalization { if ((--era) < EraNames.Length && (era >= 0)) { return (m_eraNames[era]); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } internal String[] AbbreviatedEraNames @@ -823,7 +823,7 @@ namespace System.Globalization { if ((--era) < m_abbrevEraNames.Length && (era >= 0)) { return (m_abbrevEraNames[era]); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } internal String[] AbbreviatedEnglishEraNames @@ -862,7 +862,7 @@ namespace System.Globalization { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -894,7 +894,7 @@ namespace System.Globalization { firstDayOfWeek = (int)value; } else { throw new ArgumentOutOfRangeException( - "value", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(value), Environment.GetResourceString("ArgumentOutOfRange_Range", DayOfWeek.Sunday, DayOfWeek.Saturday)); } } @@ -922,7 +922,7 @@ namespace System.Globalization { calendarWeekRule = (int)value; } else { throw new ArgumentOutOfRangeException( - "value", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(value), Environment.GetResourceString("ArgumentOutOfRange_Range", CalendarWeekRule.FirstDay, CalendarWeekRule.FirstFourDayWeek)); } } @@ -945,7 +945,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -977,7 +977,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1016,7 +1016,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1053,7 +1053,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1084,7 +1084,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1128,7 +1128,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); Contract.EndContractBlock(); @@ -1168,7 +1168,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1308,7 +1308,7 @@ namespace System.Globalization { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1349,7 +1349,7 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -1370,7 +1370,7 @@ namespace System.Globalization { Contract.Requires(values.Length >= length); for (int i = 0; i < length; i++) { if (values[i] == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException("values[" + i + "]", Environment.GetResourceString("ArgumentNull_ArrayValue")); } } @@ -1388,11 +1388,11 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 7) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 7), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 7), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length); @@ -1416,12 +1416,12 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 7) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 7), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 7), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length); @@ -1441,12 +1441,12 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 7) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 7), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 7), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length); @@ -1466,12 +1466,12 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 13) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length - 1); @@ -1492,12 +1492,12 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 13) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length - 1); @@ -1556,7 +1556,7 @@ namespace System.Globalization { // (actually is 13 right now for all cases) if ((month < 1) || (month > monthNamesArray.Length)) { throw new ArgumentOutOfRangeException( - "month", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, monthNamesArray.Length)); } return (monthNamesArray[month-1]); @@ -1614,7 +1614,7 @@ namespace System.Globalization { if ((int)dayofweek < 0 || (int)dayofweek > 6) { throw new ArgumentOutOfRangeException( - "dayofweek", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(dayofweek), Environment.GetResourceString("ArgumentOutOfRange_Range", DayOfWeek.Sunday, DayOfWeek.Saturday)); } Contract.EndContractBlock(); @@ -1633,7 +1633,7 @@ namespace System.Globalization { if ((int)dayOfWeek < 0 || (int)dayOfWeek > 6) { throw new ArgumentOutOfRangeException( - "dayOfWeek", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(dayOfWeek), Environment.GetResourceString("ArgumentOutOfRange_Range", DayOfWeek.Sunday, DayOfWeek.Saturday)); } Contract.EndContractBlock(); @@ -1740,7 +1740,7 @@ namespace System.Globalization { result = this.AllYearMonthPatterns; break; default: - throw new ArgumentException(Environment.GetResourceString("Format_BadFormatSpecifier"), "format"); + throw new ArgumentException(Environment.GetResourceString("Format_BadFormatSpecifier"), nameof(format)); } return (result); } @@ -1750,7 +1750,7 @@ namespace System.Globalization { { if ((int)dayofweek < 0 || (int)dayofweek > 6) { throw new ArgumentOutOfRangeException( - "dayofweek", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(dayofweek), Environment.GetResourceString("ArgumentOutOfRange_Range", DayOfWeek.Sunday, DayOfWeek.Saturday)); } Contract.EndContractBlock(); @@ -1765,7 +1765,7 @@ namespace System.Globalization { { if (month < 1 || month > 13) { throw new ArgumentOutOfRangeException( - "month", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 13)); } Contract.EndContractBlock(); @@ -1778,7 +1778,7 @@ namespace System.Globalization { { if (month < 1 || month > 13) { throw new ArgumentOutOfRangeException( - "month", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 13)); } Contract.EndContractBlock(); @@ -1977,7 +1977,7 @@ namespace System.Globalization { public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi) { if (dtfi == null) { - throw new ArgumentNullException("dtfi", + throw new ArgumentNullException(nameof(dtfi), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -2038,13 +2038,13 @@ namespace System.Globalization { if (IsReadOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (patterns == null) { - throw new ArgumentNullException("patterns", + throw new ArgumentNullException(nameof(patterns), Environment.GetResourceString("ArgumentNull_Array")); } if (patterns.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError"), "patterns"); + throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError"), nameof(patterns)); } Contract.EndContractBlock(); @@ -2086,7 +2086,7 @@ namespace System.Globalization { break; default: - throw new ArgumentException(Environment.GetResourceString("Format_BadFormatSpecifier"), "format"); + throw new ArgumentException(Environment.GetResourceString("Format_BadFormatSpecifier"), nameof(format)); } // Clear the token hash table, note that even short dates could require this @@ -2109,12 +2109,12 @@ namespace System.Globalization { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 13) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length - 1); @@ -2137,12 +2137,12 @@ namespace System.Globalization { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) { - throw new ArgumentNullException("value", + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_Array")); } if (value.Length != 13) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidArrayLength", 13), nameof(value)); } Contract.EndContractBlock(); CheckNullValue(value, value.Length - 1); diff --git a/src/mscorlib/src/System/Globalization/EastAsianLunisolarCalendar.cs b/src/mscorlib/src/System/Globalization/EastAsianLunisolarCalendar.cs index 2460eee3af..3c9391fa63 100644 --- a/src/mscorlib/src/System/Globalization/EastAsianLunisolarCalendar.cs +++ b/src/mscorlib/src/System/Globalization/EastAsianLunisolarCalendar.cs @@ -65,7 +65,7 @@ namespace System.Globalization { public int GetCelestialStem(int sexagenaryYear) { if ((sexagenaryYear < 1) || (sexagenaryYear > 60)) { throw new ArgumentOutOfRangeException( - "sexagenaryYear", + nameof(sexagenaryYear), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 60)); } Contract.EndContractBlock(); @@ -80,7 +80,7 @@ namespace System.Globalization { public int GetTerrestrialBranch(int sexagenaryYear) { if ((sexagenaryYear < 1) || (sexagenaryYear > 60)) { throw new ArgumentOutOfRangeException( - "sexagenaryYear", + nameof(sexagenaryYear), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 60)); } Contract.EndContractBlock(); @@ -121,7 +121,7 @@ namespace System.Globalization { return (mEraInfo[i].minEraYear); } } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } internal int MaxEraCalendarYear (int era) { @@ -144,7 +144,7 @@ namespace System.Globalization { return (mEraInfo[i].maxEraYear); } } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } // Construct an instance of EastAsianLunisolar calendar. @@ -168,7 +168,7 @@ namespace System.Globalization { } if ((era <GetEra(MinDate)) || (era > GetEra(MaxDate))) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } } @@ -178,7 +178,7 @@ namespace System.Globalization { if ((year < MinCalendarYear) || (year > MaxCalendarYear)) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), Environment.GetResourceString("ArgumentOutOfRange_Range", MinEraCalendarYear(era), MaxEraCalendarYear(era))); } return year; @@ -191,11 +191,11 @@ namespace System.Globalization { { //Reject if there is no leap month this year if (GetYearInfo(year , LeapMonth) == 0) - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } if (month < 1 || month > 13) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } return year; } @@ -236,7 +236,7 @@ namespace System.Globalization { if (day < 1 || day > daysInMonth) { BCLDebug.Log("year = " + year + ", month = " + month + ", day = " + day); throw new ArgumentOutOfRangeException( - "day", + nameof(day), Environment.GetResourceString("ArgumentOutOfRange_Day", daysInMonth, month)); } @@ -399,7 +399,7 @@ namespace System.Globalization { public override DateTime AddMonths(DateTime time, int months) { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), Environment.GetResourceString("ArgumentOutOfRange_Range", -120000, 120000)); } Contract.EndContractBlock(); @@ -561,7 +561,7 @@ namespace System.Globalization { if (day < 1 || day > daysInMonth) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), Environment.GetResourceString("ArgumentOutOfRange_Day", daysInMonth, month)); } int m = GetYearInfo(year, LeapMonth); @@ -620,7 +620,7 @@ namespace System.Globalization { if (value < 99 || value > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "value", + nameof(value), Environment.GetResourceString("ArgumentOutOfRange_Range", 99, MaxCalendarYear)); } twoDigitYearMax = value; @@ -630,7 +630,7 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/EncodingDataItem.cs b/src/mscorlib/src/System/Globalization/EncodingDataItem.cs index 1dc1bd2eaf..728c44bb9d 100644 --- a/src/mscorlib/src/System/Globalization/EncodingDataItem.cs +++ b/src/mscorlib/src/System/Globalization/EncodingDataItem.cs @@ -62,7 +62,7 @@ namespace System.Globalization { } } - throw new ArgumentException("pStrings"); + throw new ArgumentException(null, nameof(pStrings)); } else { diff --git a/src/mscorlib/src/System/Globalization/EncodingTable.cs b/src/mscorlib/src/System/Globalization/EncodingTable.cs index cdda9eaf6d..12da52e596 100644 --- a/src/mscorlib/src/System/Globalization/EncodingTable.cs +++ b/src/mscorlib/src/System/Globalization/EncodingTable.cs @@ -94,7 +94,7 @@ namespace System.Globalization throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, - Environment.GetResourceString("Argument_EncodingNotSupported"), name), "name"); + Environment.GetResourceString("Argument_EncodingNotSupported"), name), nameof(name)); } // Return a list of all EncodingInfo objects describing all of our encodings @@ -136,7 +136,7 @@ namespace System.Globalization internal static int GetCodePageFromName(String name) { if (name==null) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/GregorianCalendar.cs b/src/mscorlib/src/System/Globalization/GregorianCalendar.cs index 6f48600887..6cf9b2eb85 100644 --- a/src/mscorlib/src/System/Globalization/GregorianCalendar.cs +++ b/src/mscorlib/src/System/Globalization/GregorianCalendar.cs @@ -132,7 +132,7 @@ namespace System.Globalization { public GregorianCalendar(GregorianCalendarTypes type) { if ((int)type < (int)GregorianCalendarTypes.Localized || (int)type > (int)GregorianCalendarTypes.TransliteratedFrench) { throw new ArgumentOutOfRangeException( - "type", + nameof(type), Environment.GetResourceString("ArgumentOutOfRange_Range", GregorianCalendarTypes.Localized, GregorianCalendarTypes.TransliteratedFrench)); } @@ -159,7 +159,7 @@ namespace System.Globalization { break; default: - throw new ArgumentOutOfRangeException("m_type", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(m_type), Environment.GetResourceString("ArgumentOutOfRange_Enum")); } } } @@ -285,7 +285,7 @@ namespace System.Globalization { { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -371,16 +371,16 @@ namespace System.Globalization { public override int GetDaysInMonth(int year, int month, int era) { if (era == CurrentEra || era == ADEra) { if (year < 1 || year > MaxYear) { - throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_Range", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, MaxYear)); } if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } int[] days = ((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366: DaysToMonth365); return (days[month] - days[month - 1]); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } // Returns the number of days in the year given by the year argument for the current era. @@ -393,14 +393,14 @@ namespace System.Globalization { return ((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 366:365); } throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear)); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } // Returns the era for the specified DateTime value. @@ -437,14 +437,14 @@ namespace System.Globalization { return (12); } throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear)); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } // Returns the year part of the specified DateTime. The returned value is an @@ -463,23 +463,23 @@ namespace System.Globalization { public override bool IsLeapDay(int year, int month, int day, int era) { if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Range", + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 12)); } Contract.EndContractBlock(); if (era != CurrentEra && era != ADEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } if (year < 1 || year > MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, MaxYear)); } if (day < 1 || day > GetDaysInMonth(year, month)) { - throw new ArgumentOutOfRangeException("day", Environment.GetResourceString("ArgumentOutOfRange_Range", + throw new ArgumentOutOfRangeException(nameof(day), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, GetDaysInMonth(year, month))); } if (!IsLeapYear(year)) { @@ -500,11 +500,11 @@ namespace System.Globalization { { if (era != CurrentEra && era != ADEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } if (year < 1 || year > MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear)); @@ -520,19 +520,19 @@ namespace System.Globalization { public override bool IsLeapMonth(int year, int month, int era) { if (era != CurrentEra && era != ADEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } if (year < 1 || year > MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear)); } if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Range", + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Range", 1, 12)); } Contract.EndContractBlock(); @@ -551,12 +551,12 @@ namespace System.Globalization { } throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear)); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } // Returns the date and time converted to a DateTime value. Throws an exception if the n-tuple is invalid. @@ -567,7 +567,7 @@ namespace System.Globalization { if (era == CurrentEra || era == ADEra) { return new DateTime(year, month, day, hour, minute, second, millisecond); } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } internal override Boolean TryToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era, out DateTime result) { @@ -609,14 +609,14 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); if (year > MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear)); diff --git a/src/mscorlib/src/System/Globalization/GregorianCalendarHelper.cs b/src/mscorlib/src/System/Globalization/GregorianCalendarHelper.cs index cf3fd44cf9..062ae4818a 100644 --- a/src/mscorlib/src/System/Globalization/GregorianCalendarHelper.cs +++ b/src/mscorlib/src/System/Globalization/GregorianCalendarHelper.cs @@ -153,7 +153,7 @@ namespace System.Globalization { internal int GetGregorianYear(int year, int era) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -166,7 +166,7 @@ namespace System.Globalization { if (era == m_EraInfo[i].era) { if (year < m_EraInfo[i].minEraYear || year > m_EraInfo[i].maxEraYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -176,7 +176,7 @@ namespace System.Globalization { return (m_EraInfo[i].yearOffset + year); } } - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } internal bool IsValidYear(int year, int era) { @@ -299,7 +299,7 @@ namespace System.Globalization { { if (millisecond < 0 || millisecond >= MillisPerSecond) { throw new ArgumentOutOfRangeException( - "millisecond", + nameof(millisecond), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -346,7 +346,7 @@ namespace System.Globalization { { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -432,7 +432,7 @@ namespace System.Globalization { // year = GetGregorianYear(year, era); if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } int[] days = ((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366: DaysToMonth365); return (days[month] - days[month - 1]); @@ -460,7 +460,7 @@ namespace System.Globalization { return (m_EraInfo[i].era); } } - throw new ArgumentOutOfRangeException("time", Environment.GetResourceString("ArgumentOutOfRange_Era")); + throw new ArgumentOutOfRangeException(nameof(time), Environment.GetResourceString("ArgumentOutOfRange_Era")); } @@ -533,7 +533,7 @@ namespace System.Globalization { // year/month/era checking is done in GetDaysInMonth() if (day < 1 || day > GetDaysInMonth(year, month, era)) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -570,7 +570,7 @@ namespace System.Globalization { year = GetGregorianYear(year, era); if (month < 1 || month > 12) { throw new ArgumentOutOfRangeException( - "month", + nameof(month), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -607,7 +607,7 @@ namespace System.Globalization { public int ToFourDigitYear(int year, int twoDigitYearMax) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } Contract.EndContractBlock(); @@ -619,7 +619,7 @@ namespace System.Globalization { if (year < m_minYear || year > m_maxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), m_minYear, m_maxYear)); diff --git a/src/mscorlib/src/System/Globalization/HebrewCalendar.cs b/src/mscorlib/src/System/Globalization/HebrewCalendar.cs index 3a17494001..922581af17 100644 --- a/src/mscorlib/src/System/Globalization/HebrewCalendar.cs +++ b/src/mscorlib/src/System/Globalization/HebrewCalendar.cs @@ -397,7 +397,7 @@ namespace System.Globalization { int monthsInYear = GetMonthsInYear(year, era); if (month < 1 || month > monthsInYear) { throw new ArgumentOutOfRangeException( - "month", + nameof(month), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -421,7 +421,7 @@ namespace System.Globalization { int daysInMonth = GetDaysInMonth(year, month, era); if (day < 1 || day > daysInMonth) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -432,7 +432,7 @@ namespace System.Globalization { static internal void CheckEraRange(int era) { if (era != CurrentEra && era != HebrewEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } } @@ -486,7 +486,7 @@ namespace System.Globalization { // int index = gregorianYear - FirstGregorianTableYear; if (index < 0 || index > TABLESIZE) { - throw new ArgumentOutOfRangeException("gregorianYear"); + throw new ArgumentOutOfRangeException(nameof(gregorianYear)); } index *= 2; @@ -705,7 +705,7 @@ namespace System.Globalization { catch (ArgumentException) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_AddValue"))); @@ -815,7 +815,7 @@ namespace System.Globalization { "hebrewYearType should be from 1 to 6, but now hebrewYearType = " + hebrewYearType + " for hebrew year " + year); int monthDays = LunarMonthLen[hebrewYearType, month]; if (monthDays == 0) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } return (monthDays); } @@ -1051,7 +1051,7 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -1062,7 +1062,7 @@ namespace System.Globalization { if (year > MaxHebrewYear || year < MinHebrewYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), diff --git a/src/mscorlib/src/System/Globalization/HijriCalendar.cs b/src/mscorlib/src/System/Globalization/HijriCalendar.cs index 194d329d25..d19e77a5bb 100644 --- a/src/mscorlib/src/System/Globalization/HijriCalendar.cs +++ b/src/mscorlib/src/System/Globalization/HijriCalendar.cs @@ -222,7 +222,7 @@ namespace System.Globalization { // NOTE: Check the value of Min/MaxAdavncedHijri with Arabic speakers to see if the assumption is good. if (value < MinAdvancedHijri || value > MaxAdvancedHijri) { throw new ArgumentOutOfRangeException( - "HijriAdjustment", + nameof(HijriAdjustment), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"), @@ -320,7 +320,7 @@ namespace System.Globalization { static internal void CheckEraRange(int era) { if (era != CurrentEra && era != HijriEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } } @@ -328,7 +328,7 @@ namespace System.Globalization { CheckEraRange(era); if (year < 1 || year > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -342,7 +342,7 @@ namespace System.Globalization { if (year == MaxCalendarYear) { if (month > MaxCalendarMonth) { throw new ArgumentOutOfRangeException( - "month", + nameof(month), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -352,7 +352,7 @@ namespace System.Globalization { } if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } } @@ -465,7 +465,7 @@ namespace System.Globalization { public override DateTime AddMonths(DateTime time, int months) { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -602,7 +602,7 @@ namespace System.Globalization { int daysInMonth = GetDaysInMonth(year, month, era); if (day < 1 || day > daysInMonth) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Day"), @@ -650,7 +650,7 @@ namespace System.Globalization { if (day < 1 || day > daysInMonth) { BCLDebug.Log("year = " + year + ", month = " + month + ", day = " + day); throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Day"), @@ -683,7 +683,7 @@ namespace System.Globalization { if (value < 99 || value > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "value", + nameof(value), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -698,7 +698,7 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -709,7 +709,7 @@ namespace System.Globalization { if (year > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), diff --git a/src/mscorlib/src/System/Globalization/IdnMapping.cs b/src/mscorlib/src/System/Globalization/IdnMapping.cs index 599a32ad87..edae8ee34a 100644 --- a/src/mscorlib/src/System/Globalization/IdnMapping.cs +++ b/src/mscorlib/src/System/Globalization/IdnMapping.cs @@ -125,7 +125,7 @@ namespace System.Globalization public String GetAscii(String unicode, int index) { - if (unicode==null) throw new ArgumentNullException("unicode"); + if (unicode==null) throw new ArgumentNullException(nameof(unicode)); Contract.EndContractBlock(); return GetAscii(unicode, index, unicode.Length - index); } @@ -133,62 +133,6 @@ namespace System.Globalization public String GetAscii(String unicode, int index, int count) { throw null; - /*if (unicode==null) throw new ArgumentNullException("unicode"); - if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", - Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); - if (index > unicode.Length) - throw new ArgumentOutOfRangeException("byteIndex", - Environment.GetResourceString("ArgumentOutOfRange_Index")); - if (index > unicode.Length - count) - throw new ArgumentOutOfRangeException("unicode", - Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); - Contract.EndContractBlock(); - - // We're only using part of the string - unicode = unicode.Substring(index, count); - - if (Environment.IsWindows8OrAbove) - { - return GetAsciiUsingOS(unicode); - } - - // Check for ASCII only string, which will be unchanged - if (ValidateStd3AndAscii(unicode, UseStd3AsciiRules, true)) - { - return unicode; - } - - // Cannot be null terminated (normalization won't help us with this one, and - // may have returned false before checking the whole string above) - Contract.Assert(unicode.Length >= 1, "[IdnMapping.GetAscii]Expected 0 length strings to fail before now."); - if (unicode[unicode.Length - 1] <= 0x1f) - { - throw new ArgumentException( - Environment.GetResourceString("Argument_InvalidCharSequence", unicode.Length-1 ), - "unicode"); - } - - // Have to correctly IDNA normalize the string and Unassigned flags - bool bHasLastDot = (unicode.Length > 0) && IsDot(unicode[unicode.Length - 1]); - unicode = unicode.Normalize((NormalizationForm)(m_bAllowUnassigned ? - ExtendedNormalizationForms.FormIdna : ExtendedNormalizationForms.FormIdnaDisallowUnassigned)); - - // Make sure we didn't normalize away something after a last dot - if ((!bHasLastDot) && unicode.Length > 0 && IsDot(unicode[unicode.Length - 1])) - { - throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); - } - - // May need to check Std3 rules again for non-ascii - if (UseStd3AsciiRules) - { - ValidateStd3AndAscii(unicode, true, false); - } - - // Go ahead and encode it - return punycode_encode(unicode);*/ } @@ -198,14 +142,14 @@ namespace System.Globalization if (unicode.Length == 0) { throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); } if (unicode[unicode.Length - 1] == 0) { throw new ArgumentException( Environment.GetResourceString("Argument_InvalidCharSequence", unicode.Length - 1), - "unicode"); + nameof(unicode)); } uint flags = (uint) ((AllowUnassigned ? IDN_ALLOW_UNASSIGNED : 0) | (UseStd3AsciiRules ? IDN_USE_STD3_ASCII_RULES : 0)); @@ -218,10 +162,10 @@ namespace System.Globalization lastError = Marshal.GetLastWin32Error(); if (lastError == ERROR_INVALID_NAME) { - throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), "unicode"); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), nameof(unicode)); } - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"), "unicode"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"), nameof(unicode)); } char [] output = new char[length]; @@ -232,10 +176,10 @@ namespace System.Globalization lastError = Marshal.GetLastWin32Error(); if (lastError == ERROR_INVALID_NAME) { - throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), "unicode"); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), nameof(unicode)); } - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"), "unicode"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex"), nameof(unicode)); } return new String(output, 0, length); @@ -249,30 +193,30 @@ namespace System.Globalization public String GetUnicode(String ascii, int index) { - if (ascii==null) throw new ArgumentNullException("ascii"); + if (ascii==null) throw new ArgumentNullException(nameof(ascii)); Contract.EndContractBlock(); return GetUnicode(ascii, index, ascii.Length - index); } public String GetUnicode(String ascii, int index, int count) { - if (ascii==null) throw new ArgumentNullException("ascii"); + if (ascii==null) throw new ArgumentNullException(nameof(ascii)); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0) ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (index > ascii.Length) - throw new ArgumentOutOfRangeException("byteIndex", + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (index > ascii.Length - count) - throw new ArgumentOutOfRangeException("ascii", + throw new ArgumentOutOfRangeException(nameof(ascii), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); // This is a case (i.e. explicitly null-terminated input) where behavior in .NET and Win32 intentionally differ. // The .NET APIs should (and did in v4.0 and earlier) throw an ArgumentException on input that includes a terminating null. // The Win32 APIs fail on an embedded null, but not on a terminating null. if (count > 0 && ascii[index + count - 1] == (char)0) - throw new ArgumentException("ascii", - Environment.GetResourceString("Argument_IdnBadPunycode")); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), + nameof(ascii)); Contract.EndContractBlock(); // We're only using part of the string @@ -289,7 +233,7 @@ namespace System.Globalization // Output name MUST obey IDNA rules & round trip (casing differences are allowed) if (!ascii.Equals(GetAscii(strUnicode), StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnIllegalName"), "ascii"); + "Argument_IdnIllegalName"), nameof(ascii)); return strUnicode; } @@ -307,10 +251,10 @@ namespace System.Globalization lastError = Marshal.GetLastWin32Error(); if (lastError == ERROR_INVALID_NAME) { - throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), "ascii"); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), nameof(ascii)); } - throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), nameof(ascii)); } char [] output = new char[length]; @@ -321,10 +265,10 @@ namespace System.Globalization lastError = Marshal.GetLastWin32Error(); if (lastError == ERROR_INVALID_NAME) { - throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), "ascii"); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnIllegalName"), nameof(ascii)); } - throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), "ascii"); + throw new ArgumentException(Environment.GetResourceString("Argument_IdnBadPunycode"), nameof(ascii)); } return new String(output, 0, length); @@ -370,7 +314,7 @@ namespace System.Globalization // If its empty, then its too small if (unicode.Length == 0) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); Contract.EndContractBlock(); int iLastDot = -1; @@ -383,7 +327,7 @@ namespace System.Globalization { throw new ArgumentException( Environment.GetResourceString("Argument_InvalidCharSequence", i ), - "unicode"); + nameof(unicode)); } // If its Unicode or a control character, return false (non-ascii) @@ -396,12 +340,12 @@ namespace System.Globalization // Can't have 2 dots in a row if (i == iLastDot + 1) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); // If its too far between dots then fail if (i - iLastDot > M_labelLimit + 1) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "Unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); // If validating Std3, then char before dot can't be - char if (bUseStd3 && i > 0) @@ -422,14 +366,14 @@ namespace System.Globalization // If we never had a dot, then we need to be shorter than the label limit if (iLastDot == -1 && unicode.Length > M_labelLimit) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); // Need to validate entire string length, 1 shorter if last char wasn't a dot if (unicode.Length > M_defaultNameLimit - (IsDot(unicode[unicode.Length-1])? 0 : 1)) throw new ArgumentException(Environment.GetResourceString( "Argument_IdnBadNameSize", M_defaultNameLimit - (IsDot(unicode[unicode.Length-1]) ? 0 : 1)), - "unicode"); + nameof(unicode)); // If last char wasn't a dot we need to check for trailing - if (bUseStd3 && !IsDot(unicode[unicode.Length-1])) @@ -592,7 +536,7 @@ namespace System.Globalization // 0 length strings aren't allowed if (unicode.Length == 0) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); Contract.EndContractBlock(); StringBuilder output = new StringBuilder(unicode.Length); @@ -615,7 +559,7 @@ namespace System.Globalization // Only allowed to have empty sections as trailing . if (iNextDot != unicode.Length) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); // Last dot, stop break; } @@ -645,7 +589,7 @@ namespace System.Globalization { // Oops, last wasn't RTL, last should be RTL if first is RTL throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadBidi"), "unicode"); + "Argument_IdnBadBidi"), nameof(unicode)); } } @@ -666,7 +610,7 @@ namespace System.Globalization { // Oops, throw error throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadBidi"), "unicode"); + "Argument_IdnBadBidi"), nameof(unicode)); } // If we're not RTL we can't have RTL chars @@ -675,7 +619,7 @@ namespace System.Globalization { // Oops, throw error throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadBidi"), "unicode"); + "Argument_IdnBadBidi"), nameof(unicode)); } // If its basic then add it @@ -704,7 +648,7 @@ namespace System.Globalization unicode.Substring(iAfterLastDot, M_strAcePrefix.Length).Equals( M_strAcePrefix, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "unicode"); + "Argument_IdnBadPunycode"), nameof(unicode)); // Need to do ACE encoding int numSurrogatePairs = 0; // number of surrogate pairs so far @@ -791,7 +735,7 @@ namespace System.Globalization // Make sure its not too big if (output.Length - iOutputAfterLastDot > M_labelLimit) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "unicode"); + "Argument_IdnBadLabelSize"), nameof(unicode)); // Done with this segment, add dot if necessary if (iNextDot != unicode.Length) @@ -806,7 +750,7 @@ namespace System.Globalization throw new ArgumentException(Environment.GetResourceString( "Argument_IdnBadNameSize", M_defaultNameLimit - (IsDot(unicode[unicode.Length-1]) ? 0 : 1)), - "unicode"); + nameof(unicode)); // Return our output string return output.ToString(); @@ -840,7 +784,7 @@ namespace System.Globalization // 0 length strings aren't allowed if (ascii.Length == 0) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "ascii"); + "Argument_IdnBadLabelSize"), nameof(ascii)); Contract.EndContractBlock(); // Throw if we're too long @@ -870,7 +814,7 @@ namespace System.Globalization // Only allowed to have empty sections as trailing . if (iNextDot != ascii.Length) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "ascii"); + "Argument_IdnBadLabelSize"), nameof(ascii)); // Last dot, stop break; @@ -879,7 +823,7 @@ namespace System.Globalization // In either case it can't be bigger than segment size if (iNextDot - iAfterLastDot > M_labelLimit) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "ascii"); + "Argument_IdnBadLabelSize"), nameof(ascii)); // See if this section's ASCII or ACE if (ascii.Length < M_strAcePrefix.Length + iAfterLastDot || @@ -893,7 +837,7 @@ namespace System.Globalization // // Only ASCII is allowed // if (ascii[i] >= 0x80) // throw new ArgumentException(Environment.GetResourceString( - // "Argument_IdnBadPunycode"), "ascii"); + // "Argument_IdnBadPunycode"), nameof(ascii)); // } // Its ASCII, copy it @@ -913,7 +857,7 @@ namespace System.Globalization // Trailing - not allowed if (iTemp == iNextDot - 1) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); int numBasicCodePoints; if (iTemp <= iAfterLastDot) @@ -931,7 +875,7 @@ namespace System.Globalization // Make sure we don't allow unicode in the ascii part if (ascii[copyAscii] > 0x7f) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); // When appending make sure they get lower cased output.Append((char)(ascii[copyAscii] >= 'A' && ascii[copyAscii] <='Z' ? @@ -970,7 +914,7 @@ namespace System.Globalization // Check to make sure we aren't overrunning our ascii string if (asciiIndex >= iNextDot) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); // decode the digit from the next char int digit = decode_digit(ascii[asciiIndex++]); @@ -978,7 +922,7 @@ namespace System.Globalization Contract.Assert(w > 0, "[IdnMapping.punycode_decode]Expected w > 0"); if (digit > (maxint - i) / w) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); i += (int)(digit * w); int t = k <= bias ? tmin : @@ -987,7 +931,7 @@ namespace System.Globalization Contract.Assert(punycodeBase != t, "[IdnMapping.punycode_decode]Expected t != punycodeBase (36)"); if (w > maxint / (punycodeBase - t)) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); w *= (punycodeBase - t); } @@ -1000,7 +944,7 @@ namespace System.Globalization "[IdnMapping.punycode_decode]Expected to have added > 0 characters this segment"); if (i / ((output.Length - iOutputAfterLastDot - numSurrogatePairs) + 1) > maxint - n) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); n += (int)(i / (output.Length - iOutputAfterLastDot - numSurrogatePairs + 1)); i %= (output.Length - iOutputAfterLastDot - numSurrogatePairs + 1); @@ -1016,7 +960,7 @@ namespace System.Globalization // Make sure n is legal if ((n < 0 || n > 0x10ffff) || (n >= 0xD800 && n <= 0xDFFF)) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); // insert n at position i of the output: Really tricky if we have surrogates int iUseInsertLocation; @@ -1034,7 +978,7 @@ namespace System.Globalization // If its a surrogate, we have to go one more if (iUseInsertLocation >= output.Length) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadPunycode"), "ascii"); + "Argument_IdnBadPunycode"), nameof(ascii)); if (Char.IsSurrogate(output[iUseInsertLocation])) iUseInsertLocation++; } @@ -1079,7 +1023,7 @@ namespace System.Globalization (!bRightToLeft && (eBidi == BidiCategory.RightToLeft || eBidi == BidiCategory.RightToLeftArabic))) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadBidi"), "ascii"); + "Argument_IdnBadBidi"), nameof(ascii)); // Make it lower case if we must (so we can test IsNormalized later) // if (output[iTest] >= 'A' && output[iTest] <= 'Z') @@ -1091,14 +1035,14 @@ namespace System.Globalization { // Oops, last wasn't RTL, last should be RTL if first is RTL throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadBidi"), "ascii"); + "Argument_IdnBadBidi"), nameof(ascii)); } } // See if this label was too long if (iNextDot - iAfterLastDot > M_labelLimit) throw new ArgumentException(Environment.GetResourceString( - "Argument_IdnBadLabelSize"), "ascii"); + "Argument_IdnBadLabelSize"), nameof(ascii)); // Done with this segment, add dot if necessary if (iNextDot != ascii.Length) diff --git a/src/mscorlib/src/System/Globalization/JapaneseCalendar.cs b/src/mscorlib/src/System/Globalization/JapaneseCalendar.cs index 2984d08ab3..07642b4d42 100644 --- a/src/mscorlib/src/System/Globalization/JapaneseCalendar.cs +++ b/src/mscorlib/src/System/Globalization/JapaneseCalendar.cs @@ -491,14 +491,14 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year <= 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } Contract.EndContractBlock(); if (year > helper.MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), diff --git a/src/mscorlib/src/System/Globalization/JulianCalendar.cs b/src/mscorlib/src/System/Globalization/JulianCalendar.cs index c98254808c..db286e0363 100644 --- a/src/mscorlib/src/System/Globalization/JulianCalendar.cs +++ b/src/mscorlib/src/System/Globalization/JulianCalendar.cs @@ -112,7 +112,7 @@ namespace System.Globalization { static internal void CheckEraRange(int era) { if (era != CurrentEra && era != JulianEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } } @@ -120,7 +120,7 @@ namespace System.Globalization { CheckEraRange(era); if (year <= 0 || year > MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -131,7 +131,7 @@ namespace System.Globalization { static internal void CheckMonthRange(int month) { if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } } @@ -159,7 +159,7 @@ namespace System.Globalization { int monthDays = days[month] - days[month - 1]; if (day < 1 || day > monthDays) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -230,7 +230,7 @@ namespace System.Globalization { { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -377,7 +377,7 @@ namespace System.Globalization { CheckDayRange(year, month, day); if (millisecond < 0 || millisecond >= MillisPerSecond) { throw new ArgumentOutOfRangeException( - "millisecond", + nameof(millisecond), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -420,14 +420,14 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); if (year > MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"), diff --git a/src/mscorlib/src/System/Globalization/KoreanCalendar.cs b/src/mscorlib/src/System/Globalization/KoreanCalendar.cs index 9343884445..dde82b6e6b 100644 --- a/src/mscorlib/src/System/Globalization/KoreanCalendar.cs +++ b/src/mscorlib/src/System/Globalization/KoreanCalendar.cs @@ -254,7 +254,7 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/KoreanLunisolarCalendar.cs b/src/mscorlib/src/System/Globalization/KoreanLunisolarCalendar.cs index eb0a810864..9e36b435e7 100644 --- a/src/mscorlib/src/System/Globalization/KoreanLunisolarCalendar.cs +++ b/src/mscorlib/src/System/Globalization/KoreanLunisolarCalendar.cs @@ -1267,12 +1267,12 @@ namespace System.Globalization { internal override int GetGregorianYear(int year, int era) { if (era != CurrentEra && era != GregorianEra) - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); if (year < MIN_LUNISOLAR_YEAR || year > MAX_LUNISOLAR_YEAR) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), MIN_LUNISOLAR_YEAR, MAX_LUNISOLAR_YEAR)); diff --git a/src/mscorlib/src/System/Globalization/NumberFormatInfo.cs b/src/mscorlib/src/System/Globalization/NumberFormatInfo.cs index fae91c2a1d..bdd4dfcb0e 100644 --- a/src/mscorlib/src/System/Globalization/NumberFormatInfo.cs +++ b/src/mscorlib/src/System/Globalization/NumberFormatInfo.cs @@ -316,7 +316,7 @@ namespace System.Globalization { set { if (value < 0 || value > 99) { throw new ArgumentOutOfRangeException( - "CurrencyDecimalDigits", + nameof(CurrencyDecimalDigits), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -376,7 +376,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("CurrencyGroupSizes", + throw new ArgumentNullException(nameof(CurrencyGroupSizes), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -397,7 +397,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("NumberGroupSizes", + throw new ArgumentNullException(nameof(NumberGroupSizes), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -416,7 +416,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("PercentGroupSizes", + throw new ArgumentNullException(nameof(PercentGroupSizes), Environment.GetResourceString("ArgumentNull_Obj")); } Contract.EndContractBlock(); @@ -443,7 +443,7 @@ namespace System.Globalization { get { return currencySymbol; } set { if (value == null) { - throw new ArgumentNullException("CurrencySymbol", + throw new ArgumentNullException(nameof(CurrencySymbol), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -475,7 +475,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("NaNSymbol", + throw new ArgumentNullException(nameof(NaNSymbol), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -491,7 +491,7 @@ namespace System.Globalization { set { if (value < 0 || value > 15) { throw new ArgumentOutOfRangeException( - "CurrencyNegativePattern", + nameof(CurrencyNegativePattern), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -513,7 +513,7 @@ namespace System.Globalization { // if (value < 0 || value > 4) { throw new ArgumentOutOfRangeException( - "NumberNegativePattern", + nameof(NumberNegativePattern), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -535,7 +535,7 @@ namespace System.Globalization { // if (value < 0 || value > 3) { throw new ArgumentOutOfRangeException( - "PercentPositivePattern", + nameof(PercentPositivePattern), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -557,7 +557,7 @@ namespace System.Globalization { // if (value < 0 || value > 11) { throw new ArgumentOutOfRangeException( - "PercentNegativePattern", + nameof(PercentNegativePattern), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -577,7 +577,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("NegativeInfinitySymbol", + throw new ArgumentNullException(nameof(NegativeInfinitySymbol), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -591,7 +591,7 @@ namespace System.Globalization { get { return negativeSign; } set { if (value == null) { - throw new ArgumentNullException("NegativeSign", + throw new ArgumentNullException(nameof(NegativeSign), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -606,7 +606,7 @@ namespace System.Globalization { set { if (value < 0 || value > 99) { throw new ArgumentOutOfRangeException( - "NumberDecimalDigits", + nameof(NumberDecimalDigits), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -645,7 +645,7 @@ namespace System.Globalization { set { if (value < 0 || value > 3) { throw new ArgumentOutOfRangeException( - "CurrencyPositivePattern", + nameof(CurrencyPositivePattern), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -665,7 +665,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("PositiveInfinitySymbol", + throw new ArgumentNullException(nameof(PositiveInfinitySymbol), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -679,7 +679,7 @@ namespace System.Globalization { get { return positiveSign; } set { if (value == null) { - throw new ArgumentNullException("PositiveSign", + throw new ArgumentNullException(nameof(PositiveSign), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -694,7 +694,7 @@ namespace System.Globalization { set { if (value < 0 || value > 99) { throw new ArgumentOutOfRangeException( - "PercentDecimalDigits", + nameof(PercentDecimalDigits), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -734,7 +734,7 @@ namespace System.Globalization { } set { if (value == null) { - throw new ArgumentNullException("PercentSymbol", + throw new ArgumentNullException(nameof(PercentSymbol), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -748,7 +748,7 @@ namespace System.Globalization { get { return perMilleSymbol; } set { if (value == null) { - throw new ArgumentNullException("PerMilleSymbol", + throw new ArgumentNullException(nameof(PerMilleSymbol), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -788,7 +788,7 @@ namespace System.Globalization { public static NumberFormatInfo ReadOnly(NumberFormatInfo nfi) { if (nfi == null) { - throw new ArgumentNullException("nfi"); + throw new ArgumentNullException(nameof(nfi)); } Contract.EndContractBlock(); if (nfi.IsReadOnly) { @@ -809,7 +809,7 @@ namespace System.Globalization { internal static void ValidateParseStyleInteger(NumberStyles style) { // Check for undefined flags if ((style & InvalidNumberStyles) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNumberStyles"), "style"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNumberStyles"), nameof(style)); } Contract.EndContractBlock(); if ((style & NumberStyles.AllowHexSpecifier) != 0) { // Check for hex number @@ -822,7 +822,7 @@ namespace System.Globalization { internal static void ValidateParseStyleFloatingPoint(NumberStyles style) { // Check for undefined flags if ((style & InvalidNumberStyles) != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNumberStyles"), "style"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNumberStyles"), nameof(style)); } Contract.EndContractBlock(); if ((style & NumberStyles.AllowHexSpecifier) != 0) { // Check for hex number diff --git a/src/mscorlib/src/System/Globalization/PersianCalendar.cs b/src/mscorlib/src/System/Globalization/PersianCalendar.cs index 2f1ffacee7..ff15699971 100644 --- a/src/mscorlib/src/System/Globalization/PersianCalendar.cs +++ b/src/mscorlib/src/System/Globalization/PersianCalendar.cs @@ -147,7 +147,7 @@ namespace System.Globalization { static internal void CheckEraRange(int era) { if (era != CurrentEra && era != PersianEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } } @@ -155,7 +155,7 @@ namespace System.Globalization { CheckEraRange(era); if (year < 1 || year > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -169,7 +169,7 @@ namespace System.Globalization { if (year == MaxCalendarYear) { if (month > MaxCalendarMonth) { throw new ArgumentOutOfRangeException( - "month", + nameof(month), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -179,7 +179,7 @@ namespace System.Globalization { } if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } } @@ -290,7 +290,7 @@ namespace System.Globalization { public override DateTime AddMonths(DateTime time, int months) { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -450,7 +450,7 @@ namespace System.Globalization { int daysInMonth = GetDaysInMonth(year, month, era); if (day < 1 || day > daysInMonth) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Day"), @@ -506,7 +506,7 @@ namespace System.Globalization { if (day < 1 || day > daysInMonth) { BCLDebug.Log("year = " + year + ", month = " + month + ", day = " + day); throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Day"), @@ -538,7 +538,7 @@ namespace System.Globalization { if (value < 99 || value > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "value", + nameof(value), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -553,7 +553,7 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -564,7 +564,7 @@ namespace System.Globalization { if (year > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), diff --git a/src/mscorlib/src/System/Globalization/RegionInfo.cs b/src/mscorlib/src/System/Globalization/RegionInfo.cs index f06d63f1d2..d635458faa 100644 --- a/src/mscorlib/src/System/Globalization/RegionInfo.cs +++ b/src/mscorlib/src/System/Globalization/RegionInfo.cs @@ -62,11 +62,11 @@ namespace System.Globalization { [System.Security.SecuritySafeCritical] // auto-generated public RegionInfo(String name) { if (name==null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) //The InvariantCulture has no matching region { - throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_NoRegionInvariantCulture"), nameof(name)); } Contract.EndContractBlock(); @@ -83,12 +83,12 @@ namespace System.Globalization { throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, - Environment.GetResourceString("Argument_InvalidCultureName"), name), "name"); + Environment.GetResourceString("Argument_InvalidCultureName"), name), nameof(name)); // Not supposed to be neutral if (this.m_cultureData.IsNeutralCulture) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", name), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidNeutralRegionName", name), nameof(name)); SetName(name); } @@ -106,13 +106,13 @@ namespace System.Globalization { if (culture == CultureInfo.LOCALE_NEUTRAL) { // Not supposed to be neutral - throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture"); + throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), nameof(culture)); } if (culture == CultureInfo.LOCALE_CUSTOM_DEFAULT) { // Not supposed to be neutral - throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", culture), "culture"); + throw new ArgumentException(Environment.GetResourceString("Argument_CustomCultureCannotBePassedByNumber", culture), nameof(culture)); } this.m_cultureData = CultureData.GetCultureData(culture,true); @@ -121,7 +121,7 @@ namespace System.Globalization { if (this.m_cultureData.IsNeutralCulture) { // Not supposed to be neutral - throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), "culture"); + throw new ArgumentException(Environment.GetResourceString("Argument_CultureIsNeutral", culture), nameof(culture)); } m_cultureId = culture; } @@ -330,7 +330,7 @@ namespace System.Globalization { throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, - Environment.GetResourceString("Argument_InvalidCultureName"), m_name), "m_name"); + Environment.GetResourceString("Argument_InvalidCultureName"), m_name), nameof(m_name)); if (m_cultureId == 0) { diff --git a/src/mscorlib/src/System/Globalization/SortKey.cs b/src/mscorlib/src/System/Globalization/SortKey.cs index e3308dc4f8..62207c286e 100644 --- a/src/mscorlib/src/System/Globalization/SortKey.cs +++ b/src/mscorlib/src/System/Globalization/SortKey.cs @@ -119,7 +119,7 @@ namespace System.Globalization { public static int Compare(SortKey sortkey1, SortKey sortkey2) { if (sortkey1==null || sortkey2==null) { - throw new ArgumentNullException((sortkey1==null ? "sortkey1": "sortkey2")); + throw new ArgumentNullException((sortkey1==null ? nameof(sortkey1): nameof(sortkey2))); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/StringInfo.cs b/src/mscorlib/src/System/Globalization/StringInfo.cs index b1151bde4f..40b2f92997 100644 --- a/src/mscorlib/src/System/Globalization/StringInfo.cs +++ b/src/mscorlib/src/System/Globalization/StringInfo.cs @@ -92,7 +92,7 @@ namespace System.Globalization { } set { if (null == value) { - throw new ArgumentNullException("String", + throw new ArgumentNullException(nameof(String), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); @@ -118,11 +118,11 @@ namespace System.Globalization { if(null == this.Indexes) { // Just decide which error to give depending on the param they gave us.... if(startingTextElement < 0) { - throw new ArgumentOutOfRangeException("startingTextElement", + throw new ArgumentOutOfRangeException(nameof(startingTextElement), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } else { - throw new ArgumentOutOfRangeException("startingTextElement", + throw new ArgumentOutOfRangeException(nameof(startingTextElement), Environment.GetResourceString("Arg_ArgumentOutOfRangeException")); } } @@ -135,22 +135,22 @@ namespace System.Globalization { // Parameter checking // if(startingTextElement < 0) { - throw new ArgumentOutOfRangeException("startingTextElement", + throw new ArgumentOutOfRangeException(nameof(startingTextElement), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } if(this.String.Length == 0 || startingTextElement >= this.Indexes.Length) { - throw new ArgumentOutOfRangeException("startingTextElement", + throw new ArgumentOutOfRangeException(nameof(startingTextElement), Environment.GetResourceString("Arg_ArgumentOutOfRangeException")); } if(lengthInTextElements < 0) { - throw new ArgumentOutOfRangeException("lengthInTextElements", + throw new ArgumentOutOfRangeException(nameof(lengthInTextElements), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } if(startingTextElement > this.Indexes.Length - lengthInTextElements) { - throw new ArgumentOutOfRangeException("lengthInTextElements", + throw new ArgumentOutOfRangeException(nameof(lengthInTextElements), Environment.GetResourceString("Arg_ArgumentOutOfRangeException")); } @@ -268,7 +268,7 @@ namespace System.Globalization { // Validate parameters. // if (str==null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); @@ -277,7 +277,7 @@ namespace System.Globalization { if (index == len) { return (String.Empty); } - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } int charLen; @@ -297,14 +297,14 @@ namespace System.Globalization { // if (str==null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); int len = str.Length; if (index < 0 || (index > len)) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } return (new TextElementEnumerator(str, index, len)); @@ -326,7 +326,7 @@ namespace System.Globalization { { if (str == null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/TaiwanCalendar.cs b/src/mscorlib/src/System/Globalization/TaiwanCalendar.cs index 013e2cd50e..476ddeef7c 100644 --- a/src/mscorlib/src/System/Globalization/TaiwanCalendar.cs +++ b/src/mscorlib/src/System/Globalization/TaiwanCalendar.cs @@ -241,14 +241,14 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year <= 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } Contract.EndContractBlock(); if (year > helper.MaxYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), diff --git a/src/mscorlib/src/System/Globalization/TextInfo.cs b/src/mscorlib/src/System/Globalization/TextInfo.cs index 9b84486f4e..4fa9f66c50 100644 --- a/src/mscorlib/src/System/Globalization/TextInfo.cs +++ b/src/mscorlib/src/System/Globalization/TextInfo.cs @@ -462,7 +462,7 @@ namespace System.Globalization { [System.Runtime.InteropServices.ComVisible(false)] public static TextInfo ReadOnly(TextInfo textInfo) { - if (textInfo == null) { throw new ArgumentNullException("textInfo"); } + if (textInfo == null) { throw new ArgumentNullException(nameof(textInfo)); } Contract.EndContractBlock(); if (textInfo.IsReadOnly) { return (textInfo); } @@ -512,7 +512,7 @@ namespace System.Globalization { { if (value == null) { - throw new ArgumentNullException("value", Environment.GetResourceString("ArgumentNull_String")); + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } Contract.EndContractBlock(); VerifyWritable(); @@ -542,7 +542,7 @@ namespace System.Globalization { [System.Security.SecuritySafeCritical] // auto-generated public unsafe virtual String ToLower(String str) { - if (str == null) { throw new ArgumentNullException("str"); } + if (str == null) { throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); return InternalChangeCaseString(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, false); @@ -581,7 +581,7 @@ namespace System.Globalization { [System.Security.SecuritySafeCritical] // auto-generated public unsafe virtual String ToUpper(String str) { - if (str == null) { throw new ArgumentNullException("str"); } + if (str == null) { throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); return InternalChangeCaseString(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, true); } @@ -698,7 +698,7 @@ namespace System.Globalization { { if (str == null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); if (str.Length == 0) @@ -959,7 +959,7 @@ namespace System.Globalization { // Validate inputs if (str==null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/ThaiBuddhistCalendar.cs b/src/mscorlib/src/System/Globalization/ThaiBuddhistCalendar.cs index f26c68adce..e294b51325 100644 --- a/src/mscorlib/src/System/Globalization/ThaiBuddhistCalendar.cs +++ b/src/mscorlib/src/System/Globalization/ThaiBuddhistCalendar.cs @@ -213,7 +213,7 @@ namespace System.Globalization { public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Globalization/UmAlQuraCalendar.cs b/src/mscorlib/src/System/Globalization/UmAlQuraCalendar.cs index 94b235085e..8379c88cc3 100644 --- a/src/mscorlib/src/System/Globalization/UmAlQuraCalendar.cs +++ b/src/mscorlib/src/System/Globalization/UmAlQuraCalendar.cs @@ -392,7 +392,7 @@ namespace System.Globalization { static internal void CheckEraRange(int era) { if (era != CurrentEra && era != UmAlQuraEra) { - throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); + throw new ArgumentOutOfRangeException(nameof(era), Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue")); } } @@ -400,7 +400,7 @@ namespace System.Globalization { CheckEraRange(era); if (year < MinCalendarYear || year > MaxCalendarYear) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -412,7 +412,7 @@ namespace System.Globalization { static internal void CheckYearMonthRange(int year, int month, int era) { CheckYearRange(year, era); if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_Month")); } } @@ -528,7 +528,7 @@ namespace System.Globalization { public override DateTime AddMonths(DateTime time, int months) { if (months < -120000 || months > 120000) { throw new ArgumentOutOfRangeException( - "months", + nameof(months), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -712,7 +712,7 @@ namespace System.Globalization { int daysInMonth = GetDaysInMonth(year, month, era); if (day < 1 || day > daysInMonth) { throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Day"), @@ -774,7 +774,7 @@ namespace System.Globalization { if (day < 1 || day > daysInMonth) { BCLDebug.Log("year = " + year + ", month = " + month + ", day = " + day); throw new ArgumentOutOfRangeException( - "day", + nameof(day), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Day"), @@ -806,7 +806,7 @@ DayInRang: set { if (value != 99 && (value < MinCalendarYear || value > MaxCalendarYear)) { throw new ArgumentOutOfRangeException( - "value", + nameof(value), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), @@ -824,7 +824,7 @@ DayInRang: public override int ToFourDigitYear(int year) { if (year < 0) { - throw new ArgumentOutOfRangeException("year", + throw new ArgumentOutOfRangeException(nameof(year), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -835,7 +835,7 @@ DayInRang: if ((year < MinCalendarYear) || (year > MaxCalendarYear)) { throw new ArgumentOutOfRangeException( - "year", + nameof(year), String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), diff --git a/src/mscorlib/src/System/Guid.cs b/src/mscorlib/src/System/Guid.cs index 1ccabeb8db..c8ee9f0983 100644 --- a/src/mscorlib/src/System/Guid.cs +++ b/src/mscorlib/src/System/Guid.cs @@ -47,9 +47,9 @@ namespace System { public Guid(byte[] b) { if (b==null) - throw new ArgumentNullException("b"); + throw new ArgumentNullException(nameof(b)); if (b.Length != 16) - throw new ArgumentException(Environment.GetResourceString("Arg_GuidArrayCtor", "16"), "b"); + throw new ArgumentException(Environment.GetResourceString("Arg_GuidArrayCtor", "16"), nameof(b)); Contract.EndContractBlock(); _a = ((int)b[3] << 24) | ((int)b[2] << 16) | ((int)b[1] << 8) | b[0]; @@ -87,10 +87,10 @@ namespace System { public Guid(int a, short b, short c, byte[] d) { if (d==null) - throw new ArgumentNullException("d"); + throw new ArgumentNullException(nameof(d)); // Check that array is not too big if(d.Length != 8) - throw new ArgumentException(Environment.GetResourceString("Arg_GuidArrayCtor", "8"), "d"); + throw new ArgumentException(Environment.GetResourceString("Arg_GuidArrayCtor", "8"), nameof(d)); Contract.EndContractBlock(); _a = a; @@ -231,7 +231,7 @@ namespace System { public Guid(String g) { if (g==null) { - throw new ArgumentNullException("g"); + throw new ArgumentNullException(nameof(g)); } Contract.EndContractBlock(); this = Guid.Empty; @@ -250,7 +250,7 @@ namespace System { public static Guid Parse(String input) { if (input == null) { - throw new ArgumentNullException("input"); + throw new ArgumentNullException(nameof(input)); } Contract.EndContractBlock(); @@ -281,10 +281,10 @@ namespace System { public static Guid ParseExact(String input, String format) { if (input == null) - throw new ArgumentNullException("input"); + throw new ArgumentNullException(nameof(input)); if (format == null) - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); if( format.Length != 1) { // all acceptable format strings are of length 1 @@ -1007,7 +1007,7 @@ namespace System { return 1; } if (!(value is Guid)) { - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeGuid"), "value"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeGuid"), nameof(value)); } Guid g = (Guid)value; diff --git a/src/mscorlib/src/System/IO/BinaryReader.cs b/src/mscorlib/src/System/IO/BinaryReader.cs index 8accf0bd77..ef8245f8e8 100644 --- a/src/mscorlib/src/System/IO/BinaryReader.cs +++ b/src/mscorlib/src/System/IO/BinaryReader.cs @@ -48,10 +48,10 @@ namespace System.IO { public BinaryReader(Stream input, Encoding encoding, bool leaveOpen) { if (input==null) { - throw new ArgumentNullException("input"); + throw new ArgumentNullException(nameof(input)); } if (encoding==null) { - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); } if (!input.CanRead) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); @@ -297,13 +297,13 @@ namespace System.IO { [SecuritySafeCritical] public virtual int Read(char[] buffer, int index, int count) { if (buffer==null) { - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); } if (index < 0) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (buffer.Length - index < count) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); @@ -475,7 +475,7 @@ namespace System.IO { [SecuritySafeCritical] public virtual char[] ReadChars(int count) { if (count<0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.Ensures(Contract.Result<char[]>() != null); Contract.Ensures(Contract.Result<char[]>().Length <= count); @@ -502,11 +502,11 @@ namespace System.IO { public virtual int Read(byte[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.Ensures(Contract.Result<int>() >= 0); @@ -518,7 +518,7 @@ namespace System.IO { } public virtual byte[] ReadBytes(int count) { - if (count < 0) throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.Ensures(Contract.Result<byte[]>() != null); Contract.Ensures(Contract.Result<byte[]>().Length <= Contract.OldValue(count)); Contract.EndContractBlock(); @@ -551,7 +551,7 @@ namespace System.IO { protected virtual void FillBuffer(int numBytes) { if (m_buffer != null && (numBytes < 0 || numBytes > m_buffer.Length)) { - throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_BinaryReaderFillBuffer")); + throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_BinaryReaderFillBuffer")); } int bytesRead=0; int n = 0; diff --git a/src/mscorlib/src/System/IO/BinaryWriter.cs b/src/mscorlib/src/System/IO/BinaryWriter.cs index c775cbc9ff..3aa7e9b03c 100644 --- a/src/mscorlib/src/System/IO/BinaryWriter.cs +++ b/src/mscorlib/src/System/IO/BinaryWriter.cs @@ -73,9 +73,9 @@ namespace System.IO { public BinaryWriter(Stream output, Encoding encoding, bool leaveOpen) { if (output==null) - throw new ArgumentNullException("output"); + throw new ArgumentNullException(nameof(output)); if (encoding==null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (!output.CanWrite) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotWritable")); Contract.EndContractBlock(); @@ -166,7 +166,7 @@ namespace System.IO { // public virtual void Write(byte[] buffer) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); Contract.EndContractBlock(); OutStream.Write(buffer, 0, buffer.Length); } @@ -207,7 +207,7 @@ namespace System.IO { public virtual void Write(char[] chars) { if (chars == null) - throw new ArgumentNullException("chars"); + throw new ArgumentNullException(nameof(chars)); Contract.EndContractBlock(); byte[] bytes = _encoding.GetBytes(chars, 0, chars.Length); @@ -353,7 +353,7 @@ namespace System.IO { public unsafe virtual void Write(String value) { if (value==null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); int len = _encoding.GetByteCount(value); diff --git a/src/mscorlib/src/System/IO/Directory.cs b/src/mscorlib/src/System/IO/Directory.cs index 7de5e4ce68..d9708051e1 100644 --- a/src/mscorlib/src/System/IO/Directory.cs +++ b/src/mscorlib/src/System/IO/Directory.cs @@ -39,10 +39,10 @@ namespace System.IO { public static DirectoryInfo GetParent(String path) { if (path==null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length==0) - throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"), "path"); + throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"), nameof(path)); Contract.EndContractBlock(); String fullPath = Path.GetFullPathInternal(path); @@ -56,7 +56,7 @@ namespace System.IO { [System.Security.SecuritySafeCritical] public static DirectoryInfo CreateDirectory(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty")); Contract.EndContractBlock(); @@ -68,7 +68,7 @@ namespace System.IO { internal static DirectoryInfo UnsafeCreateDirectory(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty")); Contract.EndContractBlock(); @@ -109,7 +109,7 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated public static DirectoryInfo CreateDirectory(String path, DirectorySecurity directorySecurity) { if (path==null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty")); Contract.EndContractBlock(); @@ -512,7 +512,7 @@ namespace System.IO { public static void SetAccessControl(String path, DirectorySecurity directorySecurity) { if (directorySecurity == null) - throw new ArgumentNullException("directorySecurity"); + throw new ArgumentNullException(nameof(directorySecurity)); Contract.EndContractBlock(); String fullPath = Path.GetFullPathInternal(path); @@ -524,7 +524,7 @@ namespace System.IO { public static String[] GetFiles(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -536,9 +536,9 @@ namespace System.IO { public static String[] GetFiles(String path, String searchPattern) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -550,11 +550,11 @@ namespace System.IO { public static String[] GetFiles(String path, String searchPattern, SearchOption searchOption) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -586,7 +586,7 @@ namespace System.IO { public static String[] GetDirectories(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -598,9 +598,9 @@ namespace System.IO { public static String[] GetDirectories(String path, String searchPattern) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -612,11 +612,11 @@ namespace System.IO { public static String[] GetDirectories(String path, String searchPattern, SearchOption searchOption) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -650,7 +650,7 @@ namespace System.IO { public static String[] GetFileSystemEntries(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -662,9 +662,9 @@ namespace System.IO { public static String[] GetFileSystemEntries(String path, String searchPattern) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -676,11 +676,11 @@ namespace System.IO { public static String[] GetFileSystemEntries(String path, String searchPattern, SearchOption searchOption) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.Ensures(Contract.Result<String[]>() != null); Contract.EndContractBlock(); @@ -740,7 +740,7 @@ namespace System.IO { public static IEnumerable<String> EnumerateDirectories(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); return InternalEnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly); @@ -749,9 +749,9 @@ namespace System.IO { public static IEnumerable<String> EnumerateDirectories(String path, String searchPattern) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalEnumerateDirectories(path, searchPattern, SearchOption.TopDirectoryOnly); @@ -760,11 +760,11 @@ namespace System.IO { public static IEnumerable<String> EnumerateDirectories(String path, String searchPattern, SearchOption searchOption) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalEnumerateDirectories(path, searchPattern, searchOption); @@ -782,7 +782,7 @@ namespace System.IO { public static IEnumerable<String> EnumerateFiles(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -792,9 +792,9 @@ namespace System.IO { public static IEnumerable<String> EnumerateFiles(String path, String searchPattern) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -804,11 +804,11 @@ namespace System.IO { public static IEnumerable<String> EnumerateFiles(String path, String searchPattern, SearchOption searchOption) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -828,7 +828,7 @@ namespace System.IO { public static IEnumerable<String> EnumerateFileSystemEntries(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -838,9 +838,9 @@ namespace System.IO { public static IEnumerable<String> EnumerateFileSystemEntries(String path, String searchPattern) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -850,11 +850,11 @@ namespace System.IO { public static IEnumerable<String> EnumerateFileSystemEntries(String path, String searchPattern, SearchOption searchOption) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.Ensures(Contract.Result<IEnumerable<String>>() != null); Contract.EndContractBlock(); @@ -923,7 +923,7 @@ namespace System.IO { [System.Security.SecuritySafeCritical] public static String GetDirectoryRoot(String path) { if (path==null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); String fullPath = Path.GetFullPathInternal(path); @@ -1054,7 +1054,7 @@ namespace System.IO { public static void SetCurrentDirectory(String path) { if (path==null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(path)); if (path.Length==0) throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty")); Contract.EndContractBlock(); @@ -1093,14 +1093,14 @@ namespace System.IO { [System.Security.SecurityCritical] private static void InternalMove(String sourceDirName,String destDirName,bool checkHost) { if (sourceDirName==null) - throw new ArgumentNullException("sourceDirName"); + throw new ArgumentNullException(nameof(sourceDirName)); if (sourceDirName.Length==0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "sourceDirName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceDirName)); if (destDirName==null) - throw new ArgumentNullException("destDirName"); + throw new ArgumentNullException(nameof(destDirName)); if (destDirName.Length==0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destDirName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destDirName)); Contract.EndContractBlock(); String fullsourceDirName = Path.GetFullPathInternal(sourceDirName); diff --git a/src/mscorlib/src/System/IO/DirectoryInfo.cs b/src/mscorlib/src/System/IO/DirectoryInfo.cs index f7b0709e9e..ec58ae9bff 100644 --- a/src/mscorlib/src/System/IO/DirectoryInfo.cs +++ b/src/mscorlib/src/System/IO/DirectoryInfo.cs @@ -51,7 +51,7 @@ namespace System.IO { public static DirectoryInfo UnsafeCreateDirectoryInfo(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); DirectoryInfo di = new DirectoryInfo(); @@ -64,7 +64,7 @@ namespace System.IO { public DirectoryInfo(String path) { if (path==null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); Init(path, true); @@ -167,7 +167,7 @@ namespace System.IO { #endif public DirectoryInfo CreateSubdirectory(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); return CreateSubdirectory(path, null); @@ -186,7 +186,7 @@ namespace System.IO { public DirectoryInfo CreateSubdirectory(String path, Object directorySecurity) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); return CreateSubdirectoryHelper(path, directorySecurity); @@ -280,7 +280,7 @@ namespace System.IO { public FileInfo[] GetFiles(String searchPattern) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalGetFiles(searchPattern, SearchOption.TopDirectoryOnly); @@ -291,9 +291,9 @@ namespace System.IO { public FileInfo[] GetFiles(String searchPattern, SearchOption searchOption) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalGetFiles(searchPattern, searchOption); @@ -328,7 +328,7 @@ namespace System.IO { public FileSystemInfo[] GetFileSystemInfos(String searchPattern) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalGetFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly); @@ -339,9 +339,9 @@ namespace System.IO { public FileSystemInfo[] GetFileSystemInfos(String searchPattern, SearchOption searchOption) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalGetFileSystemInfos(searchPattern, searchOption); @@ -372,7 +372,7 @@ namespace System.IO { public DirectoryInfo[] GetDirectories(String searchPattern) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalGetDirectories(searchPattern, SearchOption.TopDirectoryOnly); @@ -384,9 +384,9 @@ namespace System.IO { public DirectoryInfo[] GetDirectories(String searchPattern, SearchOption searchOption) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalGetDirectories(searchPattern, searchOption); @@ -413,7 +413,7 @@ namespace System.IO { public IEnumerable<DirectoryInfo> EnumerateDirectories(String searchPattern) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalEnumerateDirectories(searchPattern, SearchOption.TopDirectoryOnly); @@ -422,9 +422,9 @@ namespace System.IO { public IEnumerable<DirectoryInfo> EnumerateDirectories(String searchPattern, SearchOption searchOption) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalEnumerateDirectories(searchPattern, searchOption); @@ -446,7 +446,7 @@ namespace System.IO { public IEnumerable<FileInfo> EnumerateFiles(String searchPattern) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalEnumerateFiles(searchPattern, SearchOption.TopDirectoryOnly); @@ -455,9 +455,9 @@ namespace System.IO { public IEnumerable<FileInfo> EnumerateFiles(String searchPattern, SearchOption searchOption) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalEnumerateFiles(searchPattern, searchOption); @@ -479,7 +479,7 @@ namespace System.IO { public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(String searchPattern) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); Contract.EndContractBlock(); return InternalEnumerateFileSystemInfos(searchPattern, SearchOption.TopDirectoryOnly); @@ -488,9 +488,9 @@ namespace System.IO { public IEnumerable<FileSystemInfo> EnumerateFileSystemInfos(String searchPattern, SearchOption searchOption) { if (searchPattern == null) - throw new ArgumentNullException("searchPattern"); + throw new ArgumentNullException(nameof(searchPattern)); if ((searchOption != SearchOption.TopDirectoryOnly) && (searchOption != SearchOption.AllDirectories)) - throw new ArgumentOutOfRangeException("searchOption", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(searchOption), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); return InternalEnumerateFileSystemInfos(searchPattern, searchOption); @@ -536,9 +536,9 @@ namespace System.IO { [System.Security.SecuritySafeCritical] public void MoveTo(String destDirName) { if (destDirName==null) - throw new ArgumentNullException("destDirName"); + throw new ArgumentNullException(nameof(destDirName)); if (destDirName.Length==0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destDirName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destDirName)); Contract.EndContractBlock(); #if FEATURE_CORECLR diff --git a/src/mscorlib/src/System/IO/DriveInfo.cs b/src/mscorlib/src/System/IO/DriveInfo.cs index be75e8979d..62eac429af 100644 --- a/src/mscorlib/src/System/IO/DriveInfo.cs +++ b/src/mscorlib/src/System/IO/DriveInfo.cs @@ -57,7 +57,7 @@ namespace System.IO public DriveInfo(String driveName) { if (driveName == null) - throw new ArgumentNullException("driveName"); + throw new ArgumentNullException(nameof(driveName)); Contract.EndContractBlock(); if (driveName.Length == 1) _name = driveName + ":\\"; diff --git a/src/mscorlib/src/System/IO/File.cs b/src/mscorlib/src/System/IO/File.cs index 6bf7bbc7f7..76cd0b2280 100644 --- a/src/mscorlib/src/System/IO/File.cs +++ b/src/mscorlib/src/System/IO/File.cs @@ -46,7 +46,7 @@ namespace System.IO { public static StreamReader OpenText(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); return new StreamReader(path); } @@ -54,7 +54,7 @@ namespace System.IO { public static StreamWriter CreateText(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); return new StreamWriter(path,false); } @@ -62,7 +62,7 @@ namespace System.IO { public static StreamWriter AppendText(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); return new StreamWriter(path,true); } @@ -79,13 +79,13 @@ namespace System.IO { // public static void Copy(String sourceFileName, String destFileName) { if (sourceFileName == null) - throw new ArgumentNullException("sourceFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(sourceFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (destFileName == null) - throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (sourceFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "sourceFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceFileName)); if (destFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); InternalCopy(sourceFileName, destFileName, false, true); @@ -102,13 +102,13 @@ namespace System.IO { // public static void Copy(String sourceFileName, String destFileName, bool overwrite) { if (sourceFileName == null) - throw new ArgumentNullException("sourceFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(sourceFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (destFileName == null) - throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (sourceFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "sourceFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceFileName)); if (destFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); InternalCopy(sourceFileName, destFileName, overwrite, true); @@ -117,13 +117,13 @@ namespace System.IO { [System.Security.SecurityCritical] internal static void UnsafeCopy(String sourceFileName, String destFileName, bool overwrite) { if (sourceFileName == null) - throw new ArgumentNullException("sourceFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(sourceFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (destFileName == null) - throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (sourceFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "sourceFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceFileName)); if (destFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); InternalCopy(sourceFileName, destFileName, overwrite, false); @@ -232,7 +232,7 @@ namespace System.IO { [System.Security.SecuritySafeCritical] public static void Delete(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); InternalDelete(path, true); @@ -242,7 +242,7 @@ namespace System.IO { internal static void UnsafeDelete(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); InternalDelete(path, false); @@ -279,7 +279,7 @@ namespace System.IO { public static void Decrypt(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); String fullPath = Path.GetFullPathInternal(path); @@ -303,7 +303,7 @@ namespace System.IO { public static void Encrypt(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); String fullPath = Path.GetFullPathInternal(path); @@ -630,7 +630,7 @@ namespace System.IO { public static void SetAccessControl(String path, FileSecurity fileSecurity) { if (fileSecurity == null) - throw new ArgumentNullException("fileSecurity"); + throw new ArgumentNullException(nameof(fileSecurity)); Contract.EndContractBlock(); String fullPath = Path.GetFullPathInternal(path); @@ -653,7 +653,7 @@ namespace System.IO { public static String ReadAllText(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -665,9 +665,9 @@ namespace System.IO { public static String ReadAllText(String path, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -679,7 +679,7 @@ namespace System.IO { internal static String UnsafeReadAllText(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -702,7 +702,7 @@ namespace System.IO { public static void WriteAllText(String path, String contents) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -714,9 +714,9 @@ namespace System.IO { public static void WriteAllText(String path, String contents, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -728,7 +728,7 @@ namespace System.IO { internal static void UnsafeWriteAllText(String path, String contents) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -788,11 +788,11 @@ namespace System.IO { public static void WriteAllBytes(String path, byte[] bytes) { if (path == null) - throw new ArgumentNullException("path", Environment.GetResourceString("ArgumentNull_Path")); + throw new ArgumentNullException(nameof(path), Environment.GetResourceString("ArgumentNull_Path")); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); if (bytes == null) - throw new ArgumentNullException("bytes"); + throw new ArgumentNullException(nameof(bytes)); Contract.EndContractBlock(); InternalWriteAllBytes(path, bytes, true); @@ -802,11 +802,11 @@ namespace System.IO { internal static void UnsafeWriteAllBytes(String path, byte[] bytes) { if (path == null) - throw new ArgumentNullException("path", Environment.GetResourceString("ArgumentNull_Path")); + throw new ArgumentNullException(nameof(path), Environment.GetResourceString("ArgumentNull_Path")); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); if (bytes == null) - throw new ArgumentNullException("bytes"); + throw new ArgumentNullException(nameof(bytes)); Contract.EndContractBlock(); InternalWriteAllBytes(path, bytes, false); @@ -829,7 +829,7 @@ namespace System.IO { public static String[] ReadAllLines(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -840,9 +840,9 @@ namespace System.IO { public static String[] ReadAllLines(String path, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -869,9 +869,9 @@ namespace System.IO { public static IEnumerable<String> ReadLines(String path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), "path"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), nameof(path)); Contract.EndContractBlock(); return ReadLinesIterator.CreateIterator(path, Encoding.UTF8); @@ -880,11 +880,11 @@ namespace System.IO { public static IEnumerable<String> ReadLines(String path, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), "path"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), nameof(path)); Contract.EndContractBlock(); return ReadLinesIterator.CreateIterator(path, encoding); @@ -893,9 +893,9 @@ namespace System.IO { public static void WriteAllLines(String path, String[] contents) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (contents == null) - throw new ArgumentNullException("contents"); + throw new ArgumentNullException(nameof(contents)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -906,11 +906,11 @@ namespace System.IO { public static void WriteAllLines(String path, String[] contents, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (contents == null) - throw new ArgumentNullException("contents"); + throw new ArgumentNullException(nameof(contents)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -921,9 +921,9 @@ namespace System.IO { public static void WriteAllLines(String path, IEnumerable<String> contents) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (contents == null) - throw new ArgumentNullException("contents"); + throw new ArgumentNullException(nameof(contents)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -934,11 +934,11 @@ namespace System.IO { public static void WriteAllLines(String path, IEnumerable<String> contents, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (contents == null) - throw new ArgumentNullException("contents"); + throw new ArgumentNullException(nameof(contents)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -963,7 +963,7 @@ namespace System.IO { public static void AppendAllText(String path, String contents) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -974,9 +974,9 @@ namespace System.IO { public static void AppendAllText(String path, String contents, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -997,9 +997,9 @@ namespace System.IO { public static void AppendAllLines(String path, IEnumerable<String> contents) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (contents == null) - throw new ArgumentNullException("contents"); + throw new ArgumentNullException(nameof(contents)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -1010,11 +1010,11 @@ namespace System.IO { public static void AppendAllLines(String path, IEnumerable<String> contents, Encoding encoding) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (contents == null) - throw new ArgumentNullException("contents"); + throw new ArgumentNullException(nameof(contents)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -1043,13 +1043,13 @@ namespace System.IO { [System.Security.SecurityCritical] private static void InternalMove(String sourceFileName, String destFileName, bool checkHost) { if (sourceFileName == null) - throw new ArgumentNullException("sourceFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(sourceFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (destFileName == null) - throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (sourceFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "sourceFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(sourceFileName)); if (destFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); String fullSourceFileName = Path.GetFullPathInternal(sourceFileName); @@ -1080,9 +1080,9 @@ namespace System.IO { public static void Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName) { if (sourceFileName == null) - throw new ArgumentNullException("sourceFileName"); + throw new ArgumentNullException(nameof(sourceFileName)); if (destinationFileName == null) - throw new ArgumentNullException("destinationFileName"); + throw new ArgumentNullException(nameof(destinationFileName)); Contract.EndContractBlock(); InternalReplace(sourceFileName, destinationFileName, destinationBackupFileName, false); @@ -1091,9 +1091,9 @@ namespace System.IO { public static void Replace(String sourceFileName, String destinationFileName, String destinationBackupFileName, bool ignoreMetadataErrors) { if (sourceFileName == null) - throw new ArgumentNullException("sourceFileName"); + throw new ArgumentNullException(nameof(sourceFileName)); if (destinationFileName == null) - throw new ArgumentNullException("destinationFileName"); + throw new ArgumentNullException(nameof(destinationFileName)); Contract.EndContractBlock(); InternalReplace(sourceFileName, destinationFileName, destinationBackupFileName, ignoreMetadataErrors); diff --git a/src/mscorlib/src/System/IO/FileInfo.cs b/src/mscorlib/src/System/IO/FileInfo.cs index 3ab1a5122e..d9f57532cb 100644 --- a/src/mscorlib/src/System/IO/FileInfo.cs +++ b/src/mscorlib/src/System/IO/FileInfo.cs @@ -50,7 +50,7 @@ namespace System.IO { public static FileInfo UnsafeCreateFileInfo(String fileName) { if (fileName == null) - throw new ArgumentNullException("fileName"); + throw new ArgumentNullException(nameof(fileName)); Contract.EndContractBlock(); FileInfo fi = new FileInfo(); @@ -63,7 +63,7 @@ namespace System.IO { public FileInfo(String fileName) { if (fileName == null) - throw new ArgumentNullException("fileName"); + throw new ArgumentNullException(nameof(fileName)); Contract.EndContractBlock(); Init(fileName, true); @@ -232,9 +232,9 @@ namespace System.IO { // public FileInfo CopyTo(String destFileName) { if (destFileName == null) - throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (destFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); destFileName = File.InternalCopy(FullPath, destFileName, false, true); @@ -253,9 +253,9 @@ namespace System.IO { // public FileInfo CopyTo(String destFileName, bool overwrite) { if (destFileName == null) - throw new ArgumentNullException("destFileName", Environment.GetResourceString("ArgumentNull_FileName")); + throw new ArgumentNullException(nameof(destFileName), Environment.GetResourceString("ArgumentNull_FileName")); if (destFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); destFileName = File.InternalCopy(FullPath, destFileName, overwrite, true); @@ -383,9 +383,9 @@ namespace System.IO { [System.Security.SecuritySafeCritical] public void MoveTo(String destFileName) { if (destFileName==null) - throw new ArgumentNullException("destFileName"); + throw new ArgumentNullException(nameof(destFileName)); if (destFileName.Length==0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "destFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(destFileName)); Contract.EndContractBlock(); String fullDestFileName = Path.GetFullPathInternal(destFileName); diff --git a/src/mscorlib/src/System/IO/FileSecurityState.cs b/src/mscorlib/src/System/IO/FileSecurityState.cs index 249848ac02..a3fa1fb460 100644 --- a/src/mscorlib/src/System/IO/FileSecurityState.cs +++ b/src/mscorlib/src/System/IO/FileSecurityState.cs @@ -44,7 +44,7 @@ namespace System.IO { if (path == null) { - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); } VerifyAccess(access); m_access = access; @@ -112,7 +112,7 @@ namespace System.IO private static void VerifyAccess(FileSecurityStateAccess access) { if ((access & ~FileSecurityStateAccess.AllAccess) != 0) - throw new ArgumentOutOfRangeException("access", Environment.GetResourceString("Arg_EnumIllegalVal")); + throw new ArgumentOutOfRangeException(nameof(access), Environment.GetResourceString("Arg_EnumIllegalVal")); } private static void VerifyPath(String path) diff --git a/src/mscorlib/src/System/IO/FileStream.cs b/src/mscorlib/src/System/IO/FileStream.cs index deef30c480..173917fff9 100644 --- a/src/mscorlib/src/System/IO/FileStream.cs +++ b/src/mscorlib/src/System/IO/FileStream.cs @@ -516,7 +516,7 @@ namespace System.IO { private void Init(String path, FileMode mode, FileAccess access, int rights, bool useRights, FileShare share, int bufferSize, FileOptions options, Win32Native.SECURITY_ATTRIBUTES secAttrs, String msgPath, bool bFromProxy, bool useLongPath, bool checkHost) { if (path == null) - throw new ArgumentNullException("path", Environment.GetResourceString("ArgumentNull_Path")); + throw new ArgumentNullException(nameof(path), Environment.GetResourceString("ArgumentNull_Path")); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); Contract.EndContractBlock(); @@ -549,10 +549,10 @@ namespace System.IO { // NOTE: any change to FileOptions enum needs to be matched here in the error validation if (options != FileOptions.None && (options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose | FileOptions.SequentialScan | FileOptions.Encrypted | (FileOptions)0x20000000 /* NoBuffering */)) != 0) - throw new ArgumentOutOfRangeException("options", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(options), Environment.GetResourceString("ArgumentOutOfRange_Enum")); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); // Write access validation #if FEATURE_MACL @@ -889,7 +889,7 @@ namespace System.IO { public FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) { // To ensure we don't leak a handle, put it in a SafeFileHandle first if (handle.IsInvalid) - throw new ArgumentException(Environment.GetResourceString("Arg_InvalidHandle"), "handle"); + throw new ArgumentException(Environment.GetResourceString("Arg_InvalidHandle"), nameof(handle)); Contract.EndContractBlock(); _handle = handle; @@ -897,9 +897,9 @@ namespace System.IO { // Now validate arguments. if (access < FileAccess.Read || access > FileAccess.ReadWrite) - throw new ArgumentOutOfRangeException("access", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(access), Environment.GetResourceString("ArgumentOutOfRange_Enum")); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); int handleType = Win32Native.GetFileType(_handle); Contract.Assert(handleType == Win32Native.FILE_TYPE_DISK || handleType == Win32Native.FILE_TYPE_PIPE || handleType == Win32Native.FILE_TYPE_CHAR, "FileStream was passed an unknown file type!"); @@ -1112,7 +1112,7 @@ namespace System.IO { return _pos + (_readPos - _readLen + _writePos); } set { - if (value < 0) throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + if (value < 0) throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (_writePos > 0) FlushWrite(false); _readPos = 0; @@ -1133,7 +1133,7 @@ namespace System.IO { public void SetAccessControl(FileSecurity fileSecurity) { if (fileSecurity == null) - throw new ArgumentNullException("fileSecurity"); + throw new ArgumentNullException(nameof(fileSecurity)); Contract.EndContractBlock(); if (_handle.IsClosed) __Error.FileNotOpen(); @@ -1313,7 +1313,7 @@ namespace System.IO { public override void SetLength(long value) { if (value < 0) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (_handle.IsClosed) __Error.FileNotOpen(); @@ -1351,7 +1351,7 @@ namespace System.IO { if (!Win32Native.SetEndOfFile(_handle)) { int hr = Marshal.GetLastWin32Error(); if (hr==__Error.ERROR_INVALID_PARAMETER) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_FileLengthTooBig")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_FileLengthTooBig")); __Error.WinIOError(hr, String.Empty); } // Return file pointer to where it was before setting length @@ -1366,11 +1366,11 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated public override int Read([In, Out] byte[] array, int offset, int count) { if (array==null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(array), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -1619,11 +1619,11 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated public override void Write(byte[] array, int offset, int count) { if (array==null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(array), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -1735,11 +1735,11 @@ namespace System.IO { public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, Object stateObject) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (numBytes < 0) - throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - offset < numBytes) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -1973,7 +1973,7 @@ namespace System.IO { // on our FileStreamAsyncResult. One is from BeginReadCore, // while the other is from the BeginRead buffering wrapper. if (asyncResult==null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.EndContractBlock(); if (!_isAsync) @@ -2031,11 +2031,11 @@ namespace System.IO { public override IAsyncResult BeginWrite(byte[] array, int offset, int numBytes, AsyncCallback userCallback, Object stateObject) { if (array==null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (numBytes < 0) - throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - offset < numBytes) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -2202,7 +2202,7 @@ namespace System.IO { public unsafe override void EndWrite(IAsyncResult asyncResult) { if (asyncResult==null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.EndContractBlock(); if (!_isAsync) { @@ -2427,11 +2427,11 @@ namespace System.IO { public override Task<int> ReadAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -2479,11 +2479,11 @@ namespace System.IO { public override Task WriteAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/IO/FileSystemInfo.cs b/src/mscorlib/src/System/IO/FileSystemInfo.cs index 2cd98b1b53..eaf559ba74 100644 --- a/src/mscorlib/src/System/IO/FileSystemInfo.cs +++ b/src/mscorlib/src/System/IO/FileSystemInfo.cs @@ -61,7 +61,7 @@ namespace System.IO { protected FileSystemInfo(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Must use V1 field names here, since V1 didn't implement diff --git a/src/mscorlib/src/System/IO/MemoryStream.cs b/src/mscorlib/src/System/IO/MemoryStream.cs index fa3b763ddb..137c8a6f1c 100644 --- a/src/mscorlib/src/System/IO/MemoryStream.cs +++ b/src/mscorlib/src/System/IO/MemoryStream.cs @@ -61,7 +61,7 @@ namespace System.IO { public MemoryStream(int capacity) { if (capacity < 0) { - throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); } Contract.EndContractBlock(); @@ -79,7 +79,7 @@ namespace System.IO { } public MemoryStream(byte[] buffer, bool writable) { - if (buffer == null) throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + if (buffer == null) throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); Contract.EndContractBlock(); _buffer = buffer; _length = _capacity = buffer.Length; @@ -99,11 +99,11 @@ namespace System.IO { public MemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -276,7 +276,7 @@ namespace System.IO { set { // Only update the capacity if the MS is expandable and the value is different than the current capacity. // Special behavior if the MS isn't expandable: we don't throw if value is the same as the current capacity - if (value < Length) throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + if (value < Length) throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); Contract.Ensures(_capacity - _origin == value); Contract.EndContractBlock(); @@ -312,25 +312,25 @@ namespace System.IO { } set { if (value < 0) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.Ensures(Position == value); Contract.EndContractBlock(); if (!_isOpen) __Error.StreamIsClosed(); if (value > MemStreamMaxLength) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); _position = _origin + (int)value; } } public override int Read([In, Out] byte[] buffer, int offset, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -362,11 +362,11 @@ namespace System.IO { public override Task<int> ReadAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); // contract validation copied from Read(...) @@ -477,7 +477,7 @@ namespace System.IO { if (!_isOpen) __Error.StreamIsClosed(); if (offset > MemStreamMaxLength) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); switch(loc) { case SeekOrigin.Begin: { int tempPosition = unchecked(_origin + (int)offset); @@ -520,7 +520,7 @@ namespace System.IO { // public override void SetLength(long value) { if (value < 0 || value > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); } Contract.Ensures(_length - _origin == value); Contract.EndContractBlock(); @@ -529,7 +529,7 @@ namespace System.IO { // Origin wasn't publicly exposed above. Contract.Assert(MemStreamMaxLength == Int32.MaxValue); // Check parameter validation logic in this method if this fails. if (value > (Int32.MaxValue - _origin)) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); } int newLength = _origin + (int)value; @@ -550,11 +550,11 @@ namespace System.IO { public override void Write(byte[] buffer, int offset, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -595,11 +595,11 @@ namespace System.IO { public override Task WriteAsync(Byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); // contract validation copied from Write(...) @@ -646,7 +646,7 @@ namespace System.IO { // Writes this MemoryStream to another stream. public virtual void WriteTo(Stream stream) { if (stream==null) - throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream")); + throw new ArgumentNullException(nameof(stream), Environment.GetResourceString("ArgumentNull_Stream")); Contract.EndContractBlock(); if (!_isOpen) __Error.StreamIsClosed(); diff --git a/src/mscorlib/src/System/IO/Path.cs b/src/mscorlib/src/System/IO/Path.cs index 0a28d67b73..6670ad738b 100644 --- a/src/mscorlib/src/System/IO/Path.cs +++ b/src/mscorlib/src/System/IO/Path.cs @@ -358,7 +358,7 @@ namespace System.IO { internal static string GetFullPathInternal(string path) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); Contract.EndContractBlock(); string newPath = NormalizePath(path, fullCheck: true); @@ -1212,7 +1212,7 @@ namespace System.IO { public static String Combine(String path1, String path2) { if (path1==null || path2==null) - throw new ArgumentNullException((path1==null) ? "path1" : "path2"); + throw new ArgumentNullException((path1==null) ? nameof(path1) : nameof(path2)); Contract.EndContractBlock(); CheckInvalidPathChars(path1); CheckInvalidPathChars(path2); @@ -1222,7 +1222,7 @@ namespace System.IO { public static String Combine(String path1, String path2, String path3) { if (path1 == null || path2 == null || path3 == null) - throw new ArgumentNullException((path1 == null) ? "path1" : (path2 == null) ? "path2" : "path3"); + throw new ArgumentNullException((path1 == null) ? nameof(path1) : (path2 == null) ? nameof(path2) : nameof(path3)); Contract.EndContractBlock(); CheckInvalidPathChars(path1); CheckInvalidPathChars(path2); @@ -1233,7 +1233,7 @@ namespace System.IO { public static String Combine(String path1, String path2, String path3, String path4) { if (path1 == null || path2 == null || path3 == null || path4 == null) - throw new ArgumentNullException((path1 == null) ? "path1" : (path2 == null) ? "path2" : (path3 == null) ? "path3" : "path4"); + throw new ArgumentNullException((path1 == null) ? nameof(path1) : (path2 == null) ? nameof(path2) : (path3 == null) ? nameof(path3) : nameof(path4)); Contract.EndContractBlock(); CheckInvalidPathChars(path1); CheckInvalidPathChars(path2); @@ -1245,7 +1245,7 @@ namespace System.IO { public static String Combine(params String[] paths) { if (paths == null) { - throw new ArgumentNullException("paths"); + throw new ArgumentNullException(nameof(paths)); } Contract.EndContractBlock(); @@ -1257,7 +1257,7 @@ namespace System.IO { for (int i = 0; i < paths.Length; i++) { if (paths[i] == null) { - throw new ArgumentNullException("paths"); + throw new ArgumentNullException(nameof(paths)); } if (paths[i].Length == 0) { @@ -1404,7 +1404,7 @@ namespace System.IO { internal static void CheckInvalidPathChars(String path, bool checkAdditional = false) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (PathInternal.HasIllegalCharacters(path, checkAdditional)) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPathChars")); @@ -1412,15 +1412,15 @@ namespace System.IO { internal static String InternalCombine(String path1, String path2) { if (path1==null || path2==null) - throw new ArgumentNullException((path1==null) ? "path1" : "path2"); + throw new ArgumentNullException((path1==null) ? nameof(path1) : nameof(path2)); Contract.EndContractBlock(); CheckInvalidPathChars(path1); CheckInvalidPathChars(path2); if (path2.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"), "path2"); + throw new ArgumentException(Environment.GetResourceString("Argument_PathEmpty"), nameof(path2)); if (IsPathRooted(path2)) - throw new ArgumentException(Environment.GetResourceString("Arg_Path2IsRooted"), "path2"); + throw new ArgumentException(Environment.GetResourceString("Arg_Path2IsRooted"), nameof(path2)); int i = path1.Length; if (i == 0) return path2; char ch = path1[i - 1]; diff --git a/src/mscorlib/src/System/IO/Stream.cs b/src/mscorlib/src/System/IO/Stream.cs index 745b970472..4b52e87769 100644 --- a/src/mscorlib/src/System/IO/Stream.cs +++ b/src/mscorlib/src/System/IO/Stream.cs @@ -401,7 +401,7 @@ namespace System.IO { public virtual int EndRead(IAsyncResult asyncResult) { if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.Ensures(Contract.Result<int>() >= 0); Contract.EndContractBlock(); @@ -593,7 +593,7 @@ namespace System.IO { public virtual void EndWrite(IAsyncResult asyncResult) { if (asyncResult==null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.EndContractBlock(); var writeTask = _activeReadWriteTask; @@ -817,7 +817,7 @@ namespace System.IO { public static Stream Synchronized(Stream stream) { if (stream==null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); Contract.Ensures(Contract.Result<Stream>() != null); Contract.EndContractBlock(); if (stream is SyncStream) @@ -970,7 +970,7 @@ namespace System.IO { public override int EndRead(IAsyncResult asyncResult) { if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.EndContractBlock(); return BlockingEndRead(asyncResult); @@ -987,7 +987,7 @@ namespace System.IO { public override void EndWrite(IAsyncResult asyncResult) { if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.EndContractBlock(); BlockingEndWrite(asyncResult); @@ -1133,7 +1133,7 @@ namespace System.IO { internal SyncStream(Stream stream) { if (stream == null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); Contract.EndContractBlock(); _stream = stream; } @@ -1270,7 +1270,7 @@ namespace System.IO { public override int EndRead(IAsyncResult asyncResult) { if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.Ensures(Contract.Result<int>() >= 0); Contract.EndContractBlock(); @@ -1324,7 +1324,7 @@ namespace System.IO { public override void EndWrite(IAsyncResult asyncResult) { if (asyncResult == null) - throw new ArgumentNullException("asyncResult"); + throw new ArgumentNullException(nameof(asyncResult)); Contract.EndContractBlock(); lock(_stream) diff --git a/src/mscorlib/src/System/IO/StreamReader.cs b/src/mscorlib/src/System/IO/StreamReader.cs index 549733bb47..468ca93f8b 100644 --- a/src/mscorlib/src/System/IO/StreamReader.cs +++ b/src/mscorlib/src/System/IO/StreamReader.cs @@ -161,11 +161,11 @@ namespace System.IO public StreamReader(Stream stream, Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize, bool leaveOpen) { if (stream == null || encoding == null) - throw new ArgumentNullException((stream == null ? "stream" : "encoding")); + throw new ArgumentNullException((stream == null ? nameof(stream) : nameof(encoding))); if (!stream.CanRead) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); Contract.EndContractBlock(); Init(stream, encoding, detectEncodingFromByteOrderMarks, bufferSize, leaveOpen); @@ -199,11 +199,11 @@ namespace System.IO // or we'll create a FileStream on disk and we won't close it until // the finalizer runs, causing problems for applications. if (path==null || encoding==null) - throw new ArgumentNullException((path==null ? "path" : "encoding")); + throw new ArgumentNullException((path==null ? nameof(path) : nameof(encoding))); if (path.Length==0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); Contract.EndContractBlock(); Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultFileStreamBufferSize, FileOptions.SequentialScan, Path.GetFileName(path), false, false, checkHost); @@ -358,7 +358,7 @@ namespace System.IO public override int Read([In, Out] char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) @@ -416,7 +416,7 @@ namespace System.IO public override int ReadBlock([In, Out] char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) @@ -898,7 +898,7 @@ namespace System.IO public override Task<int> ReadAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) @@ -1086,7 +1086,7 @@ namespace System.IO public override Task<int> ReadBlockAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) diff --git a/src/mscorlib/src/System/IO/StreamWriter.cs b/src/mscorlib/src/System/IO/StreamWriter.cs index 65613bb0a6..a399dc86ea 100644 --- a/src/mscorlib/src/System/IO/StreamWriter.cs +++ b/src/mscorlib/src/System/IO/StreamWriter.cs @@ -133,10 +133,10 @@ namespace System.IO : base(null) // Ask for CurrentCulture all the time { if (stream == null || encoding == null) - throw new ArgumentNullException((stream == null ? "stream" : "encoding")); + throw new ArgumentNullException((stream == null ? nameof(stream) : nameof(encoding))); if (!stream.CanWrite) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotWritable")); - if (bufferSize <= 0) throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + if (bufferSize <= 0) throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); Contract.EndContractBlock(); Init(stream, encoding, bufferSize, leaveOpen); @@ -163,12 +163,12 @@ namespace System.IO : base(null) { // Ask for CurrentCulture all the time if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (encoding == null) - throw new ArgumentNullException("encoding"); + throw new ArgumentNullException(nameof(encoding)); if (path.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath")); - if (bufferSize <= 0) throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + if (bufferSize <= 0) throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); Contract.EndContractBlock(); Stream stream = CreateFile(path, append, checkHost); @@ -365,11 +365,11 @@ namespace System.IO public override void Write(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -566,11 +566,11 @@ namespace System.IO public override Task WriteAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -723,11 +723,11 @@ namespace System.IO public override Task WriteLineAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/IO/TextReader.cs b/src/mscorlib/src/System/IO/TextReader.cs index b8cacde0d6..7ba6c276e7 100644 --- a/src/mscorlib/src/System/IO/TextReader.cs +++ b/src/mscorlib/src/System/IO/TextReader.cs @@ -97,11 +97,11 @@ namespace System.IO { public virtual int Read([In, Out] char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.Ensures(Contract.Result<int>() >= 0); @@ -202,7 +202,7 @@ namespace System.IO { public virtual Task<int> ReadAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) @@ -233,7 +233,7 @@ namespace System.IO { public virtual Task<int> ReadBlockAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) @@ -267,7 +267,7 @@ namespace System.IO { public static TextReader Synchronized(TextReader reader) { if (reader==null) - throw new ArgumentNullException("reader"); + throw new ArgumentNullException(nameof(reader)); Contract.Ensures(Contract.Result<TextReader>() != null); Contract.EndContractBlock(); @@ -379,7 +379,7 @@ namespace System.IO { public override Task<int> ReadBlockAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) @@ -395,7 +395,7 @@ namespace System.IO { public override Task<int> ReadAsync(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0 || count < 0) throw new ArgumentOutOfRangeException((index < 0 ? "index" : "count"), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) diff --git a/src/mscorlib/src/System/IO/TextWriter.cs b/src/mscorlib/src/System/IO/TextWriter.cs index b9231067cc..de1bb0c29f 100644 --- a/src/mscorlib/src/System/IO/TextWriter.cs +++ b/src/mscorlib/src/System/IO/TextWriter.cs @@ -127,7 +127,7 @@ namespace System.IO { [HostProtection(Synchronization=true)] public static TextWriter Synchronized(TextWriter writer) { if (writer==null) - throw new ArgumentNullException("writer"); + throw new ArgumentNullException(nameof(writer)); Contract.Ensures(Contract.Result<TextWriter>() != null); Contract.EndContractBlock(); @@ -158,11 +158,11 @@ namespace System.IO { // public virtual void Write(char[] buffer, int index, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs index 12cb02594d..ef301cae24 100644 --- a/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs +++ b/src/mscorlib/src/System/IO/UnmanagedMemoryAccessor.cs @@ -62,19 +62,19 @@ namespace System.IO { #pragma warning restore 618 protected void Initialize(SafeBuffer buffer, Int64 offset, Int64 capacity, FileAccess access) { if (buffer == null) { - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); } if (offset < 0) { - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (capacity < 0) { - throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (buffer.ByteLength < (UInt64)(offset + capacity)) { throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndCapacityOutOfBounds")); } if (access < FileAccess.Read || access > FileAccess.ReadWrite) { - throw new ArgumentOutOfRangeException("access"); + throw new ArgumentOutOfRangeException(nameof(access)); } Contract.EndContractBlock(); @@ -591,7 +591,7 @@ namespace System.IO { [System.Security.SecurityCritical] // auto-generated_required public void Read<T>(Int64 position, out T structure) where T : struct { if (position < 0) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -605,10 +605,10 @@ namespace System.IO { UInt32 sizeOfT = Marshal.SizeOfType(typeof(T)); if (position > _capacity - sizeOfT) { if (position >= _capacity) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToRead", typeof(T).FullName), "position"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToRead", typeof(T).FullName), nameof(position)); } } @@ -624,13 +624,13 @@ namespace System.IO { [System.Security.SecurityCritical] // auto-generated_required public int ReadArray<T>(Int64 position, T[] array, Int32 offset, Int32 count) where T : struct { if (array == null) { - throw new ArgumentNullException("array", "Buffer cannot be null."); + throw new ArgumentNullException(nameof(array), "Buffer cannot be null."); } if (offset < 0) { - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (array.Length - offset < count) { throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndLengthOutOfBounds")); @@ -645,14 +645,14 @@ namespace System.IO { } } if (position < 0) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } UInt32 sizeOfT = Marshal.AlignedSizeOf<T>(); // only check position and ask for fewer Ts if count is too big if (position >= _capacity) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); } int n = count; @@ -1106,7 +1106,7 @@ namespace System.IO { [System.Security.SecurityCritical] // auto-generated_required public void Write<T>(Int64 position, ref T structure) where T : struct { if (position < 0) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -1120,10 +1120,10 @@ namespace System.IO { UInt32 sizeOfT = Marshal.SizeOfType(typeof(T)); if (position > _capacity - sizeOfT) { if (position >= _capacity) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", typeof(T).FullName), "position"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", typeof(T).FullName), nameof(position)); } } @@ -1136,22 +1136,22 @@ namespace System.IO { [System.Security.SecurityCritical] // auto-generated_required public void WriteArray<T>(Int64 position, T[] array, Int32 offset, Int32 count) where T : struct { if (array == null) { - throw new ArgumentNullException("array", "Buffer cannot be null."); + throw new ArgumentNullException(nameof(array), "Buffer cannot be null."); } if (offset < 0) { - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (array.Length - offset < count) { throw new ArgumentException(Environment.GetResourceString("Argument_OffsetAndLengthOutOfBounds")); } if (position < 0) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (position >= Capacity) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); } Contract.EndContractBlock(); @@ -1217,15 +1217,15 @@ namespace System.IO { throw new NotSupportedException(Environment.GetResourceString("NotSupported_Reading")); } if (position < 0) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); if (position > _capacity - sizeOfType) { if (position >= _capacity) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToRead"), "position"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToRead"), nameof(position)); } } } @@ -1238,15 +1238,15 @@ namespace System.IO { throw new NotSupportedException(Environment.GetResourceString("NotSupported_Writing")); } if (position < 0) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); if (position > _capacity - sizeOfType) { if (position >= _capacity) { - throw new ArgumentOutOfRangeException("position", Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); + throw new ArgumentOutOfRangeException(nameof(position), Environment.GetResourceString("ArgumentOutOfRange_PositionLessThanCapacityRequired")); } else { - throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", "Byte"), "position"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotEnoughBytesToWrite", nameof(Byte)), nameof(position)); } } } diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs index df4df3b2ec..4a4f140aaa 100644 --- a/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs +++ b/src/mscorlib/src/System/IO/UnmanagedMemoryStream.cs @@ -135,19 +135,19 @@ namespace System.IO { [System.Security.SecurityCritical] // auto-generated internal void Initialize(SafeBuffer buffer, long offset, long length, FileAccess access, bool skipSecurityCheck) { if (buffer == null) { - throw new ArgumentNullException("buffer"); + throw new ArgumentNullException(nameof(buffer)); } if (offset < 0) { - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (buffer.ByteLength < (ulong)(offset + length)) { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSafeBufferOffLen")); } if (access < FileAccess.Read || access > FileAccess.ReadWrite) { - throw new ArgumentOutOfRangeException("access"); + throw new ArgumentOutOfRangeException(nameof(access)); } Contract.EndContractBlock(); @@ -219,17 +219,17 @@ namespace System.IO { internal unsafe void Initialize(byte* pointer, long length, long capacity, FileAccess access, bool skipSecurityCheck) { if (pointer == null) - throw new ArgumentNullException("pointer"); + throw new ArgumentNullException(nameof(pointer)); if (length < 0 || capacity < 0) throw new ArgumentOutOfRangeException((length < 0) ? "length" : "capacity", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (length > capacity) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_LengthGreaterThanCapacity")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_LengthGreaterThanCapacity")); Contract.EndContractBlock(); // Check for wraparound. if (((byte*) ((long)pointer + capacity)) < pointer) - throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamWrapAround")); + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamWrapAround")); if (access < FileAccess.Read || access > FileAccess.ReadWrite) - throw new ArgumentOutOfRangeException("access", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(access), Environment.GetResourceString("ArgumentOutOfRange_Enum")); if (_isOpen) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CalledTwice")); @@ -320,7 +320,7 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated set { if (value < 0) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (!CanSeek) __Error.StreamIsClosed(); @@ -328,7 +328,7 @@ namespace System.IO { unsafe { // On 32 bit machines, ensure we don't wrap around. if (value > (long) Int32.MaxValue || _mem + value < _mem) - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_StreamLength")); } #endif Interlocked.Exchange(ref _position, value); @@ -381,11 +381,11 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated public override int Read([In, Out] byte[] buffer, int offset, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); // Keep this in sync with contract validation in ReadAsync @@ -444,11 +444,11 @@ namespace System.IO { [ComVisible(false)] public override Task<Int32> ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); // contract validation copied from Read(...) @@ -506,7 +506,7 @@ namespace System.IO { public override long Seek(long offset, SeekOrigin loc) { if (!_isOpen) __Error.StreamIsClosed(); if (offset > UnmanagedMemStreamMaxLength) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamLength")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_UnmanagedMemStreamLength")); switch(loc) { case SeekOrigin.Begin: if (offset < 0) @@ -540,7 +540,7 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated public override void SetLength(long value) { if (value < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); if (_buffer != null) throw new NotSupportedException(Environment.GetResourceString("NotSupported_UmsSafeBuffer")); @@ -566,11 +566,11 @@ namespace System.IO { [System.Security.SecuritySafeCritical] // auto-generated public override void Write(byte[] buffer, int offset, int count) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); // Keep contract validation in sync with WriteAsync(..) @@ -646,11 +646,11 @@ namespace System.IO { public override Task WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) { if (buffer==null) - throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(buffer), Environment.GetResourceString("ArgumentNull_Buffer")); if (offset < 0) - throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(offset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (buffer.Length - offset < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); // contract validation copied from Write(..) diff --git a/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs b/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs index 5727eeddf5..81d8e56477 100644 --- a/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs +++ b/src/mscorlib/src/System/IO/UnmanagedMemoryStreamWrapper.cs @@ -127,7 +127,7 @@ namespace System.IO { // Writes this MemoryStream to another stream. public unsafe override void WriteTo(Stream stream) { if (stream==null) - throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream")); + throw new ArgumentNullException(nameof(stream), Environment.GetResourceString("ArgumentNull_Stream")); Contract.EndContractBlock(); if (!_unmanagedStream._isOpen) __Error.StreamIsClosed(); @@ -151,10 +151,10 @@ namespace System.IO { // The parameter checks must be in sync with the base version: if (destination == null) - throw new ArgumentNullException("destination"); + throw new ArgumentNullException(nameof(destination)); if (bufferSize <= 0) - throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(bufferSize), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); if (!CanRead && !CanWrite) throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed")); diff --git a/src/mscorlib/src/System/IntPtr.cs b/src/mscorlib/src/System/IntPtr.cs index c7eea36447..b7674afa90 100644 --- a/src/mscorlib/src/System/IntPtr.cs +++ b/src/mscorlib/src/System/IntPtr.cs @@ -87,7 +87,7 @@ namespace System { [System.Security.SecurityCritical] unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); #if BIT64 diff --git a/src/mscorlib/src/System/Lazy.cs b/src/mscorlib/src/System/Lazy.cs index 883979ef56..07863d1113 100644 --- a/src/mscorlib/src/System/Lazy.cs +++ b/src/mscorlib/src/System/Lazy.cs @@ -207,7 +207,7 @@ namespace System public Lazy(Func<T> valueFactory, LazyThreadSafetyMode mode) { if (valueFactory == null) - throw new ArgumentNullException("valueFactory"); + throw new ArgumentNullException(nameof(valueFactory)); m_threadSafeObj = GetObjectFromMode(mode); m_valueFactory = valueFactory; @@ -223,7 +223,7 @@ namespace System else if (mode == LazyThreadSafetyMode.PublicationOnly) return LazyHelpers.PUBLICATION_ONLY_SENTINEL; else if (mode != LazyThreadSafetyMode.None) - throw new ArgumentOutOfRangeException("mode", Environment.GetResourceString("Lazy_ctor_ModeInvalid")); + throw new ArgumentOutOfRangeException(nameof(mode), Environment.GetResourceString("Lazy_ctor_ModeInvalid")); return null; // None mode } diff --git a/src/mscorlib/src/System/MarshalByRefObject.cs b/src/mscorlib/src/System/MarshalByRefObject.cs index 201aa75e91..8b6a843a2d 100644 --- a/src/mscorlib/src/System/MarshalByRefObject.cs +++ b/src/mscorlib/src/System/MarshalByRefObject.cs @@ -234,7 +234,7 @@ namespace System { internal static bool CanCastToXmlTypeHelper(RuntimeType castType, MarshalByRefObject o) { if (castType == null) - throw new ArgumentNullException("castType"); + throw new ArgumentNullException(nameof(castType)); Contract.EndContractBlock(); // MarshalByRefObject's can only be casted to MarshalByRefObject's or interfaces. diff --git a/src/mscorlib/src/System/Math.cs b/src/mscorlib/src/System/Math.cs index a0cd7277e8..cf2b0ee15c 100644 --- a/src/mscorlib/src/System/Math.cs +++ b/src/mscorlib/src/System/Math.cs @@ -118,7 +118,7 @@ namespace System { public static double Round(double value, int digits) { if ((digits < 0) || (digits > maxRoundingDigits)) - throw new ArgumentOutOfRangeException("digits", Environment.GetResourceString("ArgumentOutOfRange_RoundingDigits")); + throw new ArgumentOutOfRangeException(nameof(digits), Environment.GetResourceString("ArgumentOutOfRange_RoundingDigits")); Contract.EndContractBlock(); return InternalRound(value, digits, MidpointRounding.ToEven); } @@ -129,9 +129,9 @@ namespace System { public static double Round(double value, int digits, MidpointRounding mode) { if ((digits < 0) || (digits > maxRoundingDigits)) - throw new ArgumentOutOfRangeException("digits", Environment.GetResourceString("ArgumentOutOfRange_RoundingDigits")); + throw new ArgumentOutOfRangeException(nameof(digits), Environment.GetResourceString("ArgumentOutOfRange_RoundingDigits")); if (mode < MidpointRounding.ToEven || mode > MidpointRounding.AwayFromZero) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidEnumValue", mode, "MidpointRounding"), "mode"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidEnumValue", mode, nameof(MidpointRounding)), nameof(mode)); } Contract.EndContractBlock(); return InternalRound(value, digits, mode); diff --git a/src/mscorlib/src/System/MissingMemberException.cs b/src/mscorlib/src/System/MissingMemberException.cs index 30ce5b8fd0..07d516da4d 100644 --- a/src/mscorlib/src/System/MissingMemberException.cs +++ b/src/mscorlib/src/System/MissingMemberException.cs @@ -85,7 +85,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/NotFiniteNumberException.cs b/src/mscorlib/src/System/NotFiniteNumberException.cs index a3d455aac6..d108f920da 100644 --- a/src/mscorlib/src/System/NotFiniteNumberException.cs +++ b/src/mscorlib/src/System/NotFiniteNumberException.cs @@ -60,7 +60,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/Nullable.cs b/src/mscorlib/src/System/Nullable.cs index 2091e20af3..8a22c8e65c 100644 --- a/src/mscorlib/src/System/Nullable.cs +++ b/src/mscorlib/src/System/Nullable.cs @@ -130,7 +130,7 @@ namespace System // Otherwise, returns the underlying type of the Nullable type public static Type GetUnderlyingType(Type nullableType) { if((object)nullableType == null) { - throw new ArgumentNullException("nullableType"); + throw new ArgumentNullException(nameof(nullableType)); } Contract.EndContractBlock(); Type result = null; diff --git a/src/mscorlib/src/System/Number.cs b/src/mscorlib/src/System/Number.cs index 3c1215d418..52bb03eb09 100644 --- a/src/mscorlib/src/System/Number.cs +++ b/src/mscorlib/src/System/Number.cs @@ -652,7 +652,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated internal unsafe static Double ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes]; @@ -933,7 +933,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated internal unsafe static Single ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt) { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes]; @@ -1014,7 +1014,7 @@ namespace System { private unsafe static void StringToNumber(String str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, Boolean parseDecimal) { if (str == null) { - throw new ArgumentNullException("String"); + throw new ArgumentNullException(nameof(String)); } Contract.EndContractBlock(); Contract.Assert(info != null, ""); diff --git a/src/mscorlib/src/System/OperatingSystem.cs b/src/mscorlib/src/System/OperatingSystem.cs index 6955310acf..7bdb2f3dd3 100644 --- a/src/mscorlib/src/System/OperatingSystem.cs +++ b/src/mscorlib/src/System/OperatingSystem.cs @@ -38,11 +38,11 @@ namespace System { if( platform < PlatformID.Win32S || platform > PlatformID.MacOSX) { throw new ArgumentException( Environment.GetResourceString("Arg_EnumIllegalVal", (int)platform), - "platform"); + nameof(platform)); } if ((Object) version == null) - throw new ArgumentNullException("version"); + throw new ArgumentNullException(nameof(version)); Contract.EndContractBlock(); _platform = platform; @@ -74,7 +74,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public void GetObjectData(SerializationInfo info, StreamingContext context) { if( info == null ) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Progress.cs b/src/mscorlib/src/System/Progress.cs index 8800c0322a..a8b48fdfc8 100644 --- a/src/mscorlib/src/System/Progress.cs +++ b/src/mscorlib/src/System/Progress.cs @@ -63,7 +63,7 @@ namespace System /// <exception cref="System.ArgumentNullException">The <paramref name="handler"/> is null (Nothing in Visual Basic).</exception> public Progress(Action<T> handler) : this() { - if (handler == null) throw new ArgumentNullException("handler"); + if (handler == null) throw new ArgumentNullException(nameof(handler)); m_handler = handler; } diff --git a/src/mscorlib/src/System/Random.cs b/src/mscorlib/src/System/Random.cs index 4059b4cfde..e4880dc332 100644 --- a/src/mscorlib/src/System/Random.cs +++ b/src/mscorlib/src/System/Random.cs @@ -195,7 +195,7 @@ namespace System { ==============================================================================*/ public virtual int Next(int minValue, int maxValue) { if (minValue>maxValue) { - throw new ArgumentOutOfRangeException("minValue",Environment.GetResourceString("Argument_MinMaxValue", "minValue", "maxValue")); + throw new ArgumentOutOfRangeException(nameof(minValue),Environment.GetResourceString("Argument_MinMaxValue", "minValue", "maxValue")); } Contract.EndContractBlock(); @@ -216,7 +216,7 @@ namespace System { ==============================================================================*/ public virtual int Next(int maxValue) { if (maxValue<0) { - throw new ArgumentOutOfRangeException("maxValue", Environment.GetResourceString("ArgumentOutOfRange_MustBePositive", "maxValue")); + throw new ArgumentOutOfRangeException(nameof(maxValue), Environment.GetResourceString("ArgumentOutOfRange_MustBePositive", "maxValue")); } Contract.EndContractBlock(); return (int)(Sample()*maxValue); @@ -240,7 +240,7 @@ namespace System { **Exceptions: None ==============================================================================*/ public virtual void NextBytes(byte [] buffer){ - if (buffer==null) throw new ArgumentNullException("buffer"); + if (buffer==null) throw new ArgumentNullException(nameof(buffer)); Contract.EndContractBlock(); for (int i=0; i<buffer.Length; i++) { buffer[i]=(byte)(InternalSample()%(Byte.MaxValue+1)); diff --git a/src/mscorlib/src/System/Reflection/Assembly.cs b/src/mscorlib/src/System/Reflection/Assembly.cs index 36bf351a9a..4383c432b4 100644 --- a/src/mscorlib/src/System/Reflection/Assembly.cs +++ b/src/mscorlib/src/System/Reflection/Assembly.cs @@ -70,7 +70,7 @@ namespace System.Reflection public static Assembly GetAssembly(Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); Module m = type.Module; @@ -113,7 +113,7 @@ namespace System.Reflection public static Assembly LoadFrom(String assemblyFile) { if(assemblyFile == null) - throw new ArgumentNullException("assemblyFile"); + throw new ArgumentNullException(nameof(assemblyFile)); string fullPath = Path.GetFullPathInternal(assemblyFile); return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath); } @@ -405,7 +405,7 @@ namespace System.Reflection public static Assembly LoadWithPartialName(String partialName) { if(partialName == null) - throw new ArgumentNullException("partialName"); + throw new ArgumentNullException(nameof(partialName)); return Load(partialName); } @@ -483,7 +483,7 @@ namespace System.Reflection #if FEATURE_CORECLR if(rawAssembly == null) - throw new ArgumentNullException("rawAssembly"); + throw new ArgumentNullException(nameof(rawAssembly)); AssemblyLoadContext alc = new FileLoadAssemblyLoadContext(); MemoryStream assemblyStream = new MemoryStream(rawAssembly); MemoryStream symbolStream = (rawSymbolStore!=null)?new MemoryStream(rawSymbolStore):null; @@ -517,7 +517,7 @@ namespace System.Reflection if (securityContextSource < SecurityContextSource.CurrentAppDomain || securityContextSource > SecurityContextSource.CurrentAssembly) { - throw new ArgumentOutOfRangeException("securityContextSource"); + throw new ArgumentOutOfRangeException(nameof(securityContextSource)); } StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -582,11 +582,11 @@ namespace System.Reflection #if FEATURE_CORECLR Assembly result = null; if(path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (Path.IsRelative(path)) { - throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), "path"); + throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(path)); } string normalizedPath = Path.GetFullPathInternal(path); @@ -1473,7 +1473,7 @@ namespace System.Reflection { // throw on null strings regardless of the value of "throwOnError" if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); RuntimeType type = null; Object keepAlive = null; @@ -1605,7 +1605,7 @@ namespace System.Reflection public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); @@ -1633,13 +1633,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -1647,13 +1647,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"caType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -1674,7 +1674,7 @@ namespace System.Reflection ref StackCrawlMark stackMark) { if (assemblyFile == null) - throw new ArgumentNullException("assemblyFile"); + throw new ArgumentNullException(nameof(assemblyFile)); Contract.EndContractBlock(); @@ -1730,7 +1730,7 @@ namespace System.Reflection out RuntimeAssembly assemblyFromResolveEvent) { if (assemblyString == null) - throw new ArgumentNullException("assemblyString"); + throw new ArgumentNullException(nameof(assemblyString)); Contract.EndContractBlock(); if ((assemblyString.Length == 0) || @@ -1777,7 +1777,7 @@ namespace System.Reflection { if (assemblyRef == null) - throw new ArgumentNullException("assemblyRef"); + throw new ArgumentNullException(nameof(assemblyRef)); Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) @@ -2106,7 +2106,7 @@ namespace System.Reflection internal static RuntimeAssembly InternalLoadFromStream(Stream assemblyStream, Stream pdbStream, ref StackCrawlMark stackMark) { if (assemblyStream == null) - throw new ArgumentNullException("assemblyStream"); + throw new ArgumentNullException(nameof(assemblyStream)); if (assemblyStream.GetType()!=typeof(UnmanagedMemoryStream)) throw new NotSupportedException(); @@ -2413,7 +2413,7 @@ namespace System.Reflection StringBuilder sb = new StringBuilder(); if(type == null) { if (name == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } else { String nameSpace = type.Namespace; @@ -2777,7 +2777,7 @@ namespace System.Reflection ref StackCrawlMark stackMark) { if (culture == null) - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Reflection/AssemblyAttributes.cs b/src/mscorlib/src/System/Reflection/AssemblyAttributes.cs index 955255572b..b2e44b0034 100644 --- a/src/mscorlib/src/System/Reflection/AssemblyAttributes.cs +++ b/src/mscorlib/src/System/Reflection/AssemblyAttributes.cs @@ -190,7 +190,7 @@ namespace System.Reflection { public AssemblyFileVersionAttribute(String version) { if (version == null) - throw new ArgumentNullException("version"); + throw new ArgumentNullException(nameof(version)); Contract.EndContractBlock(); _version = version; } diff --git a/src/mscorlib/src/System/Reflection/AssemblyName.cs b/src/mscorlib/src/System/Reflection/AssemblyName.cs index 051f3b5f0e..4c3d5aa6d6 100644 --- a/src/mscorlib/src/System/Reflection/AssemblyName.cs +++ b/src/mscorlib/src/System/Reflection/AssemblyName.cs @@ -193,7 +193,7 @@ namespace System.Reflection { static public AssemblyName GetAssemblyName(String assemblyFile) { if(assemblyFile == null) - throw new ArgumentNullException("assemblyFile"); + throw new ArgumentNullException(nameof(assemblyFile)); Contract.EndContractBlock(); // Assembly.GetNameInternal() will not demand path discovery @@ -299,7 +299,7 @@ namespace System.Reflection { public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); //Allocate the serialization info and serialize our static data. @@ -364,7 +364,7 @@ namespace System.Reflection { public AssemblyName(String assemblyName) { if (assemblyName == null) - throw new ArgumentNullException("assemblyName"); + throw new ArgumentNullException(nameof(assemblyName)); Contract.EndContractBlock(); if ((assemblyName.Length == 0) || (assemblyName[0] == '\0')) diff --git a/src/mscorlib/src/System/Reflection/ConstructorInfo.cs b/src/mscorlib/src/System/Reflection/ConstructorInfo.cs index 7811244bbe..07b29d7eca 100644 --- a/src/mscorlib/src/System/Reflection/ConstructorInfo.cs +++ b/src/mscorlib/src/System/Reflection/ConstructorInfo.cs @@ -397,13 +397,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -412,13 +412,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -532,7 +532,7 @@ namespace System.Reflection internal static void CheckCanCreateInstance(Type declaringType, bool isVarArg) { if (declaringType == null) - throw new ArgumentNullException("declaringType"); + throw new ArgumentNullException(nameof(declaringType)); Contract.EndContractBlock(); // ctor is ReflectOnly @@ -765,7 +765,7 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); MemberInfoSerializationHolder.GetSerializationInfo( info, diff --git a/src/mscorlib/src/System/Reflection/CustomAttribute.cs b/src/mscorlib/src/System/Reflection/CustomAttribute.cs index 1a605acbcf..d830765aa7 100644 --- a/src/mscorlib/src/System/Reflection/CustomAttribute.cs +++ b/src/mscorlib/src/System/Reflection/CustomAttribute.cs @@ -29,7 +29,7 @@ namespace System.Reflection public static IList<CustomAttributeData> GetCustomAttributes(MemberInfo target) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); return target.GetCustomAttributesData(); } @@ -37,7 +37,7 @@ namespace System.Reflection public static IList<CustomAttributeData> GetCustomAttributes(Module target) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); Contract.EndContractBlock(); return target.GetCustomAttributesData(); @@ -46,7 +46,7 @@ namespace System.Reflection public static IList<CustomAttributeData> GetCustomAttributes(Assembly target) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); Contract.EndContractBlock(); return target.GetCustomAttributesData(); @@ -55,7 +55,7 @@ namespace System.Reflection public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo target) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); Contract.EndContractBlock(); return target.GetCustomAttributesData(); @@ -279,7 +279,7 @@ namespace System.Reflection if (type.IsValueType) return CustomAttributeEncoding.Undefined; - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidKindOfTypeForCA"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidKindOfTypeForCA"), nameof(type)); } private static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType) { @@ -611,7 +611,7 @@ namespace System.Reflection public CustomAttributeNamedArgument(MemberInfo memberInfo, object value) { if (memberInfo == null) - throw new ArgumentNullException("memberInfo"); + throw new ArgumentNullException(nameof(memberInfo)); Type type = null; FieldInfo field = memberInfo as FieldInfo; @@ -631,7 +631,7 @@ namespace System.Reflection public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument) { if (memberInfo == null) - throw new ArgumentNullException("memberInfo"); + throw new ArgumentNullException(nameof(memberInfo)); m_memberInfo = memberInfo; m_value = typedArgument; @@ -749,7 +749,7 @@ namespace System.Reflection return typeof(object); default : - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)encodedType), "encodedType"); + throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)encodedType), nameof(encodedType)); } } @@ -795,7 +795,7 @@ namespace System.Reflection unsafe { return *(double*)&val; } default: - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)val), "val"); + throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)val), nameof(val)); } } private static RuntimeType ResolveType(RuntimeModule scope, string typeName) @@ -820,7 +820,7 @@ namespace System.Reflection { // value can be null. if (argumentType == null) - throw new ArgumentNullException("argumentType"); + throw new ArgumentNullException(nameof(argumentType)); m_value = (value == null) ? null : CanonicalizeValue(value); m_argumentType = argumentType; @@ -830,7 +830,7 @@ namespace System.Reflection { // value cannot be null. if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); m_value = CanonicalizeValue(value); m_argumentType = value.GetType(); @@ -852,7 +852,7 @@ namespace System.Reflection CustomAttributeEncoding encodedType = encodedArg.CustomAttributeType.EncodedType; if (encodedType == CustomAttributeEncoding.Undefined) - throw new ArgumentException("encodedArg"); + throw new ArgumentException(null, nameof(encodedArg)); else if (encodedType == CustomAttributeEncoding.Enum) { @@ -1031,7 +1031,7 @@ namespace System.Reflection RuntimeModule customAttributeModule) { if (customAttributeModule == null) - throw new ArgumentNullException("customAttributeModule"); + throw new ArgumentNullException(nameof(customAttributeModule)); Contract.EndContractBlock(); Contract.Assert(customAttributeCtorParameters != null); @@ -1083,7 +1083,7 @@ namespace System.Reflection public CustomAttributeNamedParameter(string argumentName, CustomAttributeEncoding fieldOrProperty, CustomAttributeType type) { if (argumentName == null) - throw new ArgumentNullException("argumentName"); + throw new ArgumentNullException(nameof(argumentName)); Contract.EndContractBlock(); m_argumentName = argumentName; diff --git a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs index b9e35dc7a1..f798cda434 100644 --- a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -246,7 +246,7 @@ namespace System.Reflection.Emit if (m_manifestModuleBuilder.InternalModule == module) return m_manifestModuleBuilder; - throw new ArgumentException("module"); + throw new ArgumentException(null, nameof(module)); } } @@ -303,7 +303,7 @@ namespace System.Reflection.Emit SecurityContextSource securityContextSource) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (access != AssemblyBuilderAccess.Run #if !FEATURE_CORECLR @@ -318,13 +318,13 @@ namespace System.Reflection.Emit #endif // FEATURE_COLLECTIBLE_TYPES ) { - throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), "access"); + throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), nameof(access)); } if (securityContextSource < SecurityContextSource.CurrentAppDomain || securityContextSource > SecurityContextSource.CurrentAssembly) { - throw new ArgumentOutOfRangeException("securityContextSource"); + throw new ArgumentOutOfRangeException(nameof(securityContextSource)); } // Clone the name in case the caller modifies it underneath us. @@ -623,11 +623,11 @@ namespace System.Reflection.Emit ref StackCrawlMark stackMark) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (name[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), nameof(name)); Contract.Ensures(Contract.Result<ModuleBuilder>() != null); Contract.EndContractBlock(); @@ -832,18 +832,18 @@ namespace System.Reflection.Emit ref StackCrawlMark stackMark) // stack crawl mark used to find caller { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (name[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), nameof(name)); if (fileName == null) - throw new ArgumentNullException("fileName"); + throw new ArgumentNullException(nameof(fileName)); if (fileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "fileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(fileName)); if (!String.Equals(fileName, Path.GetFileName(fileName))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), nameof(fileName)); Contract.Ensures(Contract.Result<ModuleBuilder>() != null); Contract.EndContractBlock(); @@ -1008,15 +1008,15 @@ namespace System.Reflection.Emit ResourceAttributes attribute) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name); if (fileName == null) - throw new ArgumentNullException("fileName"); + throw new ArgumentNullException(nameof(fileName)); if (fileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "fileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(fileName)); if (!String.Equals(fileName, Path.GetFileName(fileName))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), nameof(fileName)); Contract.EndContractBlock(); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.DefineResource( " + name + ", " + fileName + ")"); @@ -1084,15 +1084,15 @@ namespace System.Reflection.Emit ResourceAttributes attribute) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name); if (fileName == null) - throw new ArgumentNullException("fileName"); + throw new ArgumentNullException(nameof(fileName)); if (fileName.Length == 0) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), fileName); if (!String.Equals(fileName, Path.GetFileName(fileName))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), nameof(fileName)); Contract.EndContractBlock(); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.AddResourceFile( " + name + ", " + fileName + ")"); @@ -1437,7 +1437,7 @@ namespace System.Reflection.Emit public void DefineUnmanagedResource(Byte[] resource) { if (resource == null) - throw new ArgumentNullException("resource"); + throw new ArgumentNullException(nameof(resource)); Contract.EndContractBlock(); lock(SyncRoot) @@ -1461,7 +1461,7 @@ namespace System.Reflection.Emit public void DefineUnmanagedResource(String resourceFileName) { if (resourceFileName == null) - throw new ArgumentNullException("resourceFileName"); + throw new ArgumentNullException(nameof(resourceFileName)); Contract.EndContractBlock(); lock(SyncRoot) @@ -1520,9 +1520,9 @@ namespace System.Reflection.Emit String name) // the name of module for the look up { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); Contract.EndContractBlock(); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.GetDynamicModule( " + name + " )"); @@ -1571,7 +1571,7 @@ namespace System.Reflection.Emit { if (entryMethod == null) - throw new ArgumentNullException("entryMethod"); + throw new ArgumentNullException(nameof(entryMethod)); Contract.EndContractBlock(); BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.SetEntryPoint"); @@ -1609,9 +1609,9 @@ namespace System.Reflection.Emit public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); lock(SyncRoot) @@ -1647,7 +1647,7 @@ namespace System.Reflection.Emit { if (customBuilder == null) { - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); } Contract.EndContractBlock(); @@ -1710,11 +1710,11 @@ namespace System.Reflection.Emit PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine) { if (assemblyFileName == null) - throw new ArgumentNullException("assemblyFileName"); + throw new ArgumentNullException(nameof(assemblyFileName)); if (assemblyFileName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "assemblyFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), nameof(assemblyFileName)); if (!String.Equals(assemblyFileName, Path.GetFileName(assemblyFileName))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "assemblyFileName"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), nameof(assemblyFileName)); Contract.EndContractBlock(); int i; diff --git a/src/mscorlib/src/System/Reflection/Emit/ConstructorBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/ConstructorBuilder.cs index e5062d3365..7bf3a673e1 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ConstructorBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ConstructorBuilder.cs @@ -223,7 +223,7 @@ namespace System.Reflection.Emit public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) - throw new ArgumentNullException("pset"); + throw new ArgumentNullException(nameof(pset)); #pragma warning disable 618 if (!Enum.IsDefined(typeof(SecurityAction), action) || @@ -231,7 +231,7 @@ namespace System.Reflection.Emit action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) { - throw new ArgumentOutOfRangeException("action"); + throw new ArgumentOutOfRangeException(nameof(action)); } #pragma warning restore 618 Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Reflection/Emit/CustomAttributeBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/CustomAttributeBuilder.cs index 81ad5f3439..3ef44a5571 100644 --- a/src/mscorlib/src/System/Reflection/Emit/CustomAttributeBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/CustomAttributeBuilder.cs @@ -109,17 +109,17 @@ namespace System.Reflection.Emit { FieldInfo[] namedFields, Object[] fieldValues) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (constructorArgs == null) - throw new ArgumentNullException("constructorArgs"); + throw new ArgumentNullException(nameof(constructorArgs)); if (namedProperties == null) - throw new ArgumentNullException("namedProperties"); + throw new ArgumentNullException(nameof(namedProperties)); if (propertyValues == null) - throw new ArgumentNullException("propertyValues"); + throw new ArgumentNullException(nameof(propertyValues)); if (namedFields == null) - throw new ArgumentNullException("namedFields"); + throw new ArgumentNullException(nameof(namedFields)); if (fieldValues == null) - throw new ArgumentNullException("fieldValues"); + throw new ArgumentNullException(nameof(fieldValues)); if (namedProperties.Length != propertyValues.Length) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayLengthsDiffer"), "namedProperties, propertyValues"); if (namedFields.Length != fieldValues.Length) diff --git a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs index a229f3f117..7a5c5a8967 100644 --- a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -61,7 +61,7 @@ namespace System.Reflection.Emit { LocalBuilder localBuilder; if (localType == null) - throw new ArgumentNullException("localType"); + throw new ArgumentNullException(nameof(localType)); Contract.EndContractBlock(); RuntimeType rtType = localType as RuntimeType; @@ -90,7 +90,7 @@ namespace System.Reflection.Emit public override void Emit(OpCode opcode, MethodInfo meth) { if (meth == null) - throw new ArgumentNullException("meth"); + throw new ArgumentNullException(nameof(meth)); Contract.EndContractBlock(); int stackchange = 0; @@ -100,7 +100,7 @@ namespace System.Reflection.Emit { RuntimeMethodInfo rtMeth = meth as RuntimeMethodInfo; if (rtMeth == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(meth)); RuntimeType declaringType = rtMeth.GetRuntimeType(); if (declaringType != null && (declaringType.IsGenericType || declaringType.IsArray)) @@ -147,12 +147,12 @@ namespace System.Reflection.Emit public override void Emit(OpCode opcode, ConstructorInfo con) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); Contract.EndContractBlock(); RuntimeConstructorInfo rtConstructor = con as RuntimeConstructorInfo; if (rtConstructor == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "con"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(con)); RuntimeType declaringType = rtConstructor.GetRuntimeType(); int token; @@ -175,7 +175,7 @@ namespace System.Reflection.Emit public override void Emit(OpCode opcode, Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); RuntimeType rtType = type as RuntimeType; @@ -192,12 +192,12 @@ namespace System.Reflection.Emit public override void Emit(OpCode opcode, FieldInfo field) { if (field == null) - throw new ArgumentNullException("field"); + throw new ArgumentNullException(nameof(field)); Contract.EndContractBlock(); RuntimeFieldInfo runtimeField = field as RuntimeFieldInfo; if (runtimeField == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), "field"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), nameof(field)); int token; if (field.DeclaringType == null) @@ -213,7 +213,7 @@ namespace System.Reflection.Emit public override void Emit(OpCode opcode, String str) { if (str == null) - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); Contract.EndContractBlock(); int tempVal = GetTokenForString(str); @@ -310,16 +310,16 @@ namespace System.Reflection.Emit public override void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes) { if (methodInfo == null) - throw new ArgumentNullException("methodInfo"); + throw new ArgumentNullException(nameof(methodInfo)); if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), "opcode"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), nameof(opcode)); if (methodInfo.ContainsGenericParameters) - throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "methodInfo"); + throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(methodInfo)); if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.ContainsGenericParameters) - throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "methodInfo"); + throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(methodInfo)); Contract.EndContractBlock(); int tk; @@ -350,7 +350,7 @@ namespace System.Reflection.Emit public override void Emit(OpCode opcode, SignatureHelper signature) { if (signature == null) - throw new ArgumentNullException("signature"); + throw new ArgumentNullException(nameof(signature)); Contract.EndContractBlock(); int stackchange = 0; @@ -420,7 +420,7 @@ namespace System.Reflection.Emit { // execute this branch if previous clause is Catch or Fault if (exceptionType == null) - throw new ArgumentNullException("exceptionType"); + throw new ArgumentNullException(nameof(exceptionType)); if (rtType == null) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); @@ -493,7 +493,7 @@ namespace System.Reflection.Emit DynamicMethod dm = methodInfo as DynamicMethod; if (rtMeth == null && dm == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "methodInfo"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(methodInfo)); ParameterInfo[] paramInfo = methodInfo.GetParametersNoCopy(); if (paramInfo != null && paramInfo.Length != 0) @@ -1068,10 +1068,10 @@ namespace System.Reflection.Emit public unsafe void SetCode(byte* code, int codeSize, int maxStackSize) { if (codeSize < 0) - throw new ArgumentOutOfRangeException("codeSize", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(codeSize), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if (codeSize > 0 && code == null) - throw new ArgumentNullException("code"); + throw new ArgumentNullException(nameof(code)); Contract.EndContractBlock(); m_code = new byte[codeSize]; @@ -1094,10 +1094,10 @@ namespace System.Reflection.Emit public unsafe void SetExceptions(byte* exceptions, int exceptionsSize) { if (exceptionsSize < 0) - throw new ArgumentOutOfRangeException("exceptionsSize", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(exceptionsSize), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if (exceptionsSize > 0 && exceptions == null) - throw new ArgumentNullException("exceptions"); + throw new ArgumentNullException(nameof(exceptions)); Contract.EndContractBlock(); m_exceptions = new byte[exceptionsSize]; @@ -1119,10 +1119,10 @@ namespace System.Reflection.Emit public unsafe void SetLocalSignature(byte* localSignature, int signatureSize) { if (signatureSize < 0) - throw new ArgumentOutOfRangeException("signatureSize", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(signatureSize), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); if (signatureSize > 0 && localSignature == null) - throw new ArgumentNullException("localSignature"); + throw new ArgumentNullException(nameof(localSignature)); Contract.EndContractBlock(); m_localSignature = new byte[signatureSize]; diff --git a/src/mscorlib/src/System/Reflection/Emit/DynamicMethod.cs b/src/mscorlib/src/System/Reflection/Emit/DynamicMethod.cs index 501d65e6a1..bb6af23e61 100644 --- a/src/mscorlib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/mscorlib/src/System/Reflection/Emit/DynamicMethod.cs @@ -419,7 +419,7 @@ namespace System.Reflection.Emit m_methodHandle = null; if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); #if FEATURE_APPX if (AppDomain.ProfileAPICheck) @@ -439,7 +439,7 @@ namespace System.Reflection.Emit private void PerformSecurityCheck(Module m, ref StackCrawlMark stackMark, bool skipVisibility) { if (m == null) - throw new ArgumentNullException("m"); + throw new ArgumentNullException(nameof(m)); Contract.EndContractBlock(); #if !FEATURE_CORECLR @@ -452,12 +452,12 @@ namespace System.Reflection.Emit if (rtModule == null) { - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeModule"), "m"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeModule"), nameof(m)); } // The user cannot explicitly use this assembly if (rtModule == s_anonymouslyHostedDynamicMethodsModule) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"), "m"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidValue"), nameof(m)); // ask for member access if skip visibility if (skipVisibility) @@ -485,7 +485,7 @@ namespace System.Reflection.Emit private void PerformSecurityCheck(Type owner, ref StackCrawlMark stackMark, bool skipVisibility) { if (owner == null) - throw new ArgumentNullException("owner"); + throw new ArgumentNullException(nameof(owner)); #if !FEATURE_CORECLR RuntimeType rtOwner = owner as RuntimeType; @@ -493,7 +493,7 @@ namespace System.Reflection.Emit rtOwner = owner.UnderlyingSystemType as RuntimeType; if (rtOwner == null) - throw new ArgumentNullException("owner", Environment.GetResourceString("Argument_MustBeRuntimeType")); + throw new ArgumentNullException(nameof(owner), Environment.GetResourceString("Argument_MustBeRuntimeType")); // get the type the call is coming from RuntimeType callingType = RuntimeMethodHandle.GetCallerType(ref stackMark); @@ -947,7 +947,7 @@ namespace System.Reflection.Emit public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); if (attributeType.IsAssignableFrom(typeof(MethodImplAttribute))) @@ -963,7 +963,7 @@ namespace System.Reflection.Emit public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); if (attributeType.IsAssignableFrom(typeof(MethodImplAttribute))) diff --git a/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs index f8e3ab2991..dfb0b15110 100644 --- a/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs @@ -407,7 +407,7 @@ namespace System.Reflection.Emit { { // Client should not set any bits other than the visibility bits. if ((visibility & ~TypeAttributes.VisibilityMask) != 0) - throw new ArgumentException(Environment.GetResourceString("Argument_ShouldOnlySetVisibilityFlags"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_ShouldOnlySetVisibilityFlags"), nameof(name)); m_typeBuilder = new TypeBuilder(name, visibility | TypeAttributes.Sealed, typeof(System.Enum), null, module, PackingSize.Unspecified, TypeBuilder.UnspecifiedTypeSize, null); // Define the underlying field for the enum. It will be a non-static, private field with special name bit set. diff --git a/src/mscorlib/src/System/Reflection/Emit/EventBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/EventBuilder.cs index 42a5252102..60289a1c98 100644 --- a/src/mscorlib/src/System/Reflection/Emit/EventBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/EventBuilder.cs @@ -63,7 +63,7 @@ namespace System.Reflection.Emit { { if (mdBuilder == null) { - throw new ArgumentNullException("mdBuilder"); + throw new ArgumentNullException(nameof(mdBuilder)); } Contract.EndContractBlock(); @@ -110,9 +110,9 @@ namespace System.Reflection.Emit { public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); m_type.ThrowIfCreated(); @@ -130,7 +130,7 @@ namespace System.Reflection.Emit { { if (customBuilder == null) { - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); } Contract.EndContractBlock(); m_type.ThrowIfCreated(); diff --git a/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs index 0f2de5be43..84449bdd3d 100644 --- a/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs @@ -34,16 +34,16 @@ namespace System.Reflection.Emit Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes) { if (fieldName == null) - throw new ArgumentNullException("fieldName"); + throw new ArgumentNullException(nameof(fieldName)); if (fieldName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "fieldName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(fieldName)); if (fieldName[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "fieldName"); + throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(fieldName)); if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (type == typeof(void)) throw new ArgumentException(Environment.GetResourceString("Argument_BadFieldType")); @@ -198,7 +198,7 @@ namespace System.Reflection.Emit public void SetMarshal(UnmanagedMarshal unmanagedMarshal) { if (unmanagedMarshal == null) - throw new ArgumentNullException("unmanagedMarshal"); + throw new ArgumentNullException(nameof(unmanagedMarshal)); Contract.EndContractBlock(); m_typeBuilder.ThrowIfCreated(); @@ -226,10 +226,10 @@ namespace System.Reflection.Emit public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); ModuleBuilder module = m_typeBuilder.Module as ModuleBuilder; @@ -244,7 +244,7 @@ namespace System.Reflection.Emit public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { if (customBuilder == null) - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); Contract.EndContractBlock(); m_typeBuilder.ThrowIfCreated(); diff --git a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs index 6c4a7c868c..ad36bee594 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ILGenerator.cs @@ -475,7 +475,7 @@ namespace System.Reflection.Emit public virtual void Emit(OpCode opcode, MethodInfo meth) { if (meth == null) - throw new ArgumentNullException("meth"); + throw new ArgumentNullException(nameof(meth)); Contract.EndContractBlock(); if (opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj)) @@ -596,10 +596,10 @@ namespace System.Reflection.Emit public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[] optionalParameterTypes) { if (methodInfo == null) - throw new ArgumentNullException("methodInfo"); + throw new ArgumentNullException(nameof(methodInfo)); if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj))) - throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), "opcode"); + throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), nameof(opcode)); Contract.EndContractBlock(); @@ -633,7 +633,7 @@ namespace System.Reflection.Emit public virtual void Emit(OpCode opcode, SignatureHelper signature) { if (signature == null) - throw new ArgumentNullException("signature"); + throw new ArgumentNullException(nameof(signature)); Contract.EndContractBlock(); int stackchange = 0; @@ -670,7 +670,7 @@ namespace System.Reflection.Emit public virtual void Emit(OpCode opcode, ConstructorInfo con) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); Contract.EndContractBlock(); int stackchange = 0; @@ -804,7 +804,7 @@ namespace System.Reflection.Emit public virtual void Emit(OpCode opcode, Label[] labels) { if (labels == null) - throw new ArgumentNullException("labels"); + throw new ArgumentNullException(nameof(labels)); Contract.EndContractBlock(); // Emitting a switch table @@ -853,13 +853,13 @@ namespace System.Reflection.Emit if (local == null) { - throw new ArgumentNullException("local"); + throw new ArgumentNullException(nameof(local)); } Contract.EndContractBlock(); int tempVal = local.GetLocalIndex(); if (local.GetMethodBuilder() != m_methodBuilder) { - throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), "local"); + throw new ArgumentException(Environment.GetResourceString("Argument_UnmatchedMethodForLocal"), nameof(local)); } // If the instruction is a ldloc, ldloca a stloc, morph it to the optimal form. if (opcode.Equals(OpCodes.Ldloc)) @@ -1050,7 +1050,7 @@ namespace System.Reflection.Emit } else { // execute this branch if previous clause is Catch or Fault if (exceptionType==null) { - throw new ArgumentNullException("exceptionType"); + throw new ArgumentNullException(nameof(exceptionType)); } Label endLabel = current.GetEndLabel(); @@ -1152,7 +1152,7 @@ namespace System.Reflection.Emit // Emits the il to throw an exception if (excType==null) { - throw new ArgumentNullException("excType"); + throw new ArgumentNullException(nameof(excType)); } if (!excType.IsSubclassOf(typeof(Exception)) && excType!=typeof(Exception)) { @@ -1213,7 +1213,7 @@ namespace System.Reflection.Emit parameterTypes[0] = (Type)cls; MethodInfo mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi==null) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), "localBuilder"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), nameof(localBuilder)); } Emit(OpCodes.Callvirt, mi); @@ -1230,7 +1230,7 @@ namespace System.Reflection.Emit if (fld == null) { - throw new ArgumentNullException("fld"); + throw new ArgumentNullException(nameof(fld)); } Contract.EndContractBlock(); @@ -1251,7 +1251,7 @@ namespace System.Reflection.Emit parameterTypes[0] = (Type)cls; MethodInfo mi = prop.ReturnType.GetMethod("WriteLine", parameterTypes); if (mi==null) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), "fld"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmitWriteLineType"), nameof(fld)); } Emit(OpCodes.Callvirt, mi); } @@ -1282,7 +1282,7 @@ namespace System.Reflection.Emit } if (localType==null) { - throw new ArgumentNullException("localType"); + throw new ArgumentNullException(nameof(localType)); } if (methodBuilder.m_bIsBaked) { @@ -1303,10 +1303,10 @@ namespace System.Reflection.Emit // for the current active lexical scope. if (usingNamespace == null) - throw new ArgumentNullException("usingNamespace"); + throw new ArgumentNullException(nameof(usingNamespace)); if (usingNamespace.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "usingNamespace"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(usingNamespace)); Contract.EndContractBlock(); int index; @@ -1334,7 +1334,7 @@ namespace System.Reflection.Emit { if (startLine == 0 || startLine < 0 || endLine == 0 || endLine < 0) { - throw new ArgumentOutOfRangeException("startLine"); + throw new ArgumentOutOfRangeException(nameof(startLine)); } Contract.EndContractBlock(); m_LineNumberInfo.AddLineNumberInfo(document, m_length, startLine, startColumn, endLine, endColumn); diff --git a/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs index 56f820c704..a060098f64 100644 --- a/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs @@ -90,16 +90,16 @@ namespace System.Reflection.Emit ModuleBuilder mod, TypeBuilder type, bool bIsGlobalMethod) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (name[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(name)); if (mod == null) - throw new ArgumentNullException("mod"); + throw new ArgumentNullException(nameof(mod)); Contract.EndContractBlock(); if (parameterTypes != null) @@ -107,7 +107,7 @@ namespace System.Reflection.Emit foreach(Type t in parameterTypes) { if (t == null) - throw new ArgumentNullException("parameterTypes"); + throw new ArgumentNullException(nameof(parameterTypes)); } } @@ -203,7 +203,7 @@ namespace System.Reflection.Emit // queries this instance to get all of the information which it needs. if (il == null) { - throw new ArgumentNullException("il"); + throw new ArgumentNullException(nameof(il)); } Contract.EndContractBlock(); @@ -705,10 +705,10 @@ namespace System.Reflection.Emit public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names) { if (names == null) - throw new ArgumentNullException("names"); + throw new ArgumentNullException(nameof(names)); if (names.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "names"); + throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof(names)); Contract.EndContractBlock(); if (m_inst != null) @@ -716,7 +716,7 @@ namespace System.Reflection.Emit for (int i = 0; i < names.Length; i ++) if (names[i] == null) - throw new ArgumentNullException("names"); + throw new ArgumentNullException(nameof(names)); if (m_tkMethod.Token != 0) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodBuilderBaked")); @@ -932,7 +932,7 @@ namespace System.Reflection.Emit public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset) { if (pset == null) - throw new ArgumentNullException("pset"); + throw new ArgumentNullException(nameof(pset)); Contract.EndContractBlock(); ThrowIfGeneric (); @@ -943,7 +943,7 @@ namespace System.Reflection.Emit action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) { - throw new ArgumentOutOfRangeException("action"); + throw new ArgumentOutOfRangeException(nameof(action)); } #pragma warning restore 618 @@ -971,11 +971,11 @@ namespace System.Reflection.Emit { if (il == null) { - throw new ArgumentNullException("il", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(il), Environment.GetResourceString("ArgumentNull_Array")); } if (maxStack < 0) { - throw new ArgumentOutOfRangeException("maxStack", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(maxStack), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -1087,7 +1087,7 @@ namespace System.Reflection.Emit if (il != null && (count < 0 || count > il.Length)) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (il == null) @@ -1187,9 +1187,9 @@ namespace System.Reflection.Emit public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); ThrowIfGeneric(); @@ -1207,7 +1207,7 @@ namespace System.Reflection.Emit public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { if (customBuilder == null) - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); Contract.EndContractBlock(); ThrowIfGeneric(); @@ -1480,51 +1480,51 @@ namespace System.Reflection.Emit { if (tryOffset < 0) { - throw new ArgumentOutOfRangeException("tryOffset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(tryOffset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (tryLength < 0) { - throw new ArgumentOutOfRangeException("tryLength", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(tryLength), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (filterOffset < 0) { - throw new ArgumentOutOfRangeException("filterOffset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(filterOffset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (handlerOffset < 0) { - throw new ArgumentOutOfRangeException("handlerOffset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(handlerOffset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (handlerLength < 0) { - throw new ArgumentOutOfRangeException("handlerLength", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(handlerLength), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if ((long)tryOffset + tryLength > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("tryLength", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - tryOffset)); + throw new ArgumentOutOfRangeException(nameof(tryLength), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - tryOffset)); } if ((long)handlerOffset + handlerLength > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("handlerLength", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - handlerOffset)); + throw new ArgumentOutOfRangeException(nameof(handlerLength), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - handlerOffset)); } // Other tokens migth also be invalid. We only check nil tokens as the implementation (SectEH_Emit in corhlpr.cpp) requires it, // and we can't check for valid tokens until the module is baked. if (kind == ExceptionHandlingClauseOptions.Clause && (exceptionTypeToken & 0x00FFFFFF) == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeToken", exceptionTypeToken), "exceptionTypeToken"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeToken", exceptionTypeToken), nameof(exceptionTypeToken)); } Contract.EndContractBlock(); if (!IsValidKind(kind)) { - throw new ArgumentOutOfRangeException("kind", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(kind), Environment.GetResourceString("ArgumentOutOfRange_Enum")); } m_tryStartOffset = tryOffset; diff --git a/src/mscorlib/src/System/Reflection/Emit/ModuleBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/ModuleBuilder.cs index ec75d6ded4..df90041198 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ModuleBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ModuleBuilder.cs @@ -487,7 +487,7 @@ namespace System.Reflection.Emit // Helper to get constructor token. If usingRef is true, we will never use the def token if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); Contract.EndContractBlock(); int tr; @@ -1271,9 +1271,9 @@ namespace System.Reflection.Emit throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer")); if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); Contract.Ensures(Contract.Result<IResourceWriter>() != null); Contract.EndContractBlock(); @@ -1299,10 +1299,10 @@ namespace System.Reflection.Emit public void DefineManifestResource(String name, Stream stream, ResourceAttributes attribute) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (stream == null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); Contract.EndContractBlock(); // Define embedded managed resource to be stored in this module @@ -1321,9 +1321,9 @@ namespace System.Reflection.Emit Contract.EndContractBlock(); if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (m_assemblyBuilder.IsPersistable()) { @@ -1353,7 +1353,7 @@ namespace System.Reflection.Emit internal void DefineUnmanagedResourceInternalNoLock(Byte[] resource) { if (resource == null) - throw new ArgumentNullException("resource"); + throw new ArgumentNullException(nameof(resource)); Contract.EndContractBlock(); if (m_moduleData.m_strResourceFileName != null || m_moduleData.m_resourceBytes != null) @@ -1376,7 +1376,7 @@ namespace System.Reflection.Emit internal void DefineUnmanagedResourceFileInternalNoLock(String resourceFileName) { if (resourceFileName == null) - throw new ArgumentNullException("resourceFileName"); + throw new ArgumentNullException(nameof(resourceFileName)); Contract.EndContractBlock(); if (m_moduleData.m_resourceBytes != null || m_moduleData.m_strResourceFileName != null) @@ -1441,10 +1441,10 @@ namespace System.Reflection.Emit throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_GlobalsHaveBeenCreated")); if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if ((attributes & MethodAttributes.Static) == 0) throw new ArgumentException(Environment.GetResourceString("Argument_GlobalFunctionHasToBeStatic")); @@ -1636,7 +1636,7 @@ namespace System.Reflection.Emit private TypeToken GetTypeTokenWorkerNoLock(Type type, bool getGenericDefinition) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); CheckContext(type); @@ -1769,7 +1769,7 @@ namespace System.Reflection.Emit // Return a MemberRef token if MethodInfo is not defined in this module. Or // return the MethodDef token. if (method == null) - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); Contract.EndContractBlock(); int tr; @@ -1878,7 +1878,7 @@ namespace System.Reflection.Emit { if (constructor == null) { - throw new ArgumentNullException("constructor"); + throw new ArgumentNullException(nameof(constructor)); } lock (SyncRoot) @@ -1893,7 +1893,7 @@ namespace System.Reflection.Emit { if (method == null) { - throw new ArgumentNullException("method"); + throw new ArgumentNullException(nameof(method)); } // useMethodDef flag only affects the result if we pass in a generic method definition. @@ -1992,13 +1992,13 @@ namespace System.Reflection.Emit Type returnType, Type[] parameterTypes) { if (arrayClass == null) - throw new ArgumentNullException("arrayClass"); + throw new ArgumentNullException(nameof(arrayClass)); if (methodName == null) - throw new ArgumentNullException("methodName"); + throw new ArgumentNullException(nameof(methodName)); if (methodName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "methodName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(methodName)); if (arrayClass.IsArray == false) throw new ArgumentException(Environment.GetResourceString("Argument_HasToBeArrayClass")); @@ -2061,7 +2061,7 @@ namespace System.Reflection.Emit private FieldToken GetFieldTokenNoLock(FieldInfo field) { if (field == null) { - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(field)); } Contract.EndContractBlock(); @@ -2151,7 +2151,7 @@ namespace System.Reflection.Emit { if (str == null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.EndContractBlock(); @@ -2168,7 +2168,7 @@ namespace System.Reflection.Emit if (sigHelper == null) { - throw new ArgumentNullException("sigHelper"); + throw new ArgumentNullException(nameof(sigHelper)); } Contract.EndContractBlock(); @@ -2183,7 +2183,7 @@ namespace System.Reflection.Emit public SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength) { if (sigBytes == null) - throw new ArgumentNullException("sigBytes"); + throw new ArgumentNullException(nameof(sigBytes)); Contract.EndContractBlock(); byte[] localSigBytes = new byte[sigBytes.Length]; @@ -2205,9 +2205,9 @@ namespace System.Reflection.Emit public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); TypeBuilder.DefineCustomAttribute( @@ -2223,7 +2223,7 @@ namespace System.Reflection.Emit { if (customBuilder == null) { - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); } Contract.EndContractBlock(); @@ -2271,7 +2271,7 @@ namespace System.Reflection.Emit { // url cannot be null but can be an empty string if (url == null) - throw new ArgumentNullException("url"); + throw new ArgumentNullException(nameof(url)); Contract.EndContractBlock(); lock(SyncRoot) @@ -2316,7 +2316,7 @@ namespace System.Reflection.Emit if (entryPoint == null) { - throw new ArgumentNullException("entryPoint"); + throw new ArgumentNullException(nameof(entryPoint)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Reflection/Emit/ParameterBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/ParameterBuilder.cs index 693e2d3660..615cbb8716 100644 --- a/src/mscorlib/src/System/Reflection/Emit/ParameterBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/ParameterBuilder.cs @@ -31,7 +31,7 @@ namespace System.Reflection.Emit { { if (unmanagedMarshal == null) { - throw new ArgumentNullException("unmanagedMarshal"); + throw new ArgumentNullException(nameof(unmanagedMarshal)); } Contract.EndContractBlock(); @@ -61,9 +61,9 @@ namespace System.Reflection.Emit { public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); TypeBuilder.DefineCustomAttribute( @@ -80,7 +80,7 @@ namespace System.Reflection.Emit { { if (customBuilder == null) { - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); } Contract.EndContractBlock(); customBuilder.CreateCustomAttribute((ModuleBuilder) (m_methodBuilder .GetModule()), m_pdToken.Token); diff --git a/src/mscorlib/src/System/Reflection/Emit/PropertyBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/PropertyBuilder.cs index 5ac69f205f..4b8e40f068 100644 --- a/src/mscorlib/src/System/Reflection/Emit/PropertyBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/PropertyBuilder.cs @@ -47,11 +47,11 @@ namespace System.Reflection.Emit { TypeBuilder containingType) // the containing type { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (name[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(name)); Contract.EndContractBlock(); m_name = name; @@ -108,7 +108,7 @@ namespace System.Reflection.Emit { { if (mdBuilder == null) { - throw new ArgumentNullException("mdBuilder"); + throw new ArgumentNullException(nameof(mdBuilder)); } m_containingType.ThrowIfCreated(); @@ -150,9 +150,9 @@ namespace System.Reflection.Emit { public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); m_containingType.ThrowIfCreated(); TypeBuilder.DefineCustomAttribute( @@ -169,7 +169,7 @@ namespace System.Reflection.Emit { { if (customBuilder == null) { - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); } m_containingType.ThrowIfCreated(); customBuilder.CreateCustomAttribute(m_moduleBuilder, m_prToken.Token); diff --git a/src/mscorlib/src/System/Reflection/Emit/SignatureHelper.cs b/src/mscorlib/src/System/Reflection/Emit/SignatureHelper.cs index 35e8cc7e31..703ea43f50 100644 --- a/src/mscorlib/src/System/Reflection/Emit/SignatureHelper.cs +++ b/src/mscorlib/src/System/Reflection/Emit/SignatureHelper.cs @@ -123,7 +123,7 @@ namespace System.Reflection.Emit } else { - throw new ArgumentException(Environment.GetResourceString("Argument_UnknownUnmanagedCallConv"), "unmanagedCallConv"); + throw new ArgumentException(Environment.GetResourceString("Argument_UnknownUnmanagedCallConv"), nameof(unmanagedCallConv)); } sigHelp = new SignatureHelper(mod, intCall, returnType, null, null); @@ -193,15 +193,15 @@ namespace System.Reflection.Emit } [System.Security.SecurityCritical] // auto-generated - internal static SignatureHelper GetTypeSigToken(Module mod, Type type) + internal static SignatureHelper GetTypeSigToken(Module module, Type type) { - if (mod == null) - throw new ArgumentNullException("module"); + if (module == null) + throw new ArgumentNullException(nameof(module)); if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); - return new SignatureHelper(mod, type); + return new SignatureHelper(module, type); } #endregion @@ -315,13 +315,13 @@ namespace System.Reflection.Emit Type t = optionalCustomModifiers[i]; if (t == null) - throw new ArgumentNullException("optionalCustomModifiers"); + throw new ArgumentNullException(nameof(optionalCustomModifiers)); if (t.HasElementType) - throw new ArgumentException(Environment.GetResourceString("Argument_ArraysInvalid"), "optionalCustomModifiers"); + throw new ArgumentException(Environment.GetResourceString("Argument_ArraysInvalid"), nameof(optionalCustomModifiers)); if (t.ContainsGenericParameters) - throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "optionalCustomModifiers"); + throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(optionalCustomModifiers)); AddElementType(CorElementType.CModOpt); @@ -338,13 +338,13 @@ namespace System.Reflection.Emit Type t = requiredCustomModifiers[i]; if (t == null) - throw new ArgumentNullException("requiredCustomModifiers"); + throw new ArgumentNullException(nameof(requiredCustomModifiers)); if (t.HasElementType) - throw new ArgumentException(Environment.GetResourceString("Argument_ArraysInvalid"), "requiredCustomModifiers"); + throw new ArgumentException(Environment.GetResourceString("Argument_ArraysInvalid"), nameof(requiredCustomModifiers)); if (t.ContainsGenericParameters) - throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), "requiredCustomModifiers"); + throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(requiredCustomModifiers)); AddElementType(CorElementType.CModReqd); @@ -826,7 +826,7 @@ namespace System.Reflection.Emit public void AddArgument(Type argument, bool pinned) { if (argument == null) - throw new ArgumentNullException("argument"); + throw new ArgumentNullException(nameof(argument)); IncrementArgCounts(); AddOneArgTypeHelper(argument, pinned); @@ -835,10 +835,10 @@ namespace System.Reflection.Emit public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers) { if (requiredCustomModifiers != null && (arguments == null || requiredCustomModifiers.Length != arguments.Length)) - throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "requiredCustomModifiers", "arguments")); + throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "requiredCustomModifiers", nameof(arguments))); if (optionalCustomModifiers != null && (arguments == null || optionalCustomModifiers.Length != arguments.Length)) - throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "optionalCustomModifiers", "arguments")); + throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "optionalCustomModifiers", nameof(arguments))); if (arguments != null) { @@ -858,7 +858,7 @@ namespace System.Reflection.Emit throw new ArgumentException(Environment.GetResourceString("Argument_SigIsFinalized")); if (argument == null) - throw new ArgumentNullException("argument"); + throw new ArgumentNullException(nameof(argument)); IncrementArgCounts(); diff --git a/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs b/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs index 633a2bffb4..84ece90982 100644 --- a/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs +++ b/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs @@ -234,7 +234,7 @@ namespace System.Reflection.Emit internal void SetElementType(Type baseType) { if (baseType == null) - throw new ArgumentNullException("baseType"); + throw new ArgumentNullException(nameof(baseType)); Contract.EndContractBlock(); m_baseType = baseType; diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs index c50806aedc..c9adf448fc 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs @@ -56,10 +56,10 @@ namespace System.Reflection.Emit { public CustAttr(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); m_con = con; @@ -69,7 +69,7 @@ namespace System.Reflection.Emit { public CustAttr(CustomAttributeBuilder customBuilder) { if (customBuilder == null) - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); Contract.EndContractBlock(); m_customBuilder = customBuilder; @@ -105,13 +105,13 @@ namespace System.Reflection.Emit { // if we wanted to but that just complicates things so these checks are designed to prevent that scenario. if (method.IsGenericMethod && !method.IsGenericMethodDefinition) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedGenericMethodDefinition"), "method"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedGenericMethodDefinition"), nameof(method)); if (method.DeclaringType == null || !method.DeclaringType.IsGenericTypeDefinition) - throw new ArgumentException(Environment.GetResourceString("Argument_MethodNeedGenericDeclaringType"), "method"); + throw new ArgumentException(Environment.GetResourceString("Argument_MethodNeedGenericDeclaringType"), nameof(method)); if (type.GetGenericTypeDefinition() != method.DeclaringType) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMethodDeclaringType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidMethodDeclaringType"), nameof(type)); Contract.EndContractBlock(); // The following converts from Type or TypeBuilder of G<T> to TypeBuilderInstantiation G<T>. These types @@ -121,7 +121,7 @@ namespace System.Reflection.Emit { type = type.MakeGenericType(type.GetGenericArguments()); if (!(type is TypeBuilderInstantiation)) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(type)); return MethodOnTypeBuilderInstantiation.GetMethod(method, type as TypeBuilderInstantiation); } @@ -131,18 +131,18 @@ namespace System.Reflection.Emit { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeTypeBuilder")); if (!constructor.DeclaringType.IsGenericTypeDefinition) - throw new ArgumentException(Environment.GetResourceString("Argument_ConstructorNeedGenericDeclaringType"), "constructor"); + throw new ArgumentException(Environment.GetResourceString("Argument_ConstructorNeedGenericDeclaringType"), nameof(constructor)); Contract.EndContractBlock(); if (!(type is TypeBuilderInstantiation)) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(type)); // TypeBuilder G<T> ==> TypeBuilderInstantiation G<T> if (type is TypeBuilder && type.IsGenericTypeDefinition) type = type.MakeGenericType(type.GetGenericArguments()); if (type.GetGenericTypeDefinition() != constructor.DeclaringType) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidConstructorDeclaringType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidConstructorDeclaringType"), nameof(type)); return ConstructorOnTypeBuilderInstantiation.GetConstructor(constructor, type as TypeBuilderInstantiation); } @@ -152,18 +152,18 @@ namespace System.Reflection.Emit { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeTypeBuilder")); if (!field.DeclaringType.IsGenericTypeDefinition) - throw new ArgumentException(Environment.GetResourceString("Argument_FieldNeedGenericDeclaringType"), "field"); + throw new ArgumentException(Environment.GetResourceString("Argument_FieldNeedGenericDeclaringType"), nameof(field)); Contract.EndContractBlock(); if (!(type is TypeBuilderInstantiation)) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(type)); // TypeBuilder G<T> ==> TypeBuilderInstantiation G<T> if (type is TypeBuilder && type.IsGenericTypeDefinition) type = type.MakeGenericType(type.GetGenericArguments()); if (type.GetGenericTypeDefinition() != field.DeclaringType) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFieldDeclaringType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFieldDeclaringType"), nameof(type)); return FieldOnTypeBuilderInstantiation.GetField(field, type as TypeBuilderInstantiation); } @@ -595,17 +595,17 @@ namespace System.Reflection.Emit { PackingSize iPackingSize, int iTypeSize, TypeBuilder enclosingType) { if (fullname == null) - throw new ArgumentNullException("fullname"); + throw new ArgumentNullException(nameof(fullname)); if (fullname.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "fullname"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(fullname)); if (fullname[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "fullname"); + throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(fullname)); if (fullname.Length > 1023) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeNameTooLong"), "fullname"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeNameTooLong"), nameof(fullname)); Contract.EndContractBlock(); int i; @@ -621,7 +621,7 @@ namespace System.Reflection.Emit { // Nested Type should have nested attribute set. // If we are renumbering TypeAttributes' bit, we need to change the logic here. if (((attr & TypeAttributes.VisibilityMask) == TypeAttributes.Public) ||((attr & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic)) - throw new ArgumentException(Environment.GetResourceString("Argument_BadNestedTypeFlags"), "attr"); + throw new ArgumentException(Environment.GetResourceString("Argument_BadNestedTypeFlags"), nameof(attr)); } int[] interfaceTokens = null; @@ -632,7 +632,7 @@ namespace System.Reflection.Emit { if (interfaces[i] == null) { // cannot contain null in the interface list - throw new ArgumentNullException("interfaces"); + throw new ArgumentNullException(nameof(interfaces)); } } interfaceTokens = new int[interfaces.Length + 1]; @@ -741,22 +741,22 @@ namespace System.Reflection.Emit { CallingConvention nativeCallConv, CharSet nativeCharSet) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (dllName == null) - throw new ArgumentNullException("dllName"); + throw new ArgumentNullException(nameof(dllName)); if (dllName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "dllName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(dllName)); if (importName == null) - throw new ArgumentNullException("importName"); + throw new ArgumentNullException(nameof(importName)); if (importName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "importName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(importName)); if ((attributes & MethodAttributes.Abstract) != 0) throw new ArgumentException(Environment.GetResourceString("Argument_BadPInvokeMethod")); @@ -840,10 +840,10 @@ namespace System.Reflection.Emit { TypeAttributes typeAttributes; if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (size <= 0 || size >= 0x003f0000) throw new ArgumentException(Environment.GetResourceString("Argument_BadSizeForData")); @@ -1508,13 +1508,13 @@ namespace System.Reflection.Emit { throw new NotSupportedException(Environment.GetResourceString("NotSupported_TypeNotYetCreated")); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(m_bakedRuntimeType, attributeRuntimeType, inherit); } @@ -1526,13 +1526,13 @@ namespace System.Reflection.Emit { throw new NotSupportedException(Environment.GetResourceString("NotSupported_TypeNotYetCreated")); if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"caType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(m_bakedRuntimeType, attributeRuntimeType, inherit); } @@ -1559,7 +1559,7 @@ namespace System.Reflection.Emit { public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names) { if (names == null) - throw new ArgumentNullException("names"); + throw new ArgumentNullException(nameof(names)); if (names.Length == 0) throw new ArgumentException(); @@ -1567,7 +1567,7 @@ namespace System.Reflection.Emit { for (int i = 0; i < names.Length; i ++) if (names[i] == null) - throw new ArgumentNullException("names"); + throw new ArgumentNullException(nameof(names)); if (m_inst != null) throw new InvalidOperationException(); @@ -1614,10 +1614,10 @@ namespace System.Reflection.Emit { private void DefineMethodOverrideNoLock(MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration) { if (methodInfoBody == null) - throw new ArgumentNullException("methodInfoBody"); + throw new ArgumentNullException(nameof(methodInfoBody)); if (methodInfoDeclaration == null) - throw new ArgumentNullException("methodInfoDeclaration"); + throw new ArgumentNullException(nameof(methodInfoDeclaration)); Contract.EndContractBlock(); ThrowIfCreated(); @@ -1683,10 +1683,10 @@ namespace System.Reflection.Emit { Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); Contract.Ensures(Contract.Result<MethodBuilder>() != null); Contract.EndContractBlock(); @@ -1698,10 +1698,10 @@ namespace System.Reflection.Emit { if (parameterTypes != null) { if (parameterTypeOptionalCustomModifiers != null && parameterTypeOptionalCustomModifiers.Length != parameterTypes.Length) - throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "parameterTypeOptionalCustomModifiers", "parameterTypes")); + throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "parameterTypeOptionalCustomModifiers", nameof(parameterTypes))); if (parameterTypeRequiredCustomModifiers != null && parameterTypeRequiredCustomModifiers.Length != parameterTypes.Length) - throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "parameterTypeRequiredCustomModifiers", "parameterTypes")); + throw new ArgumentException(Environment.GetResourceString("Argument_MismatchedArrays", "parameterTypeRequiredCustomModifiers", nameof(parameterTypes))); } ThrowIfCreated(); @@ -2077,7 +2077,7 @@ namespace System.Reflection.Emit { private FieldBuilder DefineInitializedDataNoLock(String name, byte[] data, FieldAttributes attributes) { if (data == null) - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); Contract.EndContractBlock(); // This method will define an initialized Data in .sdata. @@ -2151,9 +2151,9 @@ namespace System.Reflection.Emit { Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); Contract.EndContractBlock(); CheckContext(returnType); @@ -2208,11 +2208,11 @@ namespace System.Reflection.Emit { private EventBuilder DefineEventNoLock(String name, EventAttributes attributes, Type eventtype) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (name[0] == '\0') - throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(name)); Contract.EndContractBlock(); int tkType; @@ -2504,7 +2504,7 @@ namespace System.Reflection.Emit { { if (interfaceType == null) { - throw new ArgumentNullException("interfaceType"); + throw new ArgumentNullException(nameof(interfaceType)); } Contract.EndContractBlock(); @@ -2532,7 +2532,7 @@ namespace System.Reflection.Emit { private void AddDeclarativeSecurityNoLock(SecurityAction action, PermissionSet pset) { if (pset == null) - throw new ArgumentNullException("pset"); + throw new ArgumentNullException(nameof(pset)); #pragma warning disable 618 if (!Enum.IsDefined(typeof(SecurityAction), action) || @@ -2540,7 +2540,7 @@ namespace System.Reflection.Emit { action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) { - throw new ArgumentOutOfRangeException("action"); + throw new ArgumentOutOfRangeException(nameof(action)); } #pragma warning restore 618 @@ -2583,10 +2583,10 @@ public TypeToken TypeToken public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { if (con == null) - throw new ArgumentNullException("con"); + throw new ArgumentNullException(nameof(con)); if (binaryAttribute == null) - throw new ArgumentNullException("binaryAttribute"); + throw new ArgumentNullException(nameof(binaryAttribute)); Contract.EndContractBlock(); TypeBuilder.DefineCustomAttribute(m_module, m_tdType.Token, ((ModuleBuilder)m_module).GetConstructorToken(con).Token, @@ -2597,7 +2597,7 @@ public TypeToken TypeToken public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { if (customBuilder == null) - throw new ArgumentNullException("customBuilder"); + throw new ArgumentNullException(nameof(customBuilder)); Contract.EndContractBlock(); customBuilder.CreateCustomAttribute((ModuleBuilder)m_module, m_tdType.Token); diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index 13b98b6543..3bae585953 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -28,13 +28,13 @@ namespace System.Reflection.Emit throw new InvalidOperationException(); if (typeArguments == null) - throw new ArgumentNullException("typeArguments"); + throw new ArgumentNullException(nameof(typeArguments)); Contract.EndContractBlock(); foreach (Type t in typeArguments) { if (t == null) - throw new ArgumentNullException("typeArguments"); + throw new ArgumentNullException(nameof(typeArguments)); } return new TypeBuilderInstantiation(type, typeArguments); diff --git a/src/mscorlib/src/System/Reflection/EventInfo.cs b/src/mscorlib/src/System/Reflection/EventInfo.cs index 3fd1951b6c..509b16ba00 100644 --- a/src/mscorlib/src/System/Reflection/EventInfo.cs +++ b/src/mscorlib/src/System/Reflection/EventInfo.cs @@ -305,13 +305,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -320,13 +320,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -377,7 +377,7 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); MemberInfoSerializationHolder.GetSerializationInfo( diff --git a/src/mscorlib/src/System/Reflection/FieldInfo.cs b/src/mscorlib/src/System/Reflection/FieldInfo.cs index c6a44d412b..5852de73fc 100644 --- a/src/mscorlib/src/System/Reflection/FieldInfo.cs +++ b/src/mscorlib/src/System/Reflection/FieldInfo.cs @@ -36,7 +36,7 @@ namespace System.Reflection public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle) { if (handle.IsNullHandle()) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), "handle"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"), nameof(handle)); FieldInfo f = RuntimeType.GetFieldInfo(handle.GetRuntimeFieldInfo()); @@ -325,13 +325,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -340,13 +340,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -366,7 +366,7 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); MemberInfoSerializationHolder.GetSerializationInfo( info, diff --git a/src/mscorlib/src/System/Reflection/IntrospectionExtensions.cs b/src/mscorlib/src/System/Reflection/IntrospectionExtensions.cs index ce2630a908..a7e41513ce 100644 --- a/src/mscorlib/src/System/Reflection/IntrospectionExtensions.cs +++ b/src/mscorlib/src/System/Reflection/IntrospectionExtensions.cs @@ -21,7 +21,7 @@ namespace System.Reflection { public static TypeInfo GetTypeInfo(this Type type){ if(type == null){ - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } var rcType=(IReflectableType)type; if(rcType==null){ diff --git a/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs b/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs index c1b4ee5fe1..ac524bd91b 100644 --- a/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs +++ b/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs @@ -31,7 +31,7 @@ namespace System.Reflection Type[] genericArguments) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); String assemblyName = reflectedClass.Module.Assembly.FullName; @@ -65,7 +65,7 @@ namespace System.Reflection internal MemberInfoSerializationHolder(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); String assemblyName = info.GetString("AssemblyName"); diff --git a/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs b/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs index dd5d69b1fb..7df9529500 100644 --- a/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs +++ b/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs @@ -29,7 +29,7 @@ namespace System.Reflection.Metadata { if (assembly == null) { - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); } blob = null; diff --git a/src/mscorlib/src/System/Reflection/MethodBase.cs b/src/mscorlib/src/System/Reflection/MethodBase.cs index 68363bf1e0..6a9778b981 100644 --- a/src/mscorlib/src/System/Reflection/MethodBase.cs +++ b/src/mscorlib/src/System/Reflection/MethodBase.cs @@ -347,7 +347,7 @@ namespace System.Reflection if (p == null) p = GetParametersNoCopy(); if (p[i].DefaultValue == System.DBNull.Value) - throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters"); + throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),nameof(parameters)); arg = p[i].DefaultValue; } copyOfParameters[i] = argRT.CheckValue(arg, binder, culture, invokeAttr); diff --git a/src/mscorlib/src/System/Reflection/MethodInfo.cs b/src/mscorlib/src/System/Reflection/MethodInfo.cs index 2d827ba0ef..8a67d4217a 100644 --- a/src/mscorlib/src/System/Reflection/MethodInfo.cs +++ b/src/mscorlib/src/System/Reflection/MethodInfo.cs @@ -479,13 +479,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType, inherit); } @@ -493,13 +493,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType, inherit); } @@ -898,15 +898,15 @@ namespace System.Reflection { // Validate the parameters. if (delegateType == null) - throw new ArgumentNullException("delegateType"); + throw new ArgumentNullException(nameof(delegateType)); Contract.EndContractBlock(); RuntimeType rtType = delegateType as RuntimeType; if (rtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "delegateType"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(delegateType)); if (!rtType.IsDelegate()) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "delegateType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(delegateType)); Delegate d = Delegate.CreateDelegateInternal(rtType, this, firstArgument, bindingFlags, ref stackMark); if (d == null) @@ -924,7 +924,7 @@ namespace System.Reflection public override MethodInfo MakeGenericMethod(params Type[] methodInstantiation) { if (methodInstantiation == null) - throw new ArgumentNullException("methodInstantiation"); + throw new ArgumentNullException(nameof(methodInstantiation)); Contract.EndContractBlock(); RuntimeType[] methodInstantionRuntimeType = new RuntimeType[methodInstantiation.Length]; @@ -1036,7 +1036,7 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); if (m_reflectedTypeCache.IsGlobal) diff --git a/src/mscorlib/src/System/Reflection/Missing.cs b/src/mscorlib/src/System/Reflection/Missing.cs index 8289193191..8d93e1e6eb 100644 --- a/src/mscorlib/src/System/Reflection/Missing.cs +++ b/src/mscorlib/src/System/Reflection/Missing.cs @@ -28,7 +28,7 @@ namespace System.Reflection void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); UnitySerializationHolder.GetUnitySerializationInfo(info, this); diff --git a/src/mscorlib/src/System/Reflection/Module.cs b/src/mscorlib/src/System/Reflection/Module.cs index 34705a4211..6d492d8e74 100644 --- a/src/mscorlib/src/System/Reflection/Module.cs +++ b/src/mscorlib/src/System/Reflection/Module.cs @@ -432,16 +432,16 @@ namespace System.Reflection String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i = 0; i < types.Length; i++) { if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); } return GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers); @@ -450,16 +450,16 @@ namespace System.Reflection public MethodInfo GetMethod(String name, Type[] types) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i = 0; i < types.Length; i++) { if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); } return GetMethodImpl(name, Module.DefaultLookup, null, CallingConventions.Any, types, null); @@ -468,7 +468,7 @@ namespace System.Reflection public MethodInfo GetMethod(String name) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); return GetMethodImpl(name, Module.DefaultLookup, null, CallingConventions.Any, @@ -652,12 +652,12 @@ namespace System.Reflection MetadataToken tk = new MetadataToken(metadataToken); if (!MetadataImport.IsValidToken(tk)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), Environment.GetResourceString("Argument_InvalidToken", tk, this)); if (!tk.IsMemberRef && !tk.IsMethodDef && !tk.IsTypeSpec && !tk.IsSignature && !tk.IsFieldDef) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidToken", tk, this), - "metadataToken"); + nameof(metadataToken)); ConstArray signature; if (tk.IsMemberRef) @@ -679,7 +679,7 @@ namespace System.Reflection MetadataToken tk = new MetadataToken(metadataToken); if (!MetadataImport.IsValidToken(tk)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), Environment.GetResourceString("Argument_InvalidToken", tk, this)); RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments); @@ -690,16 +690,16 @@ namespace System.Reflection if (!tk.IsMethodDef && !tk.IsMethodSpec) { if (!tk.IsMemberRef) - throw new ArgumentException("metadataToken", - Environment.GetResourceString("Argument_ResolveMethod", tk, this)); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveMethod", tk, this), + nameof(metadataToken)); unsafe { ConstArray sig = MetadataImport.GetMemberRefProps(tk); if (*(MdSigCallingConvention*)sig.Signature.ToPointer() == MdSigCallingConvention.Field) - throw new ArgumentException("metadataToken", - Environment.GetResourceString("Argument_ResolveMethod", tk, this)); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveMethod", tk, this), + nameof(metadataToken)); } } @@ -730,7 +730,7 @@ namespace System.Reflection MetadataToken tk = new MetadataToken(metadataToken); if (!MetadataImport.IsValidToken(tk) || !tk.IsFieldDef) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Argument_InvalidToken", tk, this))); int tkDeclaringType; @@ -752,7 +752,7 @@ namespace System.Reflection } catch { - throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this), "metadataToken"); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this), nameof(metadataToken)); } } @@ -762,7 +762,7 @@ namespace System.Reflection MetadataToken tk = new MetadataToken(metadataToken); if (!MetadataImport.IsValidToken(tk)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), Environment.GetResourceString("Argument_InvalidToken", tk, this)); RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments); @@ -775,16 +775,16 @@ namespace System.Reflection if (!tk.IsFieldDef) { if (!tk.IsMemberRef) - throw new ArgumentException("metadataToken", - Environment.GetResourceString("Argument_ResolveField", tk, this)); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this), + nameof(metadataToken)); unsafe { ConstArray sig = MetadataImport.GetMemberRefProps(tk); if (*(MdSigCallingConvention*)sig.Signature.ToPointer() != MdSigCallingConvention.Field) - throw new ArgumentException("metadataToken", - Environment.GetResourceString("Argument_ResolveField", tk, this)); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveField", tk, this), + nameof(metadataToken)); } fieldHandle = ModuleHandle.ResolveFieldHandleInternal(GetNativeHandle(), tk, typeArgs, methodArgs); @@ -817,14 +817,14 @@ namespace System.Reflection MetadataToken tk = new MetadataToken(metadataToken); if (tk.IsGlobalTypeDefToken) - throw new ArgumentException(Environment.GetResourceString("Argument_ResolveModuleType", tk), "metadataToken"); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveModuleType", tk), nameof(metadataToken)); if (!MetadataImport.IsValidToken(tk)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), Environment.GetResourceString("Argument_InvalidToken", tk, this)); if (!tk.IsTypeDef && !tk.IsTypeSpec && !tk.IsTypeRef) - throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", tk, this), "metadataToken"); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", tk, this), nameof(metadataToken)); RuntimeTypeHandle[] typeArgs = ConvertToTypeHandleArray(genericTypeArguments); RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments); @@ -834,7 +834,7 @@ namespace System.Reflection Type t = GetModuleHandle().ResolveTypeHandle(metadataToken, typeArgs, methodArgs).GetRuntimeType(); if (t == null) - throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", tk, this), "metadataToken"); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", tk, this), nameof(metadataToken)); return t; } @@ -867,7 +867,7 @@ namespace System.Reflection if (tk.IsMemberRef) { if (!MetadataImport.IsValidToken(tk)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), Environment.GetResourceString("Argument_InvalidToken", tk, this)); ConstArray sig = MetadataImport.GetMemberRefProps(tk); @@ -885,8 +885,8 @@ namespace System.Reflection } } - throw new ArgumentException("metadataToken", - Environment.GetResourceString("Argument_ResolveMember", tk, this)); + throw new ArgumentException(Environment.GetResourceString("Argument_ResolveMember", tk, this), + nameof(metadataToken)); } [System.Security.SecuritySafeCritical] // auto-generated @@ -898,7 +898,7 @@ namespace System.Reflection String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Argument_ResolveString"), metadataToken, ToString())); if (!MetadataImport.IsValidToken(tk)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(metadataToken), String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Argument_InvalidToken", tk, this))); string str = MetadataImport.GetUserString(metadataToken); @@ -1001,13 +1001,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -1016,13 +1016,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -1039,7 +1039,7 @@ namespace System.Reflection { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); UnitySerializationHolder.GetUnitySerializationInfo(info, UnitySerializationHolder.ModuleUnity, this.ScopeName, this.GetRuntimeAssembly()); @@ -1051,7 +1051,7 @@ namespace System.Reflection { // throw on null strings regardless of the value of "throwOnError" if (className == null) - throw new ArgumentNullException("className"); + throw new ArgumentNullException(nameof(className)); RuntimeType retType = null; Object keepAlive = null; @@ -1145,7 +1145,7 @@ namespace System.Reflection public override FieldInfo GetField(String name, BindingFlags bindingAttr) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (RuntimeType == null) return null; diff --git a/src/mscorlib/src/System/Reflection/ParameterInfo.cs b/src/mscorlib/src/System/Reflection/ParameterInfo.cs index 63c6330b0a..5186e69272 100644 --- a/src/mscorlib/src/System/Reflection/ParameterInfo.cs +++ b/src/mscorlib/src/System/Reflection/ParameterInfo.cs @@ -157,7 +157,7 @@ namespace System.Reflection public virtual Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); return EmptyArray<Object>.Value; @@ -166,7 +166,7 @@ namespace System.Reflection public virtual bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); return false; @@ -403,7 +403,7 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // We could be serializing for consumption by a pre-Whidbey @@ -728,7 +728,7 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); if (MdToken.IsNullToken(m_tkParamDef)) @@ -737,7 +737,7 @@ namespace System.Reflection RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -746,7 +746,7 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); if (MdToken.IsNullToken(m_tkParamDef)) @@ -755,7 +755,7 @@ namespace System.Reflection RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } diff --git a/src/mscorlib/src/System/Reflection/Pointer.cs b/src/mscorlib/src/System/Reflection/Pointer.cs index 8105208288..f0127eff1f 100644 --- a/src/mscorlib/src/System/Reflection/Pointer.cs +++ b/src/mscorlib/src/System/Reflection/Pointer.cs @@ -41,14 +41,14 @@ namespace System.Reflection { [System.Security.SecurityCritical] // auto-generated public static unsafe Object Box(void *ptr,Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (!type.IsPointer) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),nameof(ptr)); Contract.EndContractBlock(); RuntimeType rt = type as RuntimeType; if (rt == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), "ptr"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"), nameof(ptr)); Pointer x = new Pointer(); x._ptr = ptr; @@ -60,7 +60,7 @@ namespace System.Reflection { [System.Security.SecurityCritical] // auto-generated public static unsafe void* Unbox(Object ptr) { if (!(ptr is Pointer)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"ptr"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),nameof(ptr)); return ((Pointer)ptr)._ptr; } diff --git a/src/mscorlib/src/System/Reflection/PropertyInfo.cs b/src/mscorlib/src/System/Reflection/PropertyInfo.cs index 3e451b15b6..88de1ed3a9 100644 --- a/src/mscorlib/src/System/Reflection/PropertyInfo.cs +++ b/src/mscorlib/src/System/Reflection/PropertyInfo.cs @@ -332,13 +332,13 @@ namespace System.Reflection public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType); } @@ -347,13 +347,13 @@ namespace System.Reflection public override bool IsDefined(Type attributeType, bool inherit) { if (attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType); } @@ -634,7 +634,7 @@ namespace System.Reflection public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); MemberInfoSerializationHolder.GetSerializationInfo( diff --git a/src/mscorlib/src/System/Reflection/ReflectionContext.cs b/src/mscorlib/src/System/Reflection/ReflectionContext.cs index f9bfa87d76..34f692166c 100644 --- a/src/mscorlib/src/System/Reflection/ReflectionContext.cs +++ b/src/mscorlib/src/System/Reflection/ReflectionContext.cs @@ -28,7 +28,7 @@ namespace System.Reflection public virtual TypeInfo GetTypeForObject(object value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); return MapType(value.GetType().GetTypeInfo()); } diff --git a/src/mscorlib/src/System/Reflection/ReflectionTypeLoadException.cs b/src/mscorlib/src/System/Reflection/ReflectionTypeLoadException.cs index 9b55c260cf..37c93eb526 100644 --- a/src/mscorlib/src/System/Reflection/ReflectionTypeLoadException.cs +++ b/src/mscorlib/src/System/Reflection/ReflectionTypeLoadException.cs @@ -68,7 +68,7 @@ namespace System.Reflection { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/Reflection/RuntimeReflectionExtensions.cs b/src/mscorlib/src/System/Reflection/RuntimeReflectionExtensions.cs index b4ef9b9902..49262634e3 100644 --- a/src/mscorlib/src/System/Reflection/RuntimeReflectionExtensions.cs +++ b/src/mscorlib/src/System/Reflection/RuntimeReflectionExtensions.cs @@ -10,16 +10,16 @@ namespace System.Reflection { private const BindingFlags everything = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; - private static void CheckAndThrow(Type t) + private static void CheckAndThrow(Type type) { - if (t == null) throw new ArgumentNullException("type"); - if (!(t is RuntimeType)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); + if (type == null) throw new ArgumentNullException(nameof(type)); + if (!(type is RuntimeType)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } - private static void CheckAndThrow(MethodInfo m) + private static void CheckAndThrow(MethodInfo method) { - if (m == null) throw new ArgumentNullException("method"); - if (!(m is RuntimeMethodInfo)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo")); + if (method == null) throw new ArgumentNullException(nameof(method)); + if (!(method is RuntimeMethodInfo)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo")); } public static IEnumerable<PropertyInfo> GetRuntimeProperties(this Type type) @@ -72,7 +72,7 @@ namespace System.Reflection public static InterfaceMapping GetRuntimeInterfaceMap(this TypeInfo typeInfo, Type interfaceType) { - if (typeInfo == null) throw new ArgumentNullException("typeInfo"); + if (typeInfo == null) throw new ArgumentNullException(nameof(typeInfo)); if (!(typeInfo is RuntimeType)) throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); return typeInfo.GetInterfaceMap(interfaceType); @@ -80,7 +80,7 @@ namespace System.Reflection public static MethodInfo GetMethodInfo(this Delegate del) { - if (del == null) throw new ArgumentNullException("del"); + if (del == null) throw new ArgumentNullException(nameof(del)); return del.Method; } diff --git a/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs b/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs index 0d69a654ed..f9fbb631e1 100644 --- a/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs +++ b/src/mscorlib/src/System/Reflection/StrongNameKeyPair.cs @@ -48,7 +48,7 @@ namespace System.Reflection public StrongNameKeyPair(FileStream keyPairFile) { if (keyPairFile == null) - throw new ArgumentNullException("keyPairFile"); + throw new ArgumentNullException(nameof(keyPairFile)); Contract.EndContractBlock(); int length = (int)keyPairFile.Length; @@ -67,7 +67,7 @@ namespace System.Reflection public StrongNameKeyPair(byte[] keyPairArray) { if (keyPairArray == null) - throw new ArgumentNullException("keyPairArray"); + throw new ArgumentNullException(nameof(keyPairArray)); Contract.EndContractBlock(); _keyPairArray = new byte[keyPairArray.Length]; @@ -96,7 +96,7 @@ namespace System.Reflection public StrongNameKeyPair(String keyPairContainer) { if (keyPairContainer == null) - throw new ArgumentNullException("keyPairContainer"); + throw new ArgumentNullException(nameof(keyPairContainer)); Contract.EndContractBlock(); _keyPairContainer = keyPairContainer; diff --git a/src/mscorlib/src/System/Reflection/TypeDelegator.cs b/src/mscorlib/src/System/Reflection/TypeDelegator.cs index cad4a4295a..e94cfa27be 100644 --- a/src/mscorlib/src/System/Reflection/TypeDelegator.cs +++ b/src/mscorlib/src/System/Reflection/TypeDelegator.cs @@ -31,7 +31,7 @@ namespace System.Reflection { public TypeDelegator(Type delegatingType) { if (delegatingType == null) - throw new ArgumentNullException("delegatingType"); + throw new ArgumentNullException(nameof(delegatingType)); Contract.EndContractBlock(); typeImpl = delegatingType; diff --git a/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs b/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs index 8235d608be..15a076bc5c 100644 --- a/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs +++ b/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs @@ -36,13 +36,13 @@ namespace System.Resources { public LooselyLinkedResourceReference(String looselyLinkedResourceName, String typeName) { if (looselyLinkedResourceName == null) - throw new ArgumentNullException("looselyLinkedResourceName"); + throw new ArgumentNullException(nameof(looselyLinkedResourceName)); if (typeName == null) - throw new ArgumentNullException("typeName"); + throw new ArgumentNullException(nameof(typeName)); if (looselyLinkedResourceName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "looselyLinkedResourceName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(looselyLinkedResourceName)); if (typeName.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "typeName"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(typeName)); Contract.EndContractBlock(); _manifestResourceName = looselyLinkedResourceName; @@ -60,7 +60,7 @@ namespace System.Resources { public Object Resolve(Assembly assembly) { if (assembly == null) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); Contract.EndContractBlock(); Stream data = assembly.GetManifestResourceStream(_manifestResourceName); diff --git a/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs b/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs index 560cd5faa9..6517a56b6a 100644 --- a/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs +++ b/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs @@ -35,7 +35,7 @@ namespace System.Resources { public NeutralResourcesLanguageAttribute(String cultureName) { if (cultureName == null) - throw new ArgumentNullException("cultureName"); + throw new ArgumentNullException(nameof(cultureName)); Contract.EndContractBlock(); _culture = cultureName; @@ -45,7 +45,7 @@ namespace System.Resources { public NeutralResourcesLanguageAttribute(String cultureName, UltimateResourceFallbackLocation location) { if (cultureName == null) - throw new ArgumentNullException("cultureName"); + throw new ArgumentNullException(nameof(cultureName)); if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location)) throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", location)); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Resources/ResourceManager.cs b/src/mscorlib/src/System/Resources/ResourceManager.cs index b088e7f492..3cba43edee 100644 --- a/src/mscorlib/src/System/Resources/ResourceManager.cs +++ b/src/mscorlib/src/System/Resources/ResourceManager.cs @@ -292,9 +292,9 @@ namespace System.Resources { // private ResourceManager(String baseName, String resourceDir, Type usingResourceSet) { if (null==baseName) - throw new ArgumentNullException("baseName"); + throw new ArgumentNullException(nameof(baseName)); if (null==resourceDir) - throw new ArgumentNullException("resourceDir"); + throw new ArgumentNullException(nameof(resourceDir)); Contract.EndContractBlock(); #if !FEATURE_CORECLR @@ -337,10 +337,10 @@ namespace System.Resources { public ResourceManager(String baseName, Assembly assembly) { if (null==baseName) - throw new ArgumentNullException("baseName"); + throw new ArgumentNullException(nameof(baseName)); if (null==assembly) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); Contract.EndContractBlock(); if (!(assembly is RuntimeAssembly)) @@ -368,9 +368,9 @@ namespace System.Resources { public ResourceManager(String baseName, Assembly assembly, Type usingResourceSet) { if (null==baseName) - throw new ArgumentNullException("baseName"); + throw new ArgumentNullException(nameof(baseName)); if (null==assembly) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); Contract.EndContractBlock(); #if !FEATURE_CORECLR @@ -387,7 +387,7 @@ namespace System.Resources { BaseNameField = baseName; if (usingResourceSet != null && (usingResourceSet != _minResourceSet) && !(usingResourceSet.IsSubclassOf(_minResourceSet))) - throw new ArgumentException(Environment.GetResourceString("Arg_ResMgrNotResSet"), "usingResourceSet"); + throw new ArgumentException(Environment.GetResourceString("Arg_ResMgrNotResSet"), nameof(usingResourceSet)); _userResourceSet = usingResourceSet; CommonAssemblyInit(); @@ -404,7 +404,7 @@ namespace System.Resources { public ResourceManager(Type resourceSource) { if (null==resourceSource) - throw new ArgumentNullException("resourceSource"); + throw new ArgumentNullException(nameof(resourceSource)); Contract.EndContractBlock(); if (!(resourceSource is RuntimeType)) @@ -681,7 +681,7 @@ namespace System.Resources { [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public virtual ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) { if (null==culture) - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); Contract.EndContractBlock(); Dictionary<String,ResourceSet> localResourceSets = _resourceSets; @@ -846,7 +846,7 @@ namespace System.Resources { { // Ensure that the assembly reference is not null if (a == null) { - throw new ArgumentNullException("a", Environment.GetResourceString("ArgumentNull_Assembly")); + throw new ArgumentNullException(nameof(a), Environment.GetResourceString("ArgumentNull_Assembly")); } Contract.EndContractBlock(); @@ -1225,7 +1225,7 @@ namespace System.Resources { // public virtual String GetString(String name, CultureInfo culture) { if (null==name) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); #if FEATURE_APPX @@ -1342,7 +1342,7 @@ namespace System.Resources { private Object GetObject(String name, CultureInfo culture, bool wrapUnmanagedMemStream) { if (null==name) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); #if FEATURE_APPX @@ -1586,7 +1586,7 @@ namespace System.Resources { { if (rm == null) { - throw new ArgumentNullException("rm"); + throw new ArgumentNullException(nameof(rm)); } _rm = rm; } diff --git a/src/mscorlib/src/System/Resources/ResourceReader.cs b/src/mscorlib/src/System/Resources/ResourceReader.cs index a269d5c5fe..64b0f0b349 100644 --- a/src/mscorlib/src/System/Resources/ResourceReader.cs +++ b/src/mscorlib/src/System/Resources/ResourceReader.cs @@ -176,7 +176,7 @@ namespace System.Resources { public ResourceReader(Stream stream) { if (stream==null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); if (!stream.CanRead) throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable")); Contract.EndContractBlock(); @@ -1165,7 +1165,7 @@ namespace System.Resources { public void GetResourceData(String resourceName, out String resourceType, out byte[] resourceData) { if (resourceName == null) - throw new ArgumentNullException("resourceName"); + throw new ArgumentNullException(nameof(resourceName)); Contract.EndContractBlock(); if (_resCache == null) throw new InvalidOperationException(Environment.GetResourceString("ResourceReaderIsClosed")); diff --git a/src/mscorlib/src/System/Resources/ResourceSet.cs b/src/mscorlib/src/System/Resources/ResourceSet.cs index ccaba23d33..314cb8d332 100644 --- a/src/mscorlib/src/System/Resources/ResourceSet.cs +++ b/src/mscorlib/src/System/Resources/ResourceSet.cs @@ -111,7 +111,7 @@ namespace System.Resources { public ResourceSet(IResourceReader reader) { if (reader == null) - throw new ArgumentNullException("reader"); + throw new ArgumentNullException(nameof(reader)); Contract.EndContractBlock(); Reader = reader; CommonInit(); @@ -122,7 +122,7 @@ namespace System.Resources { public ResourceSet(IResourceReader reader, Assembly assembly) { if (reader == null) - throw new ArgumentNullException("reader"); + throw new ArgumentNullException(nameof(reader)); Contract.EndContractBlock(); Reader = reader; CommonInit(); @@ -293,7 +293,7 @@ namespace System.Resources { private Object GetObjectInternal(String name) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); Hashtable copyOfTable = Table; // Avoid a race with Dispose diff --git a/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs b/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs index 6b512bcf6a..7c7414c8fb 100644 --- a/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs +++ b/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs @@ -285,7 +285,7 @@ namespace System.Resources { private Object GetObject(String key, bool ignoreCase, bool isString) { if (key==null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); if (Reader == null || _resCache == null) throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs b/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs index f72e810227..327279062a 100644 --- a/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs +++ b/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs @@ -27,7 +27,7 @@ namespace System.Resources { public SatelliteContractVersionAttribute(String version) { if (version == null) - throw new ArgumentNullException("version"); + throw new ArgumentNullException(nameof(version)); Contract.EndContractBlock(); _version = version; } diff --git a/src/mscorlib/src/System/RtType.cs b/src/mscorlib/src/System/RtType.cs index 037576fc33..0ca3162767 100644 --- a/src/mscorlib/src/System/RtType.cs +++ b/src/mscorlib/src/System/RtType.cs @@ -1869,7 +1869,7 @@ namespace System ref StackCrawlMark stackMark) { if (typeName == null) - throw new ArgumentNullException("typeName"); + throw new ArgumentNullException(nameof(typeName)); Contract.EndContractBlock(); return RuntimeTypeHandle.GetTypeByName( @@ -2921,13 +2921,13 @@ namespace System throw new InvalidOperationException(Environment.GetResourceString("Arg_GenericParameter")); if ((object)ifaceType == null) - throw new ArgumentNullException("ifaceType"); + throw new ArgumentNullException(nameof(ifaceType)); Contract.EndContractBlock(); RuntimeType ifaceRtType = ifaceType as RuntimeType; if (ifaceRtType == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "ifaceType"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(ifaceType)); RuntimeTypeHandle ifaceRtTypeHandle = ifaceRtType.GetTypeHandleInternal(); @@ -3446,7 +3446,7 @@ namespace System public override bool IsSubclassOf(Type type) { if ((object)type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); RuntimeType rtType = type as RuntimeType; if (rtType == null) @@ -3862,7 +3862,7 @@ namespace System public override bool IsEnumDefined(object value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Check if both of them are of the same type @@ -3909,13 +3909,13 @@ namespace System public override string GetEnumName(object value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); Type valueType = value.GetType(); if (!(valueType.IsEnum || IsIntegerType(valueType))) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), nameof(value)); ulong ulValue = Enum.ToUInt64(value); @@ -3943,7 +3943,7 @@ namespace System public override Type MakeGenericType(Type[] instantiation) { if (instantiation == null) - throw new ArgumentNullException("instantiation"); + throw new ArgumentNullException(nameof(instantiation)); Contract.EndContractBlock(); RuntimeType[] instantiationRuntimeType = new RuntimeType[instantiation.Length]; @@ -3953,7 +3953,7 @@ namespace System Environment.GetResourceString("Arg_NotGenericTypeDefinition", this)); if (GetGenericArguments().Length != instantiation.Length) - throw new ArgumentException(Environment.GetResourceString("Argument_GenericArgsCount"), "instantiation"); + throw new ArgumentException(Environment.GetResourceString("Argument_GenericArgsCount"), nameof(instantiation)); for (int i = 0; i < instantiation.Length; i ++) { @@ -4260,7 +4260,7 @@ namespace System #region Preconditions if ((bindingFlags & InvocationMask) == 0) // "Must specify binding flags describing the invoke operation required." - throw new ArgumentException(Environment.GetResourceString("Arg_NoAccessSpec"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_NoAccessSpec"),nameof(bindingFlags)); // Provide a default binding mask if none is provided if ((bindingFlags & MemberBindingMask) == 0) @@ -4278,13 +4278,13 @@ namespace System { if (namedParams.Length > providedArgs.Length) // "Named parameter array can not be bigger than argument array." - throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamTooBig"), "namedParams"); + throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamTooBig"), nameof(namedParams)); } else { if (namedParams.Length != 0) // "Named parameter array can not be bigger than argument array." - throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamTooBig"), "namedParams"); + throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamTooBig"), nameof(namedParams)); } } #endregion @@ -4295,22 +4295,22 @@ namespace System { #region Preconditions if ((bindingFlags & ClassicBindingMask) == 0) - throw new ArgumentException(Environment.GetResourceString("Arg_COMAccess"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_COMAccess"), nameof(bindingFlags)); if ((bindingFlags & BindingFlags.GetProperty) != 0 && (bindingFlags & ClassicBindingMask & ~(BindingFlags.GetProperty | BindingFlags.InvokeMethod)) != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_PropSetGet"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_PropSetGet"), nameof(bindingFlags)); if ((bindingFlags & BindingFlags.InvokeMethod) != 0 && (bindingFlags & ClassicBindingMask & ~(BindingFlags.GetProperty | BindingFlags.InvokeMethod)) != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_PropSetInvoke"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_PropSetInvoke"), nameof(bindingFlags)); if ((bindingFlags & BindingFlags.SetProperty) != 0 && (bindingFlags & ClassicBindingMask & ~BindingFlags.SetProperty) != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_COMPropSetPut"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_COMPropSetPut"), nameof(bindingFlags)); if ((bindingFlags & BindingFlags.PutDispProperty) != 0 && (bindingFlags & ClassicBindingMask & ~BindingFlags.PutDispProperty) != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_COMPropSetPut"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_COMPropSetPut"), nameof(bindingFlags)); if ((bindingFlags & BindingFlags.PutRefDispProperty) != 0 && (bindingFlags & ClassicBindingMask & ~BindingFlags.PutRefDispProperty) != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_COMPropSetPut"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_COMPropSetPut"), nameof(bindingFlags)); #endregion #if FEATURE_REMOTING @@ -4319,7 +4319,7 @@ namespace System { #region Non-TransparentProxy case if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); bool[] isByRef = modifiers == null ? null : modifiers[0].IsByRefArray; @@ -4344,7 +4344,7 @@ namespace System #region Check that any named paramters are not null if (namedParams != null && Array.IndexOf(namedParams, null) != -1) // "Named parameter value must not be null." - throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamNull"),"namedParams"); + throw new ArgumentException(Environment.GetResourceString("Arg_NamedParamNull"),nameof(namedParams)); #endregion int argCnt = (providedArgs != null) ? providedArgs.Length : 0; @@ -4361,7 +4361,7 @@ namespace System { if ((bindingFlags & BindingFlags.CreateInstance) != 0 && (bindingFlags & BinderNonCreateInstance) != 0) // "Can not specify both CreateInstance and another access type." - throw new ArgumentException(Environment.GetResourceString("Arg_CreatInstAccess"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_CreatInstAccess"),nameof(bindingFlags)); return Activator.CreateInstance(this, bindingFlags, binder, providedArgs, culture); } @@ -4373,7 +4373,7 @@ namespace System #region Name if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (name.Length == 0 || name.Equals(@"[DISPID=0]")) { @@ -4398,26 +4398,26 @@ namespace System { if (IsSetField) // "Can not specify both Get and Set on a field." - throw new ArgumentException(Environment.GetResourceString("Arg_FldSetGet"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_FldSetGet"),nameof(bindingFlags)); if ((bindingFlags & BindingFlags.SetProperty) != 0) // "Can not specify both GetField and SetProperty." - throw new ArgumentException(Environment.GetResourceString("Arg_FldGetPropSet"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_FldGetPropSet"),nameof(bindingFlags)); } else { Contract.Assert(IsSetField); if (providedArgs == null) - throw new ArgumentNullException("providedArgs"); + throw new ArgumentNullException(nameof(providedArgs)); if ((bindingFlags & BindingFlags.GetProperty) != 0) // "Can not specify both SetField and GetProperty." - throw new ArgumentException(Environment.GetResourceString("Arg_FldSetPropGet"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_FldSetPropGet"),nameof(bindingFlags)); if ((bindingFlags & BindingFlags.InvokeMethod) != 0) // "Can not specify Set on a Field and Invoke on a method." - throw new ArgumentException(Environment.GetResourceString("Arg_FldSetInvoke"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_FldSetInvoke"),nameof(bindingFlags)); } #endregion @@ -4491,7 +4491,7 @@ namespace System { #region Get the field value if (argCnt != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_FldGetArgErr"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_FldGetArgErr"),nameof(bindingFlags)); return selFld.GetValue(target); #endregion @@ -4500,7 +4500,7 @@ namespace System { #region Set the field Value if (argCnt != 1) - throw new ArgumentException(Environment.GetResourceString("Arg_FldSetArgErr"),"bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_FldSetArgErr"),nameof(bindingFlags)); selFld.SetValue(target,providedArgs[0],bindingFlags,binder,culture); @@ -4551,7 +4551,7 @@ namespace System Contract.Assert(!IsSetField); if (isSetProperty) - throw new ArgumentException(Environment.GetResourceString("Arg_PropSetGet"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_PropSetGet"), nameof(bindingFlags)); } else { @@ -4560,7 +4560,7 @@ namespace System Contract.Assert(!IsGetField); if ((bindingFlags & BindingFlags.InvokeMethod) != 0) - throw new ArgumentException(Environment.GetResourceString("Arg_PropSetInvoke"), "bindingFlags"); + throw new ArgumentException(Environment.GetResourceString("Arg_PropSetInvoke"), nameof(bindingFlags)); } #endregion } @@ -4756,7 +4756,7 @@ namespace System public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); UnitySerializationHolder.GetUnitySerializationInfo(info, this); @@ -4774,13 +4774,13 @@ namespace System public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { if ((object)attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.GetCustomAttributes(this, attributeRuntimeType, inherit); } @@ -4789,13 +4789,13 @@ namespace System public override bool IsDefined(Type attributeType, bool inherit) { if ((object)attributeType == null) - throw new ArgumentNullException("attributeType"); + throw new ArgumentNullException(nameof(attributeType)); Contract.EndContractBlock(); RuntimeType attributeRuntimeType = attributeType.UnderlyingSystemType as RuntimeType; if (attributeRuntimeType == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),"attributeType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"),nameof(attributeType)); return CustomAttribute.IsDefined(this, attributeRuntimeType, inherit); } diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index 05850605b8..11f5327495 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -66,7 +66,7 @@ namespace System.Runtime.CompilerServices // See comment on AsyncMethodBuilderCore.Start // AsyncMethodBuilderCore.Start(ref stateMachine); - if (stateMachine == null) throw new ArgumentNullException("stateMachine"); + if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine)); Contract.EndContractBlock(); // Run the MoveNext method within a copy-on-write ExecutionContext scope. @@ -200,7 +200,7 @@ namespace System.Runtime.CompilerServices /// <exception cref="System.InvalidOperationException">The builder is not initialized.</exception> public void SetException(Exception exception) { - if (exception == null) throw new ArgumentNullException("exception"); + if (exception == null) throw new ArgumentNullException(nameof(exception)); Contract.EndContractBlock(); if (AsyncCausalityTracer.LoggingOn) @@ -301,7 +301,7 @@ namespace System.Runtime.CompilerServices // See comment on AsyncMethodBuilderCore.Start // AsyncMethodBuilderCore.Start(ref stateMachine); - if (stateMachine == null) throw new ArgumentNullException("stateMachine"); + if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine)); Contract.EndContractBlock(); // Run the MoveNext method within a copy-on-write ExecutionContext scope. @@ -457,7 +457,7 @@ namespace System.Runtime.CompilerServices // See comment on AsyncMethodBuilderCore.Start // AsyncMethodBuilderCore.Start(ref stateMachine); - if (stateMachine == null) throw new ArgumentNullException("stateMachine"); + if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine)); Contract.EndContractBlock(); // Run the MoveNext method within a copy-on-write ExecutionContext scope. @@ -650,7 +650,7 @@ namespace System.Runtime.CompilerServices /// <exception cref="System.InvalidOperationException">The task has already completed.</exception> public void SetException(Exception exception) { - if (exception == null) throw new ArgumentNullException("exception"); + if (exception == null) throw new ArgumentNullException(nameof(exception)); Contract.EndContractBlock(); @@ -859,7 +859,7 @@ namespace System.Runtime.CompilerServices internal static void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine { - if (stateMachine == null) throw new ArgumentNullException("stateMachine"); + if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine)); Contract.EndContractBlock(); // Run the MoveNext method within a copy-on-write ExecutionContext scope. @@ -887,7 +887,7 @@ namespace System.Runtime.CompilerServices /// <exception cref="System.InvalidOperationException">The builder is incorrectly initialized.</exception> public void SetStateMachine(IAsyncStateMachine stateMachine) { - if (stateMachine == null) throw new ArgumentNullException("stateMachine"); + if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine)); Contract.EndContractBlock(); if (m_stateMachine != null) throw new InvalidOperationException(Environment.GetResourceString("AsyncMethodBuilder_InstanceNotInitialized")); m_stateMachine = stateMachine; diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs b/src/mscorlib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs index 21d677241d..5531e4ad99 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs @@ -231,7 +231,7 @@ namespace System.Runtime.CompilerServices if (createValueCallback == null) { - throw new ArgumentNullException("createValueCallback"); + throw new ArgumentNullException(nameof(createValueCallback)); } TValue existingValue; diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/FormattableStringFactory.cs b/src/mscorlib/src/System/Runtime/CompilerServices/FormattableStringFactory.cs index aee3bc2230..4b99a8a5d9 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/FormattableStringFactory.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/FormattableStringFactory.cs @@ -26,12 +26,12 @@ namespace System.Runtime.CompilerServices { if (format == null) { - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); } if (arguments == null) { - throw new ArgumentNullException("arguments"); + throw new ArgumentNullException(nameof(arguments)); } return new ConcreteFormattableString(format, arguments); diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/RuntimeWrappedException.cs b/src/mscorlib/src/System/Runtime/CompilerServices/RuntimeWrappedException.cs index 2751d61db7..8eb7435f23 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/RuntimeWrappedException.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/RuntimeWrappedException.cs @@ -36,7 +36,7 @@ namespace System.Runtime.CompilerServices { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs index ea6bb96e16..874895f088 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs @@ -205,7 +205,7 @@ namespace System.Runtime.CompilerServices [SecurityCritical] internal static void OnCompletedInternal(Task task, Action continuation, bool continueOnCapturedContext, bool flowExecutionContext) { - if (continuation == null) throw new ArgumentNullException("continuation"); + if (continuation == null) throw new ArgumentNullException(nameof(continuation)); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; // If TaskWait* ETW events are enabled, trace a beginning event for this await diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/TypeDependencyAttribute.cs b/src/mscorlib/src/System/Runtime/CompilerServices/TypeDependencyAttribute.cs index db04eb9348..2de9c1f785 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/TypeDependencyAttribute.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/TypeDependencyAttribute.cs @@ -17,7 +17,7 @@ namespace System.Runtime.CompilerServices public TypeDependencyAttribute (string typeName) { - if(typeName == null) throw new ArgumentNullException("typeName"); + if(typeName == null) throw new ArgumentNullException(nameof(typeName)); Contract.EndContractBlock(); this.typeName = typeName; } diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs b/src/mscorlib/src/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs index c1656dcf99..671d1f0071 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/TypeForwardedFromAttribute.cs @@ -20,7 +20,7 @@ namespace System.Runtime.CompilerServices { if (String.IsNullOrEmpty(assemblyFullName)) { - throw new ArgumentNullException("assemblyFullName"); + throw new ArgumentNullException(nameof(assemblyFullName)); } this.assemblyFullName = assemblyFullName; } diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs b/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs index b29b39c5bf..dec33885d4 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/YieldAwaitable.cs @@ -81,7 +81,7 @@ namespace System.Runtime.CompilerServices private static void QueueContinuation(Action continuation, bool flowContext) { // Validate arguments - if (continuation == null) throw new ArgumentNullException("continuation"); + if (continuation == null) throw new ArgumentNullException(nameof(continuation)); Contract.EndContractBlock(); if (TplEtwProvider.Log.IsEnabled()) diff --git a/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs b/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs index 7251d901cd..905f12dfb5 100644 --- a/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs +++ b/src/mscorlib/src/System/Runtime/ExceptionServices/ExceptionServicesCommon.cs @@ -101,7 +101,7 @@ namespace System.Runtime.ExceptionServices { { if (source == null) { - throw new ArgumentNullException("source", Environment.GetResourceString("ArgumentNull_Obj")); + throw new ArgumentNullException(nameof(source), Environment.GetResourceString("ArgumentNull_Obj")); } return new ExceptionDispatchInfo(source); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/CurrencyWrapper.cs b/src/mscorlib/src/System/Runtime/InteropServices/CurrencyWrapper.cs index 1f7a9f18bf..470e7b20dd 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/CurrencyWrapper.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/CurrencyWrapper.cs @@ -27,7 +27,7 @@ namespace System.Runtime.InteropServices { public CurrencyWrapper(Object obj) { if (!(obj is Decimal)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDecimal"), "obj"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDecimal"), nameof(obj)); m_WrappedObject = (Decimal)obj; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/ErrorWrapper.cs b/src/mscorlib/src/System/Runtime/InteropServices/ErrorWrapper.cs index d63d69cabd..aebc858f17 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/ErrorWrapper.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/ErrorWrapper.cs @@ -28,7 +28,7 @@ namespace System.Runtime.InteropServices { public ErrorWrapper(Object errorCode) { if (!(errorCode is int)) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeInt32"), "errorCode"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeInt32"), nameof(errorCode)); m_ErrorCode = (int)errorCode; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs b/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs index 58fea97cb8..f1a88040c2 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs @@ -62,7 +62,7 @@ namespace System.Runtime.InteropServices { // Make sure the type parameter is within the valid range for the enum. if ((uint)type > (uint)MaxHandleType) - throw new ArgumentOutOfRangeException("type", Environment.GetResourceString("ArgumentOutOfRange_Enum")); + throw new ArgumentOutOfRangeException(nameof(type), Environment.GetResourceString("ArgumentOutOfRange_Enum")); Contract.EndContractBlock(); m_handle = InternalAlloc(value, type); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs b/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs index 7497c244d4..c212b2dc6e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs @@ -141,9 +141,9 @@ namespace System.Runtime.InteropServices unsafe public static String PtrToStringAnsi(IntPtr ptr, int len) { if (ptr == IntPtr.Zero) - throw new ArgumentNullException("ptr"); + throw new ArgumentNullException(nameof(ptr)); if (len < 0) - throw new ArgumentException("len"); + throw new ArgumentException(null, nameof(len)); return new String((sbyte *)ptr, 0, len); } @@ -152,9 +152,9 @@ namespace System.Runtime.InteropServices unsafe public static String PtrToStringUni(IntPtr ptr, int len) { if (ptr == IntPtr.Zero) - throw new ArgumentNullException("ptr"); + throw new ArgumentNullException(nameof(ptr)); if (len < 0) - throw new ArgumentException("len"); + throw new ArgumentException(null, nameof(len)); return new String((char *)ptr, 0, len); } @@ -199,7 +199,7 @@ namespace System.Runtime.InteropServices { if (byteLen < 0) { - throw new ArgumentException("byteLen"); + throw new ArgumentException(null, nameof(byteLen)); } else if (IntPtr.Zero == ptr) { @@ -227,7 +227,7 @@ namespace System.Runtime.InteropServices public static int SizeOf(Object structure) { if (structure == null) - throw new ArgumentNullException("structure"); + throw new ArgumentNullException(nameof(structure)); // we never had a check for generics here Contract.EndContractBlock(); @@ -243,11 +243,11 @@ namespace System.Runtime.InteropServices public static int SizeOf(Type t) { if (t == null) - throw new ArgumentNullException("t"); + throw new ArgumentNullException(nameof(t)); if (!(t is RuntimeType)) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(t)); if (t.IsGenericType) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(t)); Contract.EndContractBlock(); return SizeOfHelper(t, true); @@ -302,15 +302,15 @@ namespace System.Runtime.InteropServices public static IntPtr OffsetOf(Type t, String fieldName) { if (t == null) - throw new ArgumentNullException("t"); + throw new ArgumentNullException(nameof(t)); Contract.EndContractBlock(); FieldInfo f = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (f == null) - throw new ArgumentException(Environment.GetResourceString("Argument_OffsetOfFieldNotFound", t.FullName), "fieldName"); + throw new ArgumentException(Environment.GetResourceString("Argument_OffsetOfFieldNotFound", t.FullName), nameof(fieldName)); RtFieldInfo rtField = f as RtFieldInfo; if (rtField == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), "fieldName"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), nameof(fieldName)); return OffsetOfHelper(rtField); } @@ -915,7 +915,7 @@ namespace System.Runtime.InteropServices public static void Prelink(MethodInfo m) { if (m == null) - throw new ArgumentNullException("m"); + throw new ArgumentNullException(nameof(m)); Contract.EndContractBlock(); RuntimeMethodInfo rmi = m as RuntimeMethodInfo; @@ -934,7 +934,7 @@ namespace System.Runtime.InteropServices public static void PrelinkAll(Type c) { if (c == null) - throw new ArgumentNullException("c"); + throw new ArgumentNullException(nameof(c)); Contract.EndContractBlock(); MethodInfo[] mi = c.GetMethods(); @@ -954,7 +954,7 @@ namespace System.Runtime.InteropServices public static int NumParamBytes(MethodInfo m) { if (m == null) - throw new ArgumentNullException("m"); + throw new ArgumentNullException(nameof(m)); Contract.EndContractBlock(); RuntimeMethodInfo rmi = m as RuntimeMethodInfo; @@ -1027,15 +1027,15 @@ namespace System.Runtime.InteropServices if (ptr == IntPtr.Zero) return null; if (structureType == null) - throw new ArgumentNullException("structureType"); + throw new ArgumentNullException(nameof(structureType)); if (structureType.IsGenericType) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "structureType"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(structureType)); RuntimeType rt = structureType.UnderlyingSystemType as RuntimeType; if (rt == null) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), nameof(structureType)); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1082,7 +1082,7 @@ namespace System.Runtime.InteropServices public static IntPtr GetHINSTANCE(Module m) { if (m == null) - throw new ArgumentNullException("m"); + throw new ArgumentNullException(nameof(m)); Contract.EndContractBlock(); RuntimeModule rtModule = m as RuntimeModule; @@ -1094,7 +1094,7 @@ namespace System.Runtime.InteropServices } if (rtModule == null) - throw new ArgumentNullException("m",Environment.GetResourceString("Argument_MustBeRuntimeModule")); + throw new ArgumentNullException(nameof(m),Environment.GetResourceString("Argument_MustBeRuntimeModule")); return GetHINSTANCE(rtModule.GetNativeHandle()); } @@ -1178,7 +1178,7 @@ namespace System.Runtime.InteropServices public static Thread GetThreadFromFiberCookie(int cookie) { if (cookie == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_ArgumentZero"), "cookie"); + throw new ArgumentException(Environment.GetResourceString("Argument_ArgumentZero"), nameof(cookie)); Contract.EndContractBlock(); return InternalGetThreadFromFiberCookie(cookie); @@ -1261,7 +1261,7 @@ namespace System.Runtime.InteropServices // Overflow checking if (nb < s.Length) - throw new ArgumentOutOfRangeException("s"); + throw new ArgumentOutOfRangeException(nameof(s)); UIntPtr len = new UIntPtr((uint)nb); IntPtr hglobal = Win32Native.LocalAlloc_NoSafeHandle(LMEM_FIXED, len); @@ -1291,7 +1291,7 @@ namespace System.Runtime.InteropServices // Overflow checking if (nb < s.Length) - throw new ArgumentOutOfRangeException("s"); + throw new ArgumentOutOfRangeException(nameof(s)); UIntPtr len = new UIntPtr((uint)nb); IntPtr hglobal = Win32Native.LocalAlloc_NoSafeHandle(LMEM_FIXED, len); @@ -1358,7 +1358,7 @@ namespace System.Runtime.InteropServices public static String GetTypeLibName(ITypeLib typelib) { if (typelib == null) - throw new ArgumentNullException("typelib"); + throw new ArgumentNullException(nameof(typelib)); Contract.EndContractBlock(); String strTypeLibName = null; @@ -1379,7 +1379,7 @@ namespace System.Runtime.InteropServices internal static String GetTypeLibNameInternal(ITypeLib typelib) { if (typelib == null) - throw new ArgumentNullException("typelib"); + throw new ArgumentNullException(nameof(typelib)); Contract.EndContractBlock(); // Try GUID_ManagedName first @@ -1484,12 +1484,12 @@ namespace System.Runtime.InteropServices public static Guid GetTypeLibGuidForAssembly(Assembly asm) { if (asm == null) - throw new ArgumentNullException("asm"); + throw new ArgumentNullException(nameof(asm)); Contract.EndContractBlock(); RuntimeAssembly rtAssembly = asm as RuntimeAssembly; if (rtAssembly == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "asm"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(asm)); Guid result = new Guid(); FCallGetTypeLibGuidForAssembly(ref result, rtAssembly); @@ -1510,12 +1510,12 @@ namespace System.Runtime.InteropServices public static void GetTypeLibVersionForAssembly(Assembly inputAssembly, out int majorVersion, out int minorVersion) { if (inputAssembly == null) - throw new ArgumentNullException("inputAssembly"); + throw new ArgumentNullException(nameof(inputAssembly)); Contract.EndContractBlock(); RuntimeAssembly rtAssembly = inputAssembly as RuntimeAssembly; if (rtAssembly == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "inputAssembly"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(inputAssembly)); _GetTypeLibVersionForAssembly(rtAssembly, out majorVersion, out minorVersion); } @@ -1537,7 +1537,7 @@ namespace System.Runtime.InteropServices public static String GetTypeInfoName(ITypeInfo typeInfo) { if (typeInfo == null) - throw new ArgumentNullException("typeInfo"); + throw new ArgumentNullException(nameof(typeInfo)); Contract.EndContractBlock(); String strTypeLibName = null; @@ -1558,7 +1558,7 @@ namespace System.Runtime.InteropServices internal static String GetTypeInfoNameInternal(ITypeInfo typeInfo, out bool hasManagedName) { if (typeInfo == null) - throw new ArgumentNullException("typeInfo"); + throw new ArgumentNullException(nameof(typeInfo)); Contract.EndContractBlock(); // Try ManagedNameGuid first @@ -1893,7 +1893,7 @@ namespace System.Runtime.InteropServices // Overflow checking if (nb < s.Length) - throw new ArgumentOutOfRangeException("s"); + throw new ArgumentOutOfRangeException(nameof(s)); IntPtr hglobal = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)nb)); @@ -1926,7 +1926,7 @@ namespace System.Runtime.InteropServices // Overflow checking if (nb < s.Length) - throw new ArgumentOutOfRangeException("s"); + throw new ArgumentOutOfRangeException(nameof(s)); IntPtr pMem = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)nb +1)); @@ -1964,7 +1964,7 @@ namespace System.Runtime.InteropServices // Overflow checking if (nb < s.Length) - throw new ArgumentOutOfRangeException("s"); + throw new ArgumentOutOfRangeException(nameof(s)); IntPtr hglobal = Win32Native.CoTaskMemAlloc(new UIntPtr((uint)nb)); @@ -2019,7 +2019,7 @@ namespace System.Runtime.InteropServices // Overflow checking if (s.Length + 1 < s.Length) - throw new ArgumentOutOfRangeException("s"); + throw new ArgumentOutOfRangeException(nameof(s)); IntPtr bstr = Win32Native.SysAllocStringLen(s, s.Length); if (bstr == IntPtr.Zero) @@ -2051,7 +2051,7 @@ namespace System.Runtime.InteropServices } catch (InvalidCastException) { - throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "o"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(o)); } return co.ReleaseSelf(); @@ -2069,7 +2069,7 @@ namespace System.Runtime.InteropServices public static Int32 FinalReleaseComObject(Object o) { if (o == null) - throw new ArgumentNullException("o"); + throw new ArgumentNullException(nameof(o)); Contract.EndContractBlock(); __ComObject co = null; @@ -2081,7 +2081,7 @@ namespace System.Runtime.InteropServices } catch (InvalidCastException) { - throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "o"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(o)); } co.FinalReleaseSelf(); @@ -2104,9 +2104,9 @@ namespace System.Runtime.InteropServices #else // Validate that the arguments aren't null. if (obj == null) - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); __ComObject comObj = null; @@ -2118,12 +2118,12 @@ namespace System.Runtime.InteropServices } catch (InvalidCastException) { - throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "obj"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(obj)); } if (obj.GetType().IsWindowsRuntimeObject) { - throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), "obj"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), nameof(obj)); } // Retrieve the data from the __ComObject. @@ -2145,9 +2145,9 @@ namespace System.Runtime.InteropServices #else // Validate that the arguments aren't null. The data can validly be null. if (obj == null) - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); __ComObject comObj = null; @@ -2159,12 +2159,12 @@ namespace System.Runtime.InteropServices } catch (InvalidCastException) { - throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "obj"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(obj)); } if (obj.GetType().IsWindowsRuntimeObject) { - throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), "obj"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), nameof(obj)); } // Retrieve the data from the __ComObject. @@ -2182,15 +2182,15 @@ namespace System.Runtime.InteropServices { // Validate the arguments. if (t == null) - throw new ArgumentNullException("t"); + throw new ArgumentNullException(nameof(t)); if (!t.IsCOMObject) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotComObject"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotComObject"), nameof(t)); if (t.IsGenericType) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(t)); Contract.EndContractBlock(); if (t.IsWindowsRuntimeObject) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeIsWinRTType"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeIsWinRTType"), nameof(t)); // Check for the null case. if (o == null) @@ -2198,9 +2198,9 @@ namespace System.Runtime.InteropServices // Make sure the object is a COM object. if (!o.GetType().IsCOMObject) - throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), "o"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjNotComObject"), nameof(o)); if (o.GetType().IsWindowsRuntimeObject) - throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), "o"); + throw new ArgumentException(Environment.GetResourceString("Argument_ObjIsWinRTObject"), nameof(o)); // Check to see if the type of the object is the requested type. if (o.GetType() == t) @@ -2342,15 +2342,15 @@ namespace System.Runtime.InteropServices public static int GetComSlotForMethodInfo(MemberInfo m) { if (m== null) - throw new ArgumentNullException("m"); + throw new ArgumentNullException(nameof(m)); if (!(m is RuntimeMethodInfo)) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "m"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(m)); if (!m.DeclaringType.IsInterface) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeInterfaceMethod"), "m"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeInterfaceMethod"), nameof(m)); if (m.DeclaringType.IsGenericType) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "m"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(m)); Contract.EndContractBlock(); return InternalGetComSlotForMethodInfo((IRuntimeMethodInfo)m); @@ -2396,15 +2396,15 @@ namespace System.Runtime.InteropServices throw new PlatformNotSupportedException(); #else if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (type.IsImport) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustNotBeComImport"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustNotBeComImport"), nameof(type)); if (type.IsGenericType) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(type)); Contract.EndContractBlock(); if (!RegistrationServices.TypeRequiresRegistrationHelper(type)) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"), nameof(type)); IList<CustomAttributeData> cas = CustomAttributeData.GetCustomAttributes(type); for (int i = 0; i < cas.Count; i ++) @@ -2644,21 +2644,21 @@ namespace System.Runtime.InteropServices { // Validate the parameters if (ptr == IntPtr.Zero) - throw new ArgumentNullException("ptr"); + throw new ArgumentNullException(nameof(ptr)); if (t == null) - throw new ArgumentNullException("t"); + throw new ArgumentNullException(nameof(t)); Contract.EndContractBlock(); if ((t as RuntimeType) == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"), nameof(t)); if (t.IsGenericType) - throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), "t"); + throw new ArgumentException(Environment.GetResourceString("Argument_NeedNonGenericType"), nameof(t)); Type c = t.BaseType; if (c == null || (c != typeof(Delegate) && c != typeof(MulticastDelegate))) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), "t"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeDelegate"), nameof(t)); return GetDelegateForFunctionPointerInternal(ptr, t); } @@ -2676,7 +2676,7 @@ namespace System.Runtime.InteropServices public static IntPtr GetFunctionPointerForDelegate(Delegate d) { if (d == null) - throw new ArgumentNullException("d"); + throw new ArgumentNullException(nameof(d)); Contract.EndContractBlock(); return GetFunctionPointerForDelegateInternal(d); @@ -2697,7 +2697,7 @@ namespace System.Runtime.InteropServices [System.Security.SecurityCritical] // auto-generated_required public static IntPtr SecureStringToBSTR(SecureString s) { if( s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } Contract.EndContractBlock(); @@ -2708,7 +2708,7 @@ namespace System.Runtime.InteropServices [System.Security.SecurityCritical] // auto-generated_required public static IntPtr SecureStringToCoTaskMemAnsi(SecureString s) { if( s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } Contract.EndContractBlock(); @@ -2720,7 +2720,7 @@ namespace System.Runtime.InteropServices { if (s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } Contract.EndContractBlock(); @@ -2764,7 +2764,7 @@ namespace System.Runtime.InteropServices [System.Security.SecurityCritical] // auto-generated_required public static IntPtr SecureStringToGlobalAllocAnsi(SecureString s) { if( s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } Contract.EndContractBlock(); @@ -2774,7 +2774,7 @@ namespace System.Runtime.InteropServices [System.Security.SecurityCritical] // auto-generated_required public static IntPtr SecureStringToGlobalAllocUnicode(SecureString s) { if( s == null) { - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/RegistrationServices.cs b/src/mscorlib/src/System/Runtime/InteropServices/RegistrationServices.cs index 7d3670d877..9fd818dbad 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/RegistrationServices.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/RegistrationServices.cs @@ -96,7 +96,7 @@ namespace System.Runtime.InteropServices { { // Validate the arguments. if (assembly == null) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); if (assembly.ReflectionOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsmLoadedForReflectionOnly")); @@ -159,7 +159,7 @@ namespace System.Runtime.InteropServices { { // Validate the arguments. if (assembly == null) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); if (assembly.ReflectionOnly) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AsmLoadedForReflectionOnly")); @@ -219,11 +219,11 @@ namespace System.Runtime.InteropServices { { // Validate the arguments. if (assembly == null) - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); Contract.EndContractBlock(); if (!(assembly is RuntimeAssembly)) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(assembly)); // Retrieve the list of types in the assembly. Type[] aTypes = assembly.GetExportedTypes(); @@ -257,12 +257,12 @@ namespace System.Runtime.InteropServices { { #if FEATURE_COMINTEROP_MANAGED_ACTIVATION if(type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); if((type as RuntimeType) == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"),"type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"),nameof(type)); if(!TypeRequiresRegistration(type)) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"),"type"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"),nameof(type)); // Call the native method to do CoRegisterClassObject RegisterTypeForComClientsNative(type, ref g); @@ -313,12 +313,12 @@ namespace System.Runtime.InteropServices { { #if FEATURE_COMINTEROP_MANAGED_ACTIVATION if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); Contract.EndContractBlock(); if ((type as RuntimeType) == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"),"type"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"),nameof(type)); if (!TypeRequiresRegistration(type)) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"),"type"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeMustBeComCreatable"),nameof(type)); // Call the native method to do CoRegisterClassObject return RegisterTypeForComClientsExNative(type, classContext, flags); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs b/src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs index a659daf2b5..0946902bc5 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/SafeBuffer.cs @@ -101,13 +101,13 @@ using System.Diagnostics.Contracts; public void Initialize(ulong numBytes) { if (numBytes < 0) - throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (IntPtr.Size == 4 && numBytes > UInt32.MaxValue) - throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_AddressSpace")); + throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_AddressSpace")); Contract.EndContractBlock(); if (numBytes >= (ulong)Uninitialized) - throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_UIntPtrMax-1")); + throw new ArgumentOutOfRangeException(nameof(numBytes), Environment.GetResourceString("ArgumentOutOfRange_UIntPtrMax-1")); _numBytes = (UIntPtr) numBytes; } @@ -120,16 +120,16 @@ using System.Diagnostics.Contracts; public void Initialize(uint numElements, uint sizeOfEachElement) { if (numElements < 0) - throw new ArgumentOutOfRangeException("numElements", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(numElements), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (sizeOfEachElement < 0) - throw new ArgumentOutOfRangeException("sizeOfEachElement", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(sizeOfEachElement), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (IntPtr.Size == 4 && numElements * sizeOfEachElement > UInt32.MaxValue) throw new ArgumentOutOfRangeException("numBytes", Environment.GetResourceString("ArgumentOutOfRange_AddressSpace")); Contract.EndContractBlock(); if (numElements * sizeOfEachElement >= (ulong)Uninitialized) - throw new ArgumentOutOfRangeException("numElements", Environment.GetResourceString("ArgumentOutOfRange_UIntPtrMax-1")); + throw new ArgumentOutOfRangeException(nameof(numElements), Environment.GetResourceString("ArgumentOutOfRange_UIntPtrMax-1")); _numBytes = checked((UIntPtr) (numElements * sizeOfEachElement)); } @@ -245,11 +245,11 @@ using System.Diagnostics.Contracts; where T : struct { if (array == null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(array), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -317,11 +317,11 @@ using System.Diagnostics.Contracts; where T : struct { if (array == null) - throw new ArgumentNullException("array", Environment.GetResourceString("ArgumentNull_Buffer")); + throw new ArgumentNullException(nameof(array), Environment.GetResourceString("ArgumentNull_Buffer")); if (index < 0) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (array.Length - index < count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/StringBuffer.cs b/src/mscorlib/src/System/Runtime/InteropServices/StringBuffer.cs index 15b1b6ae8e..2046306d0d 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/StringBuffer.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/StringBuffer.cs @@ -65,13 +65,13 @@ namespace System.Runtime.InteropServices [System.Security.SecuritySafeCritical] get { - if (index >= _length) throw new ArgumentOutOfRangeException("index"); + if (index >= _length) throw new ArgumentOutOfRangeException(nameof(index)); return CharPointer[index]; } [System.Security.SecuritySafeCritical] set { - if (index >= _length) throw new ArgumentOutOfRangeException("index"); + if (index >= _length) throw new ArgumentOutOfRangeException(nameof(index)); CharPointer[index] = value; } } @@ -113,7 +113,7 @@ namespace System.Runtime.InteropServices [System.Security.SecuritySafeCritical] set { - if (value == uint.MaxValue) throw new ArgumentOutOfRangeException("Length"); + if (value == uint.MaxValue) throw new ArgumentOutOfRangeException(nameof(Length)); // Null terminate EnsureCharCapacity(value + 1); @@ -174,7 +174,7 @@ namespace System.Runtime.InteropServices [System.Security.SecuritySafeCritical] public bool StartsWith(string value) { - if (value == null) throw new ArgumentNullException("value"); + if (value == null) throw new ArgumentNullException(nameof(value)); if (_length < (uint)value.Length) return false; return SubstringEquals(value, startIndex: 0, count: value.Length); } @@ -193,11 +193,11 @@ namespace System.Runtime.InteropServices public unsafe bool SubstringEquals(string value, uint startIndex = 0, int count = -1) { if (value == null) return false; - if (count < -1) throw new ArgumentOutOfRangeException("count"); - if (startIndex > _length) throw new ArgumentOutOfRangeException("startIndex"); + if (count < -1) throw new ArgumentOutOfRangeException(nameof(count)); + if (startIndex > _length) throw new ArgumentOutOfRangeException(nameof(startIndex)); uint realCount = count == -1 ? _length - startIndex : (uint)count; - if (checked(startIndex + realCount) > _length) throw new ArgumentOutOfRangeException("count"); + if (checked(startIndex + realCount) > _length) throw new ArgumentOutOfRangeException(nameof(count)); int length = value.Length; @@ -249,7 +249,7 @@ namespace System.Runtime.InteropServices /// </exception> public void Append(StringBuffer value, uint startIndex = 0) { - if (value == null) throw new ArgumentNullException("value"); + if (value == null) throw new ArgumentNullException(nameof(value)); if (value.Length == 0) return; value.CopyTo( bufferIndex: startIndex, @@ -271,7 +271,7 @@ namespace System.Runtime.InteropServices /// </exception> public void Append(StringBuffer value, uint startIndex, uint count) { - if (value == null) throw new ArgumentNullException("value"); + if (value == null) throw new ArgumentNullException(nameof(value)); if (count == 0) return; value.CopyTo( bufferIndex: startIndex, @@ -292,10 +292,10 @@ namespace System.Runtime.InteropServices [System.Security.SecuritySafeCritical] public unsafe void CopyTo(uint bufferIndex, StringBuffer destination, uint destinationIndex, uint count) { - if (destination == null) throw new ArgumentNullException("destination"); - if (destinationIndex > destination._length) throw new ArgumentOutOfRangeException("destinationIndex"); - if (bufferIndex >= _length) throw new ArgumentOutOfRangeException("bufferIndex"); - if (_length < checked(bufferIndex + count)) throw new ArgumentOutOfRangeException("count"); + if (destination == null) throw new ArgumentNullException(nameof(destination)); + if (destinationIndex > destination._length) throw new ArgumentOutOfRangeException(nameof(destinationIndex)); + if (bufferIndex >= _length) throw new ArgumentOutOfRangeException(nameof(bufferIndex)); + if (_length < checked(bufferIndex + count)) throw new ArgumentOutOfRangeException(nameof(count)); if (count == 0) return; uint lastIndex = checked(destinationIndex + count); @@ -320,11 +320,11 @@ namespace System.Runtime.InteropServices [System.Security.SecuritySafeCritical] public unsafe void CopyFrom(uint bufferIndex, string source, int sourceIndex = 0, int count = -1) { - if (source == null) throw new ArgumentNullException("source"); - if (bufferIndex > _length) throw new ArgumentOutOfRangeException("bufferIndex"); - if (sourceIndex < 0 || sourceIndex >= source.Length) throw new ArgumentOutOfRangeException("sourceIndex"); + if (source == null) throw new ArgumentNullException(nameof(source)); + if (bufferIndex > _length) throw new ArgumentOutOfRangeException(nameof(bufferIndex)); + if (sourceIndex < 0 || sourceIndex >= source.Length) throw new ArgumentOutOfRangeException(nameof(sourceIndex)); if (count == -1) count = source.Length - sourceIndex; - if (count < 0 || source.Length - count < sourceIndex) throw new ArgumentOutOfRangeException("count"); + if (count < 0 || source.Length - count < sourceIndex) throw new ArgumentOutOfRangeException(nameof(count)); if (count == 0) return; uint lastIndex = bufferIndex + (uint)count; @@ -380,11 +380,11 @@ namespace System.Runtime.InteropServices [System.Security.SecuritySafeCritical] public unsafe string Substring(uint startIndex, int count = -1) { - if (startIndex > (_length == 0 ? 0 : _length - 1)) throw new ArgumentOutOfRangeException("startIndex"); - if (count < -1) throw new ArgumentOutOfRangeException("count"); + if (startIndex > (_length == 0 ? 0 : _length - 1)) throw new ArgumentOutOfRangeException(nameof(startIndex)); + if (count < -1) throw new ArgumentOutOfRangeException(nameof(count)); uint realCount = count == -1 ? _length - startIndex : (uint)count; - if (realCount > int.MaxValue || checked(startIndex + realCount) > _length) throw new ArgumentOutOfRangeException("count"); + if (realCount > int.MaxValue || checked(startIndex + realCount) > _length) throw new ArgumentOutOfRangeException(nameof(count)); if (realCount == 0) return string.Empty; // The buffer could be bigger than will fit into a string, but the substring might fit. As the starting diff --git a/src/mscorlib/src/System/Runtime/InteropServices/TypeLibConverter.cs b/src/mscorlib/src/System/Runtime/InteropServices/TypeLibConverter.cs index e6b148a0a5..629c414d58 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/TypeLibConverter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/TypeLibConverter.cs @@ -88,13 +88,13 @@ namespace System.Runtime.InteropServices { { // Validate the arguments. if (typeLib == null) - throw new ArgumentNullException("typeLib"); + throw new ArgumentNullException(nameof(typeLib)); if (asmFileName == null) - throw new ArgumentNullException("asmFileName"); + throw new ArgumentNullException(nameof(asmFileName)); if (notifySink == null) - throw new ArgumentNullException("notifySink"); + throw new ArgumentNullException(nameof(notifySink)); if (String.Empty.Equals(asmFileName)) - throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "asmFileName"); + throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), nameof(asmFileName)); if (asmFileName.Length > Path.MaxPath) throw new ArgumentException(Environment.GetResourceString("IO.PathTooLong"), asmFileName); if ((flags & TypeLibImporterFlags.PrimaryInteropAssembly) != 0 && publicKey == null && keyPair == null) diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs index 5574f3c251..e9d2cddc41 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs @@ -67,7 +67,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void CopyTo(Array array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); // ICollection expects the destination array to be single-dimensional. if (array.Rank != 1) @@ -79,7 +79,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime int destLen = array.GetLength(0); if (arrayIndex < destLB) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); // Does the dimension in question have sufficient space to copy the expected number of entries? // We perform this check before valid index check to ensure the exception message is in sync with diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs index 73ebf721ee..6ec2933461 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs @@ -35,7 +35,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal object Indexer_Get(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); return GetAt(_this, (uint)index); @@ -46,7 +46,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void Indexer_Set(int index, object value) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); SetAt(_this, (uint)index, value); @@ -127,7 +127,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void Insert(int index, object item) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); InsertAtHelper(_this, (uint)index, item); @@ -158,7 +158,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void RemoveAt(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IBindableVector _this = JitHelpers.UnsafeCast<IBindableVector>(this); RemoveAtHelper(_this, (uint)index); @@ -178,7 +178,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -196,7 +196,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -214,7 +214,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -232,7 +232,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs index af1381c366..a5abb4f23e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs @@ -45,7 +45,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ConstantSplittableMap(IReadOnlyDictionary<TKey, TValue> data) { if (data == null) - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); Contract.EndContractBlock(); this.firstItemIndex = 0; @@ -56,7 +56,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ConstantSplittableMap(IMapView<TKey, TValue> data) { if (data == null) - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); if (((UInt32)Int32.MaxValue) < data.Size) { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs index 04fe1bf9b2..85ebd7120e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs @@ -29,7 +29,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public CustomPropertyImpl(PropertyInfo propertyInfo) { if (propertyInfo == null) - throw new ArgumentNullException("propertyInfo"); + throw new ArgumentNullException(nameof(propertyInfo)); m_property = propertyInfo; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs index c1586ee9ce..c33e002e0e 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs @@ -18,7 +18,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public DictionaryKeyCollection(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -26,9 +26,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime public void CopyTo(TKey[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -90,7 +90,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public DictionaryKeyEnumerator(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs index 03e897a917..fcc7755d67 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs @@ -21,7 +21,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { public DictionaryValueCollection(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -29,9 +29,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime { public void CopyTo(TValue[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -97,7 +97,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { public DictionaryValueEnumerator(IDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs index 3600a3ae70..32bbd3f78b 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs @@ -36,7 +36,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal V Indexer_Get<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); @@ -67,7 +67,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal bool ContainsKey<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); return _this.HasKey(key); @@ -78,7 +78,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal bool TryGetValue<K, V>(K key, out V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMapView<K, V> _this = JitHelpers.UnsafeCast<IMapView<K, V>>(this); @@ -137,7 +137,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryKeyCollection(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -146,9 +146,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime public void CopyTo(TKey[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -192,7 +192,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryKeyEnumerator(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); @@ -232,7 +232,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryValueCollection(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; } @@ -241,9 +241,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime public void CopyTo(TValue[] array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (array.Length <= index && this.Count > 0) throw new ArgumentException(Environment.GetResourceString("Arg_IndexOutOfRangeException")); if (array.Length - index < dictionary.Count) @@ -291,7 +291,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public ReadOnlyDictionaryValueEnumerator(IReadOnlyDictionary<TKey, TValue> dictionary) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); this.dictionary = dictionary; this.enumeration = dictionary.GetEnumerator(); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs index 95780bcb13..c37c32dfa9 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs @@ -130,7 +130,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs index 72d6fa8cc3..bb497ca864 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs @@ -38,7 +38,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal T Indexer_Get<T>(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVectorView<T> _this = JitHelpers.UnsafeCast<IVectorView<T>>(this); @@ -52,7 +52,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs index 35dc495d3f..3cf1d4d0a7 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs @@ -179,7 +179,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs index f760576aaa..2e2ea9b876 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ListToBindableVectorViewAdapter(IList list) { if (list == null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); Contract.EndContractBlock(); @@ -38,7 +38,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs index 77f3a9464f..cb61168845 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs @@ -212,7 +212,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime // that Size > Int32.MaxValue: if (((uint)Int32.MaxValue) <= index || index >= (uint)listCapacity) { - Exception e = new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); + Exception e = new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexLargerThanMaxValue")); e.SetErrorCode(__HResults.E_BOUNDS); throw e; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs index 3e93428d26..cb710ff21a 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs @@ -37,12 +37,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal ManagedActivationFactory(Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); // Check whether the type is "exported to WinRT", i.e. it is declared in a managed .winmd and is decorated // with at least one ActivatableAttribute or StaticAttribute. if (!(type is RuntimeType) || !type.IsExportedToWindowsRuntime) - throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotActivatableViaWindowsRuntime", type), "type"); + throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotActivatableViaWindowsRuntime", type), nameof(type)); m_type = type; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs index 395bef93d5..4517e15501 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs @@ -139,10 +139,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void CopyTo<K, V>(KeyValuePair<K, V>[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); if (array.Length <= arrayIndex && Count<K, V>() > 0) throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds")); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs index d7897ced9f..d032937146 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs @@ -34,7 +34,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal V Indexer_Get<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); @@ -47,7 +47,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void Indexer_Set<K, V>(K key, V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); Contract.EndContractBlock(); @@ -79,7 +79,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal bool ContainsKey<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); return _this.HasKey(key); @@ -90,7 +90,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void Add<K, V>(K key, V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); if (ContainsKey<K, V>(key)) throw new ArgumentException(Environment.GetResourceString("Argument_AddingDuplicate")); @@ -106,7 +106,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal bool Remove<K, V>(K key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); if (!_this.HasKey(key)) @@ -132,7 +132,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal bool TryGetValue<K, V>(K key, out V value) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); IMap<K, V> _this = JitHelpers.UnsafeCast<IMap<K, V>>(this); if (!_this.HasKey(key)) diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs index 5eeb0afcfc..ba29eae233 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs @@ -82,10 +82,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void CopyTo<T>(T[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); if (array.Length <= arrayIndex && Count<T>() > 0) throw new ArgumentException(Environment.GetResourceString("Argument_IndexOutOfArrayBounds")); diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs index f27cc95176..feefe4e927 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs @@ -34,7 +34,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal T Indexer_Get<T>(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); return GetAt(_this, (uint)index); @@ -45,7 +45,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void Indexer_Set<T>(int index, T value) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); SetAt(_this, (uint)index, value); @@ -76,7 +76,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void Insert<T>(int index, T item) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); InsertAtHelper<T>(_this, (uint)index, item); @@ -87,7 +87,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime internal void RemoveAt<T>(int index) { if (index < 0) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); IVector<T> _this = JitHelpers.UnsafeCast<IVector<T>>(this); RemoveAtHelper<T>(_this, (uint)index); @@ -107,7 +107,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -125,7 +125,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -143,7 +143,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } @@ -161,7 +161,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); throw; } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs index 038efd5013..5b04329e81 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs @@ -29,9 +29,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime T handler) { if (addMethod == null) - throw new ArgumentNullException("addMethod"); + throw new ArgumentNullException(nameof(addMethod)); if (removeMethod == null) - throw new ArgumentNullException("removeMethod"); + throw new ArgumentNullException(nameof(removeMethod)); Contract.EndContractBlock(); // Managed code allows adding a null event handler, the effect is a no-op. To match this behavior @@ -58,7 +58,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler) { if (removeMethod == null) - throw new ArgumentNullException("removeMethod"); + throw new ArgumentNullException(nameof(removeMethod)); Contract.EndContractBlock(); // Managed code allows removing a null event handler, the effect is a no-op. To match this behavior @@ -83,7 +83,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod) { if (removeMethod == null) - throw new ArgumentNullException("removeMethod"); + throw new ArgumentNullException(nameof(removeMethod)); Contract.EndContractBlock(); // Delegate to managed event registration implementation or native event registration implementation @@ -1272,7 +1272,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public static IActivationFactory GetActivationFactory(Type type) { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); if (type.IsWindowsRuntimeObject && type.IsImport) { @@ -1298,7 +1298,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_WinRT")); if (s == null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); unsafe { diff --git a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs index e2ad203583..642c4b203f 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs @@ -30,7 +30,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime public static IEnumerable<string> ResolveNamespace(string namespaceName, string windowsSdkFilePath, IEnumerable<string> packageGraphFilePaths) { if (namespaceName == null) - throw new ArgumentNullException("namespaceName"); + throw new ArgumentNullException(nameof(namespaceName)); Contract.EndContractBlock(); string[] packageGraphFilePathsArray = null; diff --git a/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs index 2c0732502e..d46d0d0d88 100644 --- a/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs @@ -101,12 +101,12 @@ namespace System.Runtime.Loader { if (assemblyPath == null) { - throw new ArgumentNullException("assemblyPath"); + throw new ArgumentNullException(nameof(assemblyPath)); } if (Path.IsRelative(assemblyPath)) { - throw new ArgumentException( Environment.GetResourceString("Argument_AbsolutePathRequired"), "assemblyPath"); + throw new ArgumentException( Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(assemblyPath)); } RuntimeAssembly loadedAssembly = null; @@ -118,17 +118,17 @@ namespace System.Runtime.Loader { if (nativeImagePath == null) { - throw new ArgumentNullException("nativeImagePath"); + throw new ArgumentNullException(nameof(nativeImagePath)); } if (Path.IsRelative(nativeImagePath)) { - throw new ArgumentException( Environment.GetResourceString("Argument_AbsolutePathRequired"), "nativeImagePath"); + throw new ArgumentException( Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(nativeImagePath)); } if (assemblyPath != null && Path.IsRelative(assemblyPath)) { - throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), "assemblyPath"); + throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(assemblyPath)); } // Basic validation has succeeded - lets try to load the NI image. @@ -147,7 +147,7 @@ namespace System.Runtime.Loader { if (assembly == null) { - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); } int iAssemblyStreamLength = (int)assembly.Length; @@ -302,15 +302,15 @@ namespace System.Runtime.Loader { if (unmanagedDllPath == null) { - throw new ArgumentNullException("unmanagedDllPath"); + throw new ArgumentNullException(nameof(unmanagedDllPath)); } if (unmanagedDllPath.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), "unmanagedDllPath"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyPath"), nameof(unmanagedDllPath)); } if (Path.IsRelative(unmanagedDllPath)) { - throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), "unmanagedDllPath"); + throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(unmanagedDllPath)); } return InternalLoadUnmanagedDllFromPath(unmanagedDllPath); @@ -366,7 +366,7 @@ namespace System.Runtime.Loader { if (context == null) { - throw new ArgumentNullException("context"); + throw new ArgumentNullException(nameof(context)); } // Try to override the default assembly load context @@ -389,7 +389,7 @@ namespace System.Runtime.Loader { if (assemblyPath == null) { - throw new ArgumentNullException("assemblyPath"); + throw new ArgumentNullException(nameof(assemblyPath)); } String fullPath = Path.GetFullPathInternal(assemblyPath); @@ -405,7 +405,7 @@ namespace System.Runtime.Loader { if (assembly == null) { - throw new ArgumentNullException("assembly"); + throw new ArgumentNullException(nameof(assembly)); } AssemblyLoadContext loadContextForAssembly = null; diff --git a/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs b/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs index 4ae6047661..f04456bd3c 100644 --- a/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs +++ b/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs @@ -157,7 +157,7 @@ namespace System.Runtime public MemoryFailPoint(int sizeInMegabytes) { if (sizeInMegabytes <= 0) - throw new ArgumentOutOfRangeException("sizeInMegabytes", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(sizeInMegabytes), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); ulong size = ((ulong)sizeInMegabytes) << 20; diff --git a/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs b/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs index 7df221c9cd..b710ed0b3a 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs @@ -25,7 +25,7 @@ namespace System.Runtime.Serialization { public Object Convert(Object value, Type type) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ChangeType(value, type, CultureInfo.InvariantCulture); @@ -33,7 +33,7 @@ namespace System.Runtime.Serialization { public Object Convert(Object value, TypeCode typeCode) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ChangeType(value, typeCode, CultureInfo.InvariantCulture); @@ -41,7 +41,7 @@ namespace System.Runtime.Serialization { public bool ToBoolean(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToBoolean(value, CultureInfo.InvariantCulture); @@ -49,7 +49,7 @@ namespace System.Runtime.Serialization { public char ToChar(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToChar(value, CultureInfo.InvariantCulture); @@ -58,7 +58,7 @@ namespace System.Runtime.Serialization { [CLSCompliant(false)] public sbyte ToSByte(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToSByte(value, CultureInfo.InvariantCulture); @@ -66,7 +66,7 @@ namespace System.Runtime.Serialization { public byte ToByte(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToByte(value, CultureInfo.InvariantCulture); @@ -74,7 +74,7 @@ namespace System.Runtime.Serialization { public short ToInt16(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToInt16(value, CultureInfo.InvariantCulture); @@ -83,7 +83,7 @@ namespace System.Runtime.Serialization { [CLSCompliant(false)] public ushort ToUInt16(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToUInt16(value, CultureInfo.InvariantCulture); @@ -91,7 +91,7 @@ namespace System.Runtime.Serialization { public int ToInt32(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToInt32(value, CultureInfo.InvariantCulture); @@ -100,7 +100,7 @@ namespace System.Runtime.Serialization { [CLSCompliant(false)] public uint ToUInt32(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToUInt32(value, CultureInfo.InvariantCulture); @@ -108,7 +108,7 @@ namespace System.Runtime.Serialization { public long ToInt64(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToInt64(value, CultureInfo.InvariantCulture); @@ -117,7 +117,7 @@ namespace System.Runtime.Serialization { [CLSCompliant(false)] public ulong ToUInt64(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToUInt64(value, CultureInfo.InvariantCulture); @@ -125,7 +125,7 @@ namespace System.Runtime.Serialization { public float ToSingle(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToSingle(value, CultureInfo.InvariantCulture); @@ -133,7 +133,7 @@ namespace System.Runtime.Serialization { public double ToDouble(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToDouble(value, CultureInfo.InvariantCulture); @@ -141,7 +141,7 @@ namespace System.Runtime.Serialization { public Decimal ToDecimal(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToDecimal(value, CultureInfo.InvariantCulture); @@ -149,7 +149,7 @@ namespace System.Runtime.Serialization { public DateTime ToDateTime(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToDateTime(value, CultureInfo.InvariantCulture); @@ -157,7 +157,7 @@ namespace System.Runtime.Serialization { public String ToString(Object value) { if (value==null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return System.Convert.ToString(value, CultureInfo.InvariantCulture); diff --git a/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs b/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs index c6f27b5b2a..82fb362e9d 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs @@ -199,7 +199,7 @@ namespace System.Runtime.Serialization { MemberInfo[] members; if ((object)type==null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); @@ -257,7 +257,7 @@ namespace System.Runtime.Serialization { [System.Security.SecurityCritical] // auto-generated_required public static Object GetUninitializedObject(Type type) { if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); @@ -271,7 +271,7 @@ namespace System.Runtime.Serialization { [System.Security.SecurityCritical] // auto-generated_required public static Object GetSafeUninitializedObject(Type type) { if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); @@ -348,15 +348,15 @@ namespace System.Runtime.Serialization { [System.Security.SecurityCritical] // auto-generated_required public static Object PopulateObjectMembers(Object obj, MemberInfo[] members, Object[] data) { if (obj==null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } if (members==null) { - throw new ArgumentNullException("members"); + throw new ArgumentNullException(nameof(members)); } if (data==null) { - throw new ArgumentNullException("data"); + throw new ArgumentNullException(nameof(data)); } if (members.Length!=data.Length) { @@ -372,7 +372,7 @@ namespace System.Runtime.Serialization { mi = members[i]; if (mi==null) { - throw new ArgumentNullException("members", Environment.GetResourceString("ArgumentNull_NullMember", i)); + throw new ArgumentNullException(nameof(members), Environment.GetResourceString("ArgumentNull_NullMember", i)); } //If we find an empty, it means that the value was never set during deserialization. @@ -404,11 +404,11 @@ namespace System.Runtime.Serialization { public static Object[] GetObjectData(Object obj, MemberInfo[] members) { if (obj==null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } if (members==null) { - throw new ArgumentNullException("members"); + throw new ArgumentNullException(nameof(members)); } Contract.EndContractBlock(); @@ -421,7 +421,7 @@ namespace System.Runtime.Serialization { mi=members[i]; if (mi==null) { - throw new ArgumentNullException("members", Environment.GetResourceString("ArgumentNull_NullMember", i)); + throw new ArgumentNullException(nameof(members), Environment.GetResourceString("ArgumentNull_NullMember", i)); } if (mi.MemberType==MemberTypes.Field) { @@ -448,7 +448,7 @@ namespace System.Runtime.Serialization { public static ISerializationSurrogate GetSurrogateForCyclicalReference(ISerializationSurrogate innerSurrogate) { if (innerSurrogate == null) - throw new ArgumentNullException("innerSurrogate"); + throw new ArgumentNullException(nameof(innerSurrogate)); Contract.EndContractBlock(); return new SurrogateForCyclicalReference(innerSurrogate); } @@ -462,7 +462,7 @@ namespace System.Runtime.Serialization { [System.Security.SecurityCritical] // auto-generated_required public static Type GetTypeFromAssembly(Assembly assem, String name) { if (assem==null) - throw new ArgumentNullException("assem"); + throw new ArgumentNullException(nameof(assem)); Contract.EndContractBlock(); return assem.GetType(name, false, false); } @@ -499,7 +499,7 @@ namespace System.Runtime.Serialization { internal static string GetClrAssemblyName(Type type, out bool hasTypeForwardedFrom) { if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } object[] typeAttributes = type.GetCustomAttributes(typeof(TypeForwardedFromAttribute), false); @@ -566,7 +566,7 @@ namespace System.Runtime.Serialization { internal SurrogateForCyclicalReference(ISerializationSurrogate innerSurrogate) { if (innerSurrogate == null) - throw new ArgumentNullException("innerSurrogate"); + throw new ArgumentNullException(nameof(innerSurrogate)); this.innerSurrogate = innerSurrogate; } diff --git a/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs b/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs index 7fea98a1f0..9c8932712b 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs @@ -221,7 +221,7 @@ namespace System.Runtime.Serialization public void AddSerializedState(ISafeSerializationData serializedState) { if (serializedState == null) - throw new ArgumentNullException("serializedState"); + throw new ArgumentNullException(nameof(serializedState)); if (!serializedState.GetType().IsSerializable) throw new ArgumentException(Environment.GetResourceString("Serialization_NonSerType", serializedState.GetType(), serializedState.GetType().Assembly.FullName)); diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs index 94e6825b51..64a7fca776 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs @@ -61,12 +61,12 @@ namespace System.Runtime.Serialization { if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } if (converter == null) { - throw new ArgumentNullException("converter"); + throw new ArgumentNullException(nameof(converter)); } Contract.EndContractBlock(); @@ -96,7 +96,7 @@ namespace System.Runtime.Serialization { if (null == value) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); @@ -116,7 +116,7 @@ namespace System.Runtime.Serialization { if (null == value) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); if (this.requireSameTokenInPartialTrust) @@ -133,7 +133,7 @@ namespace System.Runtime.Serialization { if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); @@ -280,12 +280,12 @@ namespace System.Runtime.Serialization { if (null == name) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); @@ -447,7 +447,7 @@ namespace System.Runtime.Serialization { if (null == name) { - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); } Contract.EndContractBlock(); BCLDebug.Trace("SER", "[SerializationInfo.FindElement]Looking for ", name, " CurrMember is: ", m_currMember); @@ -514,7 +514,7 @@ namespace System.Runtime.Serialization if ((object)type == null) { - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Runtime/Versioning/BinaryCompatibility.cs b/src/mscorlib/src/System/Runtime/Versioning/BinaryCompatibility.cs index 60ffce2109..58c0d4e17a 100644 --- a/src/mscorlib/src/System/Runtime/Versioning/BinaryCompatibility.cs +++ b/src/mscorlib/src/System/Runtime/Versioning/BinaryCompatibility.cs @@ -356,11 +356,11 @@ namespace System.Runtime.Versioning { if (frameworkName == null) { - throw new ArgumentNullException("frameworkName"); + throw new ArgumentNullException(nameof(frameworkName)); } if (frameworkName.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_StringZeroLength"), "frameworkName"); + throw new ArgumentException(Environment.GetResourceString("Argument_StringZeroLength"), nameof(frameworkName)); } Contract.EndContractBlock(); @@ -370,7 +370,7 @@ namespace System.Runtime.Versioning // Identifer and Version are required, Profile is optional. if (components.Length < 2 || components.Length > 3) { - throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameTooShort"), "frameworkName"); + throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameTooShort"), nameof(frameworkName)); } // @@ -380,7 +380,7 @@ namespace System.Runtime.Versioning if (identifier.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameInvalid"), "frameworkName"); + throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameInvalid"), nameof(frameworkName)); } bool versionFound = false; @@ -396,7 +396,7 @@ namespace System.Runtime.Versioning if (keyValuePair.Length != 2) { - throw new ArgumentException(Environment.GetResourceString("SR.Argument_FrameworkNameInvalid"), "frameworkName"); + throw new ArgumentException(Environment.GetResourceString("SR.Argument_FrameworkNameInvalid"), nameof(frameworkName)); } // Get the key and value, trimming any whitespace @@ -435,13 +435,13 @@ namespace System.Runtime.Versioning } else { - throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameInvalid"), "frameworkName"); + throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameInvalid"), nameof(frameworkName)); } } if (!versionFound) { - throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameMissingVersion"), "frameworkName"); + throw new ArgumentException(Environment.GetResourceString("Argument_FrameworkNameMissingVersion"), nameof(frameworkName)); } } diff --git a/src/mscorlib/src/System/Runtime/Versioning/TargetFrameworkAttribute.cs b/src/mscorlib/src/System/Runtime/Versioning/TargetFrameworkAttribute.cs index dbf98c08d8..600ba3f154 100644 --- a/src/mscorlib/src/System/Runtime/Versioning/TargetFrameworkAttribute.cs +++ b/src/mscorlib/src/System/Runtime/Versioning/TargetFrameworkAttribute.cs @@ -26,7 +26,7 @@ namespace System.Runtime.Versioning { public TargetFrameworkAttribute(String frameworkName) { if (frameworkName == null) - throw new ArgumentNullException("frameworkName"); + throw new ArgumentNullException(nameof(frameworkName)); Contract.EndContractBlock(); _frameworkName = frameworkName; } diff --git a/src/mscorlib/src/System/RuntimeHandles.cs b/src/mscorlib/src/System/RuntimeHandles.cs index 24ca45e309..86f4bebfe1 100644 --- a/src/mscorlib/src/System/RuntimeHandles.cs +++ b/src/mscorlib/src/System/RuntimeHandles.cs @@ -582,7 +582,7 @@ namespace System internal static RuntimeType GetTypeByNameUsingCARules(string name, RuntimeModule scope) { if (name == null || name.Length == 0) - throw new ArgumentException("name"); + throw new ArgumentException(null, nameof(name)); Contract.EndContractBlock(); RuntimeType type = null; @@ -792,7 +792,7 @@ namespace System private RuntimeTypeHandle(SerializationInfo info, StreamingContext context) { if(info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); RuntimeType m = (RuntimeType)info.GetValue("TypeObj", typeof(RuntimeType)); @@ -807,7 +807,7 @@ namespace System public void GetObjectData(SerializationInfo info, StreamingContext context) { if(info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); if (m_type == null) @@ -959,7 +959,7 @@ namespace System private RuntimeMethodHandle(SerializationInfo info, StreamingContext context) { if(info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); MethodBase m =(MethodBase)info.GetValue("MethodObj", typeof(MethodBase)); @@ -974,7 +974,7 @@ namespace System public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); if (m_value == null) @@ -1646,7 +1646,7 @@ namespace System private RuntimeFieldHandle(SerializationInfo info, StreamingContext context) { if(info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); FieldInfo f =(RuntimeFieldInfo) info.GetValue("FieldObj", typeof(RuntimeFieldInfo)); @@ -1664,7 +1664,7 @@ namespace System public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); if (m_ptr == null) @@ -1775,7 +1775,7 @@ namespace System { ValidateModulePointer(module); if (!ModuleHandle.GetMetadataImport(module).IsValidToken(typeToken)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(typeToken), Environment.GetResourceString("Argument_InvalidToken", typeToken, new ModuleHandle(module))); int typeInstCount, methodInstCount; @@ -1832,7 +1832,7 @@ namespace System { ValidateModulePointer(module); if (!ModuleHandle.GetMetadataImport(module.GetNativeHandle()).IsValidToken(methodToken)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(methodToken), Environment.GetResourceString("Argument_InvalidToken", methodToken, new ModuleHandle(module))); fixed (IntPtr* typeInstArgs = typeInstantiationContext, methodInstArgs = methodInstantiationContext) @@ -1862,7 +1862,7 @@ namespace System { ValidateModulePointer(module); if (!ModuleHandle.GetMetadataImport(module.GetNativeHandle()).IsValidToken(fieldToken)) - throw new ArgumentOutOfRangeException("metadataToken", + throw new ArgumentOutOfRangeException(nameof(fieldToken), Environment.GetResourceString("Argument_InvalidToken", fieldToken, new ModuleHandle(module))); // defensive copy to be sure array is not mutated from the outside during processing diff --git a/src/mscorlib/src/System/Security/CodeAccessPermission.cs b/src/mscorlib/src/System/Security/CodeAccessPermission.cs index 61334c22bd..46a1286483 100644 --- a/src/mscorlib/src/System/Security/CodeAccessPermission.cs +++ b/src/mscorlib/src/System/Security/CodeAccessPermission.cs @@ -177,7 +177,7 @@ namespace System.Security static internal void ValidateElement( SecurityElement elem, IPermission perm ) { if (elem == null) - throw new ArgumentNullException( "elem" ); + throw new ArgumentNullException( nameof(elem) ); Contract.EndContractBlock(); if (!XMLUtil.IsPermissionElement( perm, elem )) diff --git a/src/mscorlib/src/System/Security/HostProtectionException.cs b/src/mscorlib/src/System/Security/HostProtectionException.cs index 83f005fe9b..ffdc6078f9 100644 --- a/src/mscorlib/src/System/Security/HostProtectionException.cs +++ b/src/mscorlib/src/System/Security/HostProtectionException.cs @@ -53,7 +53,7 @@ namespace System.Security protected HostProtectionException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); m_protected = (HostProtectionResource)info.GetValue(ProtectedResourcesName, typeof(HostProtectionResource)); @@ -124,7 +124,7 @@ namespace System.Security public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); base.GetObjectData( info, context ); diff --git a/src/mscorlib/src/System/Security/HostSecurityManager.cs b/src/mscorlib/src/System/Security/HostSecurityManager.cs index 46d5552478..0c2b33f6f1 100644 --- a/src/mscorlib/src/System/Security/HostSecurityManager.cs +++ b/src/mscorlib/src/System/Security/HostSecurityManager.cs @@ -86,7 +86,7 @@ namespace System.Security { public virtual ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context) { if (applicationEvidence == null) - throw new ArgumentNullException("applicationEvidence"); + throw new ArgumentNullException(nameof(applicationEvidence)); Contract.EndContractBlock(); // This method looks for a trust decision for the ActivationContext in three locations, in order @@ -154,7 +154,7 @@ namespace System.Security { public virtual PermissionSet ResolvePolicy(Evidence evidence) { if (evidence == null) - throw new ArgumentNullException("evidence"); + throw new ArgumentNullException(nameof(evidence)); Contract.EndContractBlock(); // diff --git a/src/mscorlib/src/System/Security/NamedPermissionSet.cs b/src/mscorlib/src/System/Security/NamedPermissionSet.cs index fba76749a1..a8779adcec 100644 --- a/src/mscorlib/src/System/Security/NamedPermissionSet.cs +++ b/src/mscorlib/src/System/Security/NamedPermissionSet.cs @@ -156,7 +156,7 @@ namespace System.Security { internal override void FromXml( SecurityElement et, bool allowInternalOnly, bool ignoreTypeLoadFailures ) { if (et == null) - throw new ArgumentNullException( "et" ); + throw new ArgumentNullException( nameof(et) ); Contract.EndContractBlock(); String elem; diff --git a/src/mscorlib/src/System/Security/PermissionSet.cs b/src/mscorlib/src/System/Security/PermissionSet.cs index e36f0752ad..195323b993 100644 --- a/src/mscorlib/src/System/Security/PermissionSet.cs +++ b/src/mscorlib/src/System/Security/PermissionSet.cs @@ -253,7 +253,7 @@ namespace System.Security { public virtual void CopyTo(Array array, int index) { if (array == null) - throw new ArgumentNullException( "array" ); + throw new ArgumentNullException( nameof(array) ); Contract.EndContractBlock(); PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(this); @@ -1751,10 +1751,10 @@ namespace System.Security { internal virtual void FromXml( SecurityElement et, bool allowInternalOnly, bool ignoreTypeLoadFailures ) { if (et == null) - throw new ArgumentNullException("et"); + throw new ArgumentNullException(nameof(et)); if (!et.Tag.Equals(s_str_PermissionSet)) - throw new ArgumentException(String.Format( null, Environment.GetResourceString( "Argument_InvalidXMLElement" ), "PermissionSet", this.GetType().FullName) ); + throw new ArgumentException(String.Format( null, Environment.GetResourceString( "Argument_InvalidXMLElement" ), nameof(PermissionSet), this.GetType().FullName) ); Contract.EndContractBlock(); Reset(); @@ -1852,11 +1852,11 @@ namespace System.Security { internal virtual void FromXml( SecurityDocument doc, int position, bool allowInternalOnly ) { if (doc == null) - throw new ArgumentNullException("doc"); + throw new ArgumentNullException(nameof(doc)); Contract.EndContractBlock(); if (!doc.GetTagForElement( position ).Equals(s_str_PermissionSet)) - throw new ArgumentException(String.Format( null, Environment.GetResourceString( "Argument_InvalidXMLElement" ), "PermissionSet", this.GetType().FullName) ); + throw new ArgumentException(String.Format( null, Environment.GetResourceString( "Argument_InvalidXMLElement" ), nameof(PermissionSet), this.GetType().FullName) ); Reset(); m_allPermissionsDecoded = false; diff --git a/src/mscorlib/src/System/Security/PermissionToken.cs b/src/mscorlib/src/System/Security/PermissionToken.cs index e78c0f1a93..1896dd95c1 100644 --- a/src/mscorlib/src/System/Security/PermissionToken.cs +++ b/src/mscorlib/src/System/Security/PermissionToken.cs @@ -64,7 +64,7 @@ namespace System.Security { // The data structure consuming this will be responsible for dealing with null objects as keys. public int GetHashCode(Object obj) { - if (obj == null) throw new ArgumentNullException("obj"); + if (obj == null) throw new ArgumentNullException(nameof(obj)); Contract.EndContractBlock(); String str = obj as String; diff --git a/src/mscorlib/src/System/Security/Permissions/StrongNameIdentityPermission.cs b/src/mscorlib/src/System/Security/Permissions/StrongNameIdentityPermission.cs index 5f5de0ef80..0bc689b644 100644 --- a/src/mscorlib/src/System/Security/Permissions/StrongNameIdentityPermission.cs +++ b/src/mscorlib/src/System/Security/Permissions/StrongNameIdentityPermission.cs @@ -135,7 +135,7 @@ namespace System.Security.Permissions public StrongNameIdentityPermission( StrongNamePublicKeyBlob blob, String name, Version version ) { if (blob == null) - throw new ArgumentNullException( "blob" ); + throw new ArgumentNullException( nameof(blob) ); if (name != null && name.Equals( "" )) throw new ArgumentException( Environment.GetResourceString( "Argument_EmptyStrongName" ) ); Contract.EndContractBlock(); @@ -156,7 +156,7 @@ namespace System.Security.Permissions set { if (value == null) - throw new ArgumentNullException( "PublicKey" ); + throw new ArgumentNullException( nameof(PublicKey) ); Contract.EndContractBlock(); m_unrestricted = false; if(m_strongNames != null && m_strongNames.Length == 1) diff --git a/src/mscorlib/src/System/Security/Permissions/StrongNamePublicKeyBlob.cs b/src/mscorlib/src/System/Security/Permissions/StrongNamePublicKeyBlob.cs index e0aacaf80c..823eaba938 100644 --- a/src/mscorlib/src/System/Security/Permissions/StrongNamePublicKeyBlob.cs +++ b/src/mscorlib/src/System/Security/Permissions/StrongNamePublicKeyBlob.cs @@ -20,7 +20,7 @@ namespace System.Security.Permissions public StrongNamePublicKeyBlob( byte[] publicKey ) { if (publicKey == null) - throw new ArgumentNullException( "PublicKey" ); + throw new ArgumentNullException( nameof(PublicKey) ); Contract.EndContractBlock(); this.PublicKey = new byte[publicKey.Length]; diff --git a/src/mscorlib/src/System/Security/Permissions/URLIdentityPermission.cs b/src/mscorlib/src/System/Security/Permissions/URLIdentityPermission.cs index e62449cf3e..99f86ede42 100644 --- a/src/mscorlib/src/System/Security/Permissions/URLIdentityPermission.cs +++ b/src/mscorlib/src/System/Security/Permissions/URLIdentityPermission.cs @@ -110,7 +110,7 @@ namespace System.Security.Permissions public UrlIdentityPermission( String site ) { if (site == null) - throw new ArgumentNullException( "site" ); + throw new ArgumentNullException( nameof(site) ); Contract.EndContractBlock(); Url = site; } diff --git a/src/mscorlib/src/System/Security/Permissions/keycontainerpermission.cs b/src/mscorlib/src/System/Security/Permissions/keycontainerpermission.cs index 9691c03da3..feb5911f61 100644 --- a/src/mscorlib/src/System/Security/Permissions/keycontainerpermission.cs +++ b/src/mscorlib/src/System/Security/Permissions/keycontainerpermission.cs @@ -88,7 +88,7 @@ namespace System.Security.Permissions { m_keyStore = "*"; } else { if (value != "User" && value != "Machine" && value != "*") - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidKeyStore", value), "value"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidKeyStore", value), nameof(value)); m_keyStore = value; } } @@ -232,7 +232,7 @@ namespace System.Security.Permissions { if (index < 0) throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted")); if (index >= Count) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); return (KeyContainerPermissionAccessEntry)m_list[index]; @@ -247,7 +247,7 @@ namespace System.Security.Permissions { public int Add (KeyContainerPermissionAccessEntry accessEntry) { if (accessEntry == null) - throw new ArgumentNullException("accessEntry"); + throw new ArgumentNullException(nameof(accessEntry)); Contract.EndContractBlock(); int index = m_list.IndexOf(accessEntry); @@ -275,7 +275,7 @@ namespace System.Security.Permissions { public void Remove (KeyContainerPermissionAccessEntry accessEntry) { if (accessEntry == null) - throw new ArgumentNullException("accessEntry"); + throw new ArgumentNullException(nameof(accessEntry)); Contract.EndContractBlock(); m_list.Remove(accessEntry); } @@ -292,11 +292,11 @@ namespace System.Security.Permissions { /// <internalonly/> void ICollection.CopyTo (Array array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (index + this.Count > array.Length) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); @@ -385,7 +385,7 @@ namespace System.Security.Permissions { public KeyContainerPermission (KeyContainerPermissionFlags flags, KeyContainerPermissionAccessEntry[] accessList) { if (accessList == null) - throw new ArgumentNullException("accessList"); + throw new ArgumentNullException(nameof(accessList)); Contract.EndContractBlock(); VerifyFlags(flags); diff --git a/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs b/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs index 57b216e462..5cfc1dbc44 100644 --- a/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs +++ b/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs @@ -83,7 +83,7 @@ namespace System.Security.Policy { public ApplicationTrust(PermissionSet defaultGrantSet, IEnumerable<StrongName> fullTrustAssemblies) { if (fullTrustAssemblies == null) { - throw new ArgumentNullException("fullTrustAssemblies"); + throw new ArgumentNullException(nameof(fullTrustAssemblies)); } InitDefaultGrantSet(defaultGrantSet); @@ -91,7 +91,7 @@ namespace System.Security.Policy { List<StrongName> fullTrustList = new List<StrongName>(); foreach (StrongName strongName in fullTrustAssemblies) { if (strongName == null) { - throw new ArgumentException(Environment.GetResourceString("Argument_NullFullTrustAssembly"), "fullTrustAssemblies"); + throw new ArgumentException(Environment.GetResourceString("Argument_NullFullTrustAssembly"), nameof(fullTrustAssemblies)); } fullTrustList.Add(new StrongName(strongName.PublicKey, strongName.Name, strongName.Version)); @@ -104,7 +104,7 @@ namespace System.Security.Policy { // IEnumerable virtual dispatches on startup when there are no fullTrustAssemblies (CoreCLR) private void InitDefaultGrantSet(PermissionSet defaultGrantSet) { if (defaultGrantSet == null) { - throw new ArgumentNullException("defaultGrantSet"); + throw new ArgumentNullException(nameof(defaultGrantSet)); } // Creating a PolicyStatement copies the incoming permission set, so we don't have to worry @@ -120,7 +120,7 @@ namespace System.Security.Policy { } set { if (value == null) - throw new ArgumentNullException("value", Environment.GetResourceString("Argument_InvalidAppId")); + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("Argument_InvalidAppId")); Contract.EndContractBlock(); m_appId = value; } @@ -223,7 +223,7 @@ namespace System.Security.Policy { public void FromXml (SecurityElement element) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); @@ -455,7 +455,7 @@ namespace System.Security.Policy { [System.Security.SecurityCritical] // auto-generated public int Add (ApplicationTrust trust) { if (trust == null) - throw new ArgumentNullException("trust"); + throw new ArgumentNullException(nameof(trust)); if (trust.ApplicationIdentity == null) throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity")); Contract.EndContractBlock(); @@ -472,7 +472,7 @@ namespace System.Security.Policy { [System.Security.SecurityCritical] // auto-generated public void AddRange (ApplicationTrust[] trusts) { if (trusts == null) - throw new ArgumentNullException("trusts"); + throw new ArgumentNullException(nameof(trusts)); Contract.EndContractBlock(); int i=0; @@ -491,7 +491,7 @@ namespace System.Security.Policy { [System.Security.SecurityCritical] // auto-generated public void AddRange (ApplicationTrustCollection trusts) { if (trusts == null) - throw new ArgumentNullException("trusts"); + throw new ArgumentNullException(nameof(trusts)); Contract.EndContractBlock(); int i = 0; @@ -527,7 +527,7 @@ namespace System.Security.Policy { [System.Security.SecurityCritical] // auto-generated public void Remove (ApplicationTrust trust) { if (trust == null) - throw new ArgumentNullException("trust"); + throw new ArgumentNullException(nameof(trust)); if (trust.ApplicationIdentity == null) throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity")); Contract.EndContractBlock(); @@ -543,7 +543,7 @@ namespace System.Security.Policy { [System.Security.SecurityCritical] // auto-generated public void RemoveRange (ApplicationTrust[] trusts) { if (trusts == null) - throw new ArgumentNullException("trusts"); + throw new ArgumentNullException(nameof(trusts)); Contract.EndContractBlock(); int i=0; @@ -562,7 +562,7 @@ namespace System.Security.Policy { [System.Security.SecurityCritical] // auto-generated public void RemoveRange (ApplicationTrustCollection trusts) { if (trusts == null) - throw new ArgumentNullException("trusts"); + throw new ArgumentNullException(nameof(trusts)); Contract.EndContractBlock(); int i = 0; @@ -610,11 +610,11 @@ namespace System.Security.Policy { [System.Security.SecuritySafeCritical] // overrides public transparent member void ICollection.CopyTo(Array array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (array.Rank != 1) throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported")); if (index < 0 || index >= array.Length) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (array.Length - index < this.Count) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Security/Policy/Evidence.cs b/src/mscorlib/src/System/Security/Policy/Evidence.cs index 8bf8aa7e92..3fe3b586b5 100644 --- a/src/mscorlib/src/System/Security/Policy/Evidence.cs +++ b/src/mscorlib/src/System/Security/Policy/Evidence.cs @@ -355,9 +355,9 @@ namespace System.Security.Policy public void AddHost(object id) { if (id == null) - throw new ArgumentNullException("id"); + throw new ArgumentNullException(nameof(id)); if (!id.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Policy_EvidenceMustBeSerializable"), "id"); + throw new ArgumentException(Environment.GetResourceString("Policy_EvidenceMustBeSerializable"), nameof(id)); Contract.EndContractBlock(); if (m_locked) @@ -377,9 +377,9 @@ namespace System.Security.Policy public void AddAssembly(object id) { if (id == null) - throw new ArgumentNullException("id"); + throw new ArgumentNullException(nameof(id)); if (!id.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Policy_EvidenceMustBeSerializable"), "id"); + throw new ArgumentException(Environment.GetResourceString("Policy_EvidenceMustBeSerializable"), nameof(id)); Contract.EndContractBlock(); EvidenceBase evidence = WrapLegacyEvidence(id); @@ -398,7 +398,7 @@ namespace System.Security.Policy public void AddAssemblyEvidence<T>(T evidence) where T : EvidenceBase { if (evidence == null) - throw new ArgumentNullException("evidence"); + throw new ArgumentNullException(nameof(evidence)); Contract.EndContractBlock(); // Index the evidence under the type that the Add function was called with, unless we were given @@ -455,7 +455,7 @@ namespace System.Security.Policy public void AddHostEvidence<T>(T evidence) where T : EvidenceBase { if (evidence == null) - throw new ArgumentNullException("evidence"); + throw new ArgumentNullException(nameof(evidence)); Contract.EndContractBlock(); // Index the evidence under the type that the Add function was called with, unless we were given @@ -1064,9 +1064,9 @@ namespace System.Security.Policy public void CopyTo(Array array, int index) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (index < 0 || index > array.Length - Count) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); Contract.EndContractBlock(); int currentIndex = index; @@ -1445,7 +1445,7 @@ namespace System.Security.Policy public void RemoveType(Type t) { if (t == null) - throw new ArgumentNullException("t"); + throw new ArgumentNullException(nameof(t)); Contract.EndContractBlock(); using (EvidenceLockHolder lockHolder = new EvidenceLockHolder(this, EvidenceLockHolder.LockType.Writer)) diff --git a/src/mscorlib/src/System/Security/Policy/PolicyStatement.cs b/src/mscorlib/src/System/Security/Policy/PolicyStatement.cs index 72c07d1246..5fb61d119d 100644 --- a/src/mscorlib/src/System/Security/Policy/PolicyStatement.cs +++ b/src/mscorlib/src/System/Security/Policy/PolicyStatement.cs @@ -357,10 +357,10 @@ namespace System.Security.Policy { internal void FromXml( SecurityElement et, PolicyLevel level, bool allowInternalOnly ) { if (et == null) - throw new ArgumentNullException( "et" ); + throw new ArgumentNullException( nameof(et) ); if (!et.Tag.Equals( "PolicyStatement" )) - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ), "PolicyStatement", this.GetType().FullName ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ), nameof(PolicyStatement), this.GetType().FullName ) ); Contract.EndContractBlock(); m_attributes = (PolicyStatementAttribute) 0; @@ -434,11 +434,11 @@ namespace System.Security.Policy { internal void FromXml( SecurityDocument doc, int position, PolicyLevel level, bool allowInternalOnly ) { if (doc == null) - throw new ArgumentNullException( "doc" ); + throw new ArgumentNullException( nameof(doc) ); Contract.EndContractBlock(); if (!doc.GetTagForElement( position ).Equals( "PolicyStatement" )) - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ), "PolicyStatement", this.GetType().FullName ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidXMLElement" ), nameof(PolicyStatement), this.GetType().FullName ) ); m_attributes = (PolicyStatementAttribute) 0; diff --git a/src/mscorlib/src/System/Security/Policy/Site.cs b/src/mscorlib/src/System/Security/Policy/Site.cs index e7c6cd3d83..9c954d220a 100644 --- a/src/mscorlib/src/System/Security/Policy/Site.cs +++ b/src/mscorlib/src/System/Security/Policy/Site.cs @@ -26,7 +26,7 @@ namespace System.Security.Policy public Site(String name) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); m_name = new SiteString( name ); diff --git a/src/mscorlib/src/System/Security/Policy/StrongName.cs b/src/mscorlib/src/System/Security/Policy/StrongName.cs index c49f2b0674..0cdf85f703 100644 --- a/src/mscorlib/src/System/Security/Policy/StrongName.cs +++ b/src/mscorlib/src/System/Security/Policy/StrongName.cs @@ -42,20 +42,20 @@ namespace System.Security.Policy { internal StrongName(StrongNamePublicKeyBlob blob, String name, Version version, Assembly assembly) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (String.IsNullOrEmpty(name)) throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName")); if (blob == null) - throw new ArgumentNullException("blob"); + throw new ArgumentNullException(nameof(blob)); if (version == null) - throw new ArgumentNullException("version"); + throw new ArgumentNullException(nameof(version)); Contract.EndContractBlock(); RuntimeAssembly rtAssembly = assembly as RuntimeAssembly; if (assembly != null && rtAssembly == null) - throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly"); + throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), nameof(assembly)); m_publicKeyBlob = blob; m_name = name; @@ -154,7 +154,7 @@ namespace System.Security.Policy { internal void FromXml (SecurityElement element) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (String.Compare(element.Tag, "StrongName", StringComparison.Ordinal) != 0) throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Security/Policy/URL.cs b/src/mscorlib/src/System/Security/Policy/URL.cs index d3ad4f8724..dba8ca89c1 100644 --- a/src/mscorlib/src/System/Security/Policy/URL.cs +++ b/src/mscorlib/src/System/Security/Policy/URL.cs @@ -25,7 +25,7 @@ namespace System.Security.Policy { internal Url( String name, bool parsed ) { if (name == null) - throw new ArgumentNullException( "name" ); + throw new ArgumentNullException( nameof(name) ); Contract.EndContractBlock(); m_url = new URLString( name, parsed ); @@ -34,7 +34,7 @@ namespace System.Security.Policy { public Url( String name ) { if (name == null) - throw new ArgumentNullException( "name" ); + throw new ArgumentNullException( nameof(name) ); Contract.EndContractBlock(); m_url = new URLString( name ); diff --git a/src/mscorlib/src/System/Security/Policy/Zone.cs b/src/mscorlib/src/System/Security/Policy/Zone.cs index c999abe340..267c059e90 100644 --- a/src/mscorlib/src/System/Security/Policy/Zone.cs +++ b/src/mscorlib/src/System/Security/Policy/Zone.cs @@ -60,7 +60,7 @@ namespace System.Security.Policy { public static Zone CreateFromUrl( String url ) { if (url == null) - throw new ArgumentNullException( "url" ); + throw new ArgumentNullException( nameof(url) ); Contract.EndContractBlock(); return new Zone( url ); diff --git a/src/mscorlib/src/System/Security/SecurityElement.cs b/src/mscorlib/src/System/Security/SecurityElement.cs index 9f925b5ae9..667bf7fef4 100644 --- a/src/mscorlib/src/System/Security/SecurityElement.cs +++ b/src/mscorlib/src/System/Security/SecurityElement.cs @@ -99,7 +99,7 @@ namespace System.Security public static SecurityElement FromString( String xml ) { if (xml == null) - throw new ArgumentNullException( "xml" ); + throw new ArgumentNullException( nameof(xml) ); Contract.EndContractBlock(); return new Parser( xml ).GetTopElement(); @@ -109,7 +109,7 @@ namespace System.Security public SecurityElement( String tag ) { if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); if (!IsValidTag( tag )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementTag" ), tag ) ); @@ -122,7 +122,7 @@ namespace System.Security public SecurityElement( String tag, String text ) { if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); if (!IsValidTag( tag )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementTag" ), tag ) ); @@ -148,7 +148,7 @@ namespace System.Security set { if (value == null) - throw new ArgumentNullException( "Tag" ); + throw new ArgumentNullException( nameof(Tag) ); if (!IsValidTag( value )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementTag" ), value ) ); @@ -314,10 +314,10 @@ namespace System.Security public void AddAttribute( String name, String value ) { if (name == null) - throw new ArgumentNullException( "name" ); + throw new ArgumentNullException( nameof(name) ); if (value == null) - throw new ArgumentNullException( "value" ); + throw new ArgumentNullException( nameof(value) ); if (!IsValidAttributeName( name )) throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Argument_InvalidElementName" ), name ) ); @@ -332,7 +332,7 @@ namespace System.Security public void AddChild( SecurityElement child ) { if (child == null) - throw new ArgumentNullException( "child" ); + throw new ArgumentNullException( nameof(child) ); Contract.EndContractBlock(); if (m_lChildren == null) @@ -344,7 +344,7 @@ namespace System.Security internal void AddChild( ISecurityElementFactory child ) { if (child == null) - throw new ArgumentNullException( "child" ); + throw new ArgumentNullException( nameof(child) ); Contract.EndContractBlock(); if (m_lChildren == null) @@ -356,7 +356,7 @@ namespace System.Security internal void AddChildNoDuplicates( ISecurityElementFactory child ) { if (child == null) - throw new ArgumentNullException( "child" ); + throw new ArgumentNullException( nameof(child) ); Contract.EndContractBlock(); if (m_lChildren == null) @@ -772,7 +772,7 @@ namespace System.Security public String Attribute( String name ) { if (name == null) - throw new ArgumentNullException( "name" ); + throw new ArgumentNullException( nameof(name) ); Contract.EndContractBlock(); // Note: we don't check for validity here because an @@ -810,7 +810,7 @@ namespace System.Security // find the one are are asked for (matching tags) if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); Contract.EndContractBlock(); // Note: we don't check for a valid tag here because @@ -869,7 +869,7 @@ namespace System.Security // child's child, depth-first if (strLocalName == null) - throw new ArgumentNullException( "strLocalName" ); + throw new ArgumentNullException( nameof(strLocalName) ); Contract.EndContractBlock(); // Note: we don't check for a valid tag here because @@ -901,7 +901,7 @@ namespace System.Security // child's child, depth-first if (tag == null) - throw new ArgumentNullException( "tag" ); + throw new ArgumentNullException( nameof(tag) ); Contract.EndContractBlock(); // Note: we don't check for a valid tag here because diff --git a/src/mscorlib/src/System/Security/SecurityException.cs b/src/mscorlib/src/System/Security/SecurityException.cs index ca06da017f..4de9d6502d 100644 --- a/src/mscorlib/src/System/Security/SecurityException.cs +++ b/src/mscorlib/src/System/Security/SecurityException.cs @@ -229,7 +229,7 @@ namespace System.Security protected SecurityException(SerializationInfo info, StreamingContext context) : base (info, context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); try @@ -605,7 +605,7 @@ namespace System.Security protected SecurityException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); } @@ -643,7 +643,7 @@ namespace System.Security public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/Security/SecurityManager.cs b/src/mscorlib/src/System/Security/SecurityManager.cs index 5c46dfcbfc..235d510a3f 100644 --- a/src/mscorlib/src/System/Security/SecurityManager.cs +++ b/src/mscorlib/src/System/Security/SecurityManager.cs @@ -77,7 +77,7 @@ namespace System.Security { public static PermissionSet GetStandardSandbox(Evidence evidence) { if (evidence == null) - throw new ArgumentNullException("evidence"); + throw new ArgumentNullException(nameof(evidence)); Contract.EndContractBlock(); // @@ -160,7 +160,7 @@ namespace System.Security { static public PolicyLevel LoadPolicyLevelFromFile(string path, PolicyLevelType type) { if (path == null) - throw new ArgumentNullException( "path" ); + throw new ArgumentNullException( nameof(path) ); Contract.EndContractBlock(); if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) @@ -197,7 +197,7 @@ namespace System.Security { private static PolicyLevel LoadPolicyLevelFromStringHelper (string str, string path, PolicyLevelType type) { if (str == null) - throw new ArgumentNullException( "str" ); + throw new ArgumentNullException( nameof(str) ); Contract.EndContractBlock(); PolicyLevel level = new PolicyLevel(type, path); @@ -205,25 +205,25 @@ namespace System.Security { Parser parser = new Parser( str ); SecurityElement elRoot = parser.GetTopElement(); if (elRoot == null) - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "configuration" ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), nameof(configuration) ) ); SecurityElement elMscorlib = elRoot.SearchForChildByTag( "mscorlib" ); if (elMscorlib == null) - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "mscorlib" ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), nameof(mscorlib) ) ); SecurityElement elSecurity = elMscorlib.SearchForChildByTag( "security" ); if (elSecurity == null) - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "security" ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), nameof(security) ) ); SecurityElement elPolicy = elSecurity.SearchForChildByTag( "policy" ); if (elPolicy == null) - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "policy" ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), nameof(policy) ) ); SecurityElement elPolicyLevel = elPolicy.SearchForChildByTag( "PolicyLevel" ); if (elPolicyLevel != null) level.FromXml( elPolicyLevel ); else - throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), "PolicyLevel" ) ); + throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Policy_BadXml" ), nameof(PolicyLevel) ) ); return level; } diff --git a/src/mscorlib/src/System/Security/Util/Hex.cs b/src/mscorlib/src/System/Security/Util/Hex.cs index 709744f2a2..4ca1cf678b 100644 --- a/src/mscorlib/src/System/Security/Util/Hex.cs +++ b/src/mscorlib/src/System/Security/Util/Hex.cs @@ -73,7 +73,7 @@ namespace System.Security.Util public static byte[] DecodeHexString(String hexString) { if (hexString == null) - throw new ArgumentNullException( "hexString" ); + throw new ArgumentNullException( nameof(hexString) ); Contract.EndContractBlock(); bool spaceSkippingMode = false; diff --git a/src/mscorlib/src/System/Security/Util/StringExpressionSet.cs b/src/mscorlib/src/System/Security/Util/StringExpressionSet.cs index 19937f5ae6..03d6998c6d 100644 --- a/src/mscorlib/src/System/Security/Util/StringExpressionSet.cs +++ b/src/mscorlib/src/System/Security/Util/StringExpressionSet.cs @@ -122,7 +122,7 @@ namespace System.Security.Util { public void AddExpressions( String str ) { if (str == null) - throw new ArgumentNullException( "str" ); + throw new ArgumentNullException( nameof(str) ); Contract.EndContractBlock(); if (str.Length == 0) return; @@ -210,14 +210,14 @@ namespace System.Security.Util { { if (str == null) { - throw new ArgumentNullException( "str" ); + throw new ArgumentNullException( nameof(str) ); } Contract.EndContractBlock(); ArrayList retArrayList = new ArrayList(); for (int index = 0; index < str.Length; ++index) { if (str[index] == null) - throw new ArgumentNullException( "str" ); + throw new ArgumentNullException( nameof(str) ); // Replace alternate directory separators String oneString = StaticProcessWholeString( str[index] ); diff --git a/src/mscorlib/src/System/Security/Util/URLString.cs b/src/mscorlib/src/System/Security/Util/URLString.cs index 51ae24cf4a..997cb2cf12 100644 --- a/src/mscorlib/src/System/Security/Util/URLString.cs +++ b/src/mscorlib/src/System/Security/Util/URLString.cs @@ -680,7 +680,7 @@ namespace System.Security.Util { { if (url == null) { - throw new ArgumentNullException( "url" ); + throw new ArgumentNullException( nameof(url) ); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/String.Comparison.cs b/src/mscorlib/src/System/String.Comparison.cs index a05f9f201a..cf52ada6f3 100644 --- a/src/mscorlib/src/System/String.Comparison.cs +++ b/src/mscorlib/src/System/String.Comparison.cs @@ -348,7 +348,7 @@ namespace System // Single comparison to check if comparisonType is within [CurrentCulture .. OrdinalIgnoreCase] if ((uint)(comparisonType - StringComparison.CurrentCulture) > (uint)(StringComparison.OrdinalIgnoreCase - StringComparison.CurrentCulture)) { - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } Contract.EndContractBlock(); @@ -417,7 +417,7 @@ namespace System public static int Compare(String strA, String strB, CultureInfo culture, CompareOptions options) { if (culture == null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.EndContractBlock(); @@ -511,7 +511,7 @@ namespace System { if (culture == null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.EndContractBlock(); @@ -535,7 +535,7 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public static int Compare(String strA, int indexA, String strB, int indexB, int length, StringComparison comparisonType) { if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase) { - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } Contract.EndContractBlock(); @@ -552,7 +552,7 @@ namespace System if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); } if (indexA < 0 || indexB < 0) @@ -657,7 +657,7 @@ namespace System if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); } if (indexA < 0 || indexB < 0) @@ -728,11 +728,11 @@ namespace System [ComVisible(false)] public Boolean EndsWith(String value, StringComparison comparisonType) { if( (Object)value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if( comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase) { - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } Contract.EndContractBlock(); @@ -767,14 +767,14 @@ namespace System return this.Length < value.Length ? false : (TextInfo.CompareOrdinalIgnoreCaseEx(this, this.Length - value.Length, value, 0, value.Length, value.Length) == 0); #endif default: - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } } [Pure] public Boolean EndsWith(String value, Boolean ignoreCase, CultureInfo culture) { if (null==value) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); @@ -849,7 +849,7 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public bool Equals(String value, StringComparison comparisonType) { if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase) - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); Contract.EndContractBlock(); if ((Object)this == (Object)value) { @@ -895,7 +895,7 @@ namespace System #endif default: - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } } @@ -918,7 +918,7 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public static bool Equals(String a, String b, StringComparison comparisonType) { if (comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase) - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); Contract.EndContractBlock(); if ((Object)a==(Object)b) { @@ -966,7 +966,7 @@ namespace System } default: - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } } @@ -1073,7 +1073,7 @@ namespace System [Pure] public Boolean StartsWith(String value) { if ((Object)value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); return StartsWith(value, StringComparison.CurrentCulture); @@ -1084,11 +1084,11 @@ namespace System [ComVisible(false)] public Boolean StartsWith(String value, StringComparison comparisonType) { if( (Object)value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if( comparisonType < StringComparison.CurrentCulture || comparisonType > StringComparison.OrdinalIgnoreCase) { - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } Contract.EndContractBlock(); @@ -1133,14 +1133,14 @@ namespace System #endif default: - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } } [Pure] public Boolean StartsWith(String value, Boolean ignoreCase, CultureInfo culture) { if (null==value) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/String.Manipulation.cs b/src/mscorlib/src/System/String.Manipulation.cs index 8c81897d72..563cd8193b 100644 --- a/src/mscorlib/src/System/String.Manipulation.cs +++ b/src/mscorlib/src/System/String.Manipulation.cs @@ -114,7 +114,7 @@ namespace System { if (args == null) { - throw new ArgumentNullException("args"); + throw new ArgumentNullException(nameof(args)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -181,7 +181,7 @@ namespace System public static string Concat<T>(IEnumerable<T> values) { if (values == null) - throw new ArgumentNullException("values"); + throw new ArgumentNullException(nameof(values)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -232,7 +232,7 @@ namespace System public static string Concat(IEnumerable<string> values) { if (values == null) - throw new ArgumentNullException("values"); + throw new ArgumentNullException(nameof(values)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -369,7 +369,7 @@ namespace System [System.Security.SecuritySafeCritical] public static String Concat(params String[] values) { if (values == null) - throw new ArgumentNullException("values"); + throw new ArgumentNullException(nameof(values)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -456,7 +456,7 @@ namespace System { // To preserve the original exception behavior, throw an exception about format if both // args and format are null. The actual null check for format is in FormatHelper. - throw new ArgumentNullException((format == null) ? "format" : "args"); + throw new ArgumentNullException((format == null) ? nameof(format) : nameof(args)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -484,7 +484,7 @@ namespace System { // To preserve the original exception behavior, throw an exception about format if both // args and format are null. The actual null check for format is in FormatHelper. - throw new ArgumentNullException((format == null) ? "format" : "args"); + throw new ArgumentNullException((format == null) ? nameof(format) : nameof(args)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -494,7 +494,7 @@ namespace System private static String FormatHelper(IFormatProvider provider, String format, ParamsArray args) { if (format == null) - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); return StringBuilderCache.GetStringAndRelease( StringBuilderCache @@ -506,9 +506,9 @@ namespace System public String Insert(int startIndex, String value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex < 0 || startIndex > this.Length) - throw new ArgumentOutOfRangeException("startIndex"); + throw new ArgumentOutOfRangeException(nameof(startIndex)); Contract.Ensures(Contract.Result<String>() != null); Contract.Ensures(Contract.Result<String>().Length == this.Length + value.Length); Contract.EndContractBlock(); @@ -546,7 +546,7 @@ namespace System // public static String Join(String separator, params String[] value) { if (value==null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); return Join(separator, value, 0, value.Length); } @@ -555,7 +555,7 @@ namespace System public static string Join(string separator, params object[] values) { if (values == null) - throw new ArgumentNullException("values"); + throw new ArgumentNullException(nameof(values)); Contract.EndContractBlock(); if (values.Length == 0 || values[0] == null) @@ -588,7 +588,7 @@ namespace System public static String Join<T>(String separator, IEnumerable<T> values) { if (values == null) - throw new ArgumentNullException("values"); + throw new ArgumentNullException(nameof(values)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -638,7 +638,7 @@ namespace System [ComVisible(false)] public static String Join(String separator, IEnumerable<String> values) { if (values == null) - throw new ArgumentNullException("values"); + throw new ArgumentNullException(nameof(values)); Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -671,15 +671,15 @@ namespace System public unsafe static String Join(String separator, String[] value, int startIndex, int count) { //Range check the array if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); if (startIndex > value.Length - count) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); //Treat null as empty string. @@ -749,7 +749,7 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public String PadLeft(int totalWidth, char paddingChar) { if (totalWidth < 0) - throw new ArgumentOutOfRangeException("totalWidth", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(totalWidth), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); int oldLength = Length; int count = totalWidth - oldLength; if (count <= 0) @@ -779,7 +779,7 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public String PadRight(int totalWidth, char paddingChar) { if (totalWidth < 0) - throw new ArgumentOutOfRangeException("totalWidth", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(totalWidth), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); int oldLength = Length; int count = totalWidth - oldLength; if (count <= 0) @@ -804,13 +804,13 @@ namespace System public String Remove(int startIndex, int count) { if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); if (count > Length - startIndex) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); Contract.Ensures(Contract.Result<String>() != null); Contract.Ensures(Contract.Result<String>().Length == this.Length - count); @@ -840,12 +840,12 @@ namespace System // a remove that just takes a startindex. public string Remove( int startIndex ) { if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (startIndex >= Length) { - throw new ArgumentOutOfRangeException("startIndex", + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndexLessThanLength")); } @@ -935,7 +935,7 @@ namespace System public String Replace(String oldValue, String newValue) { if (oldValue == null) - throw new ArgumentNullException("oldValue"); + throw new ArgumentNullException(nameof(oldValue)); // Note that if newValue is null, we treat it like String.Empty. Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -1018,7 +1018,7 @@ namespace System private unsafe String[] SplitInternal(char* separators, int separatorsLength, int count, StringSplitOptions options) { if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); if (options < StringSplitOptions.None || options > StringSplitOptions.RemoveEmptyEntries) @@ -1089,7 +1089,7 @@ namespace System private String[] SplitInternal(String separator, String[] separators, Int32 count, StringSplitOptions options) { if (count < 0) { - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); } @@ -1357,19 +1357,19 @@ namespace System //Bounds Checking. if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (startIndex > Length) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndexLargerThanLength")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndexLargerThanLength")); } if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); } if (startIndex > Length - length) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_IndexLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_IndexLength")); } Contract.EndContractBlock(); @@ -1412,7 +1412,7 @@ namespace System public String ToLower(CultureInfo culture) { if (culture == null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -1441,7 +1441,7 @@ namespace System public String ToUpper(CultureInfo culture) { if (culture == null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/String.Searching.cs b/src/mscorlib/src/System/String.Searching.cs index b972529694..30933dbb73 100644 --- a/src/mscorlib/src/System/String.Searching.cs +++ b/src/mscorlib/src/System/String.Searching.cs @@ -32,10 +32,10 @@ namespace System [System.Security.SecuritySafeCritical] // auto-generated public unsafe int IndexOf(char value, int startIndex, int count) { if (startIndex < 0 || startIndex > Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count < 0 || count > Length - startIndex) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); fixed (char* pChars = &m_firstChar) { @@ -116,11 +116,11 @@ namespace System [Pure] public int IndexOf(String value, int startIndex, int count) { if (startIndex < 0 || startIndex > this.Length) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (count < 0 || count > this.Length - startIndex) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); } Contract.EndContractBlock(); @@ -142,13 +142,13 @@ namespace System public int IndexOf(String value, int startIndex, int count, StringComparison comparisonType) { // Validate inputs if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex < 0 || startIndex > this.Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count < 0 || startIndex > this.Length - count) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); Contract.EndContractBlock(); switch (comparisonType) { @@ -174,7 +174,7 @@ namespace System return TextInfo.IndexOfStringOrdinalIgnoreCase(this, value, startIndex, count); default: - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } } @@ -200,10 +200,10 @@ namespace System return -1; if (startIndex < 0 || startIndex >= Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count < 0 || count - 1 > startIndex) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); fixed (char* pChars = &m_firstChar) { @@ -281,7 +281,7 @@ namespace System [Pure] public int LastIndexOf(String value, int startIndex, int count) { if (count<0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); } Contract.EndContractBlock(); @@ -302,7 +302,7 @@ namespace System [System.Security.SecuritySafeCritical] public int LastIndexOf(String value, int startIndex, int count, StringComparison comparisonType) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Special case for 0 length input strings @@ -311,7 +311,7 @@ namespace System // Now after handling empty strings, make sure we're not out of range if (startIndex < 0 || startIndex > this.Length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); // Make sure that we allow startIndex == this.Length if (startIndex == this.Length) @@ -327,7 +327,7 @@ namespace System // 2nd half of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0. if (count < 0 || startIndex - count + 1 < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Count")); switch (comparisonType) { @@ -351,7 +351,7 @@ namespace System else return TextInfo.LastIndexOfStringOrdinalIgnoreCase(this, value, startIndex, count); default: - throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), "comparisonType"); + throw new ArgumentException(Environment.GetResourceString("NotSupported_StringComparison"), nameof(comparisonType)); } } } diff --git a/src/mscorlib/src/System/String.cs b/src/mscorlib/src/System/String.cs index bcf869fe14..f2de71169b 100644 --- a/src/mscorlib/src/System/String.cs +++ b/src/mscorlib/src/System/String.cs @@ -115,15 +115,15 @@ namespace System { unsafe public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) { if (destination == null) - throw new ArgumentNullException("destination"); + throw new ArgumentNullException(nameof(destination)); if (count < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); if (sourceIndex < 0) - throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (count > Length - sourceIndex) - throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); if (destinationIndex > destination.Length - count || destinationIndex < 0) - throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); + throw new ArgumentOutOfRangeException(nameof(destinationIndex), Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); Contract.EndContractBlock(); // Note: fixed does not like empty arrays @@ -163,9 +163,9 @@ namespace System { { // Range check everything. if (startIndex < 0 || startIndex > Length || startIndex > Length - length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); if (length < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); if (length > 0) @@ -242,12 +242,12 @@ namespace System { return new String(value, startIndex, length); // default to ANSI if (length < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); if ((value + startIndex) < value) { // overflow check - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); } byte [] b = new byte[length]; @@ -258,7 +258,7 @@ namespace System { catch(NullReferenceException) { // If we got a NullReferencException. It means the pointer or // the index is out of range - throw new ArgumentOutOfRangeException("value", + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); } @@ -455,16 +455,16 @@ namespace System { private String CtorCharArrayStartLength(char [] value, int startIndex, int length) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (startIndex < 0) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); if (length < 0) - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); if (startIndex > value.Length - length) - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); if (length > 0) { @@ -519,7 +519,7 @@ namespace System { else if (count == 0) return String.Empty; else - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "count")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "count")); } [System.Security.SecurityCritical] // auto-generated @@ -641,7 +641,7 @@ namespace System { return result; } catch (NullReferenceException) { - throw new ArgumentOutOfRangeException("ptr", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); + throw new ArgumentOutOfRangeException(nameof(ptr), Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); } } @@ -649,11 +649,11 @@ namespace System { private unsafe String CtorCharPtrStartLength(char *ptr, int startIndex, int length) { if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); } if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } Contract.EndContractBlock(); Contract.Assert(this == null, "this == null"); // this is the string constructor, we allocate it @@ -661,7 +661,7 @@ namespace System { char *pFrom = ptr + startIndex; if (pFrom < ptr) { // This means that the pointer operation has had an overflow - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); } if (length == 0) @@ -675,7 +675,7 @@ namespace System { return result; } catch (NullReferenceException) { - throw new ArgumentOutOfRangeException("ptr", Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); + throw new ArgumentOutOfRangeException(nameof(ptr), Environment.GetResourceString("ArgumentOutOfRange_PartialWCHAR")); } } @@ -708,7 +708,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated unsafe public static String Copy (String str) { if (str==null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -727,7 +727,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated public static String Intern(String str) { if (str==null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.Ensures(Contract.Result<String>().Length == str.Length); Contract.Ensures(str.Equals(Contract.Result<String>())); @@ -740,7 +740,7 @@ namespace System { [System.Security.SecuritySafeCritical] // auto-generated public static String IsInterned(String str) { if (str==null) { - throw new ArgumentNullException("str"); + throw new ArgumentNullException(nameof(str)); } Contract.Ensures(Contract.Result<String>() == null || Contract.Result<String>().Length == str.Length); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/StringComparer.cs b/src/mscorlib/src/System/StringComparer.cs index 57bdf4c6b2..38964f02a2 100644 --- a/src/mscorlib/src/System/StringComparer.cs +++ b/src/mscorlib/src/System/StringComparer.cs @@ -64,7 +64,7 @@ namespace System { public static StringComparer Create(CultureInfo culture, bool ignoreCase) { if( culture == null) { - throw new ArgumentNullException("culture"); + throw new ArgumentNullException(nameof(culture)); } Contract.Ensures(Contract.Result<StringComparer>() != null); Contract.EndContractBlock(); @@ -110,7 +110,7 @@ namespace System { public int GetHashCode(object obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -161,7 +161,7 @@ namespace System { public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -229,7 +229,7 @@ namespace System { public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -311,7 +311,7 @@ namespace System { public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -388,7 +388,7 @@ namespace System { [System.Security.SecuritySafeCritical] public override int GetHashCode(string obj) { if( obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/StubHelpers.cs b/src/mscorlib/src/System/StubHelpers.cs index a9c584e9fc..34745e5155 100644 --- a/src/mscorlib/src/System/StubHelpers.cs +++ b/src/mscorlib/src/System/StubHelpers.cs @@ -1780,7 +1780,7 @@ namespace System.StubHelpers { { if (pHandle == null) { - throw new ArgumentNullException("pHandle", Environment.GetResourceString("ArgumentNull_SafeHandle")); + throw new ArgumentNullException(nameof(pHandle), Environment.GetResourceString("ArgumentNull_SafeHandle")); } Contract.EndContractBlock(); @@ -1796,7 +1796,7 @@ namespace System.StubHelpers { { if (pHandle == null) { - throw new ArgumentNullException("pHandle", Environment.GetResourceString("ArgumentNull_SafeHandle")); + throw new ArgumentNullException(nameof(pHandle), Environment.GetResourceString("ArgumentNull_SafeHandle")); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Text/ASCIIEncoding.cs b/src/mscorlib/src/System/Text/ASCIIEncoding.cs index bf1a62df55..2f653e4c5f 100644 --- a/src/mscorlib/src/System/Text/ASCIIEncoding.cs +++ b/src/mscorlib/src/System/Text/ASCIIEncoding.cs @@ -708,7 +708,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -721,7 +721,7 @@ namespace System.Text // 1 to 1 for most characters. Only surrogates with fallbacks have less. if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -729,7 +729,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -741,7 +741,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/BaseCodePageEncoding.cs b/src/mscorlib/src/System/Text/BaseCodePageEncoding.cs index 4c9ca6eaaf..8d22b8be93 100644 --- a/src/mscorlib/src/System/Text/BaseCodePageEncoding.cs +++ b/src/mscorlib/src/System/Text/BaseCodePageEncoding.cs @@ -175,7 +175,7 @@ namespace System.Text internal BaseCodePageEncoding(SerializationInfo info, StreamingContext context) : base(0) { // We cannot ever call this, we've proxied ourselved to CodePageEncoding - throw new ArgumentNullException("this"); + throw new ArgumentNullException(nameof(this)); } // ISerializable implementation diff --git a/src/mscorlib/src/System/Text/CodePageEncoding.cs b/src/mscorlib/src/System/Text/CodePageEncoding.cs index 9f1b2d2620..5ab73fc11c 100644 --- a/src/mscorlib/src/System/Text/CodePageEncoding.cs +++ b/src/mscorlib/src/System/Text/CodePageEncoding.cs @@ -44,7 +44,7 @@ namespace System.Text internal CodePageEncoding(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All versions have a code page @@ -113,7 +113,7 @@ namespace System.Text internal Decoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); this.realEncoding = (Encoding)info.GetValue("encoding", typeof(Encoding)); diff --git a/src/mscorlib/src/System/Text/DBCSCodePageEncoding.cs b/src/mscorlib/src/System/Text/DBCSCodePageEncoding.cs index c103d7898f..57468db9aa 100644 --- a/src/mscorlib/src/System/Text/DBCSCodePageEncoding.cs +++ b/src/mscorlib/src/System/Text/DBCSCodePageEncoding.cs @@ -62,7 +62,7 @@ namespace System.Text { // Actually this can't ever get called, CodePageEncoding is our proxy Contract.Assert(false, "Didn't expect to make it to DBCSCodePageEncoding serialization constructor"); - throw new ArgumentNullException("this"); + throw new ArgumentNullException(nameof(this)); } // MBCS data section: @@ -1129,7 +1129,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1143,7 +1143,7 @@ namespace System.Text byteCount *= 2; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -1151,7 +1151,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1163,7 +1163,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/Decoder.cs b/src/mscorlib/src/System/Text/Decoder.cs index f794dc4dce..6c1b7e2b23 100644 --- a/src/mscorlib/src/System/Text/Decoder.cs +++ b/src/mscorlib/src/System/Text/Decoder.cs @@ -49,13 +49,13 @@ namespace System.Text set { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Can't change fallback if buffer is wrong if (m_fallbackBuffer != null && m_fallbackBuffer.Remaining > 0) throw new ArgumentException( - Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), "value"); + Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), nameof(value)); m_fallback = value; m_fallbackBuffer = null; @@ -131,11 +131,11 @@ namespace System.Text { // Validate input parameters if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -197,11 +197,11 @@ namespace System.Text { // Validate input parameters if (chars == null || bytes == null) - throw new ArgumentNullException(chars == null ? "chars" : "bytes", + throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((byteCount<0 ? "byteCount" : "charCount"), + throw new ArgumentOutOfRangeException((byteCount<0 ? nameof(byteCount) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -256,23 +256,23 @@ namespace System.Text { // Validate parameters if (bytes == null || chars == null) - throw new ArgumentNullException((bytes == null ? "bytes" : "chars"), + throw new ArgumentNullException((bytes == null ? nameof(bytes) : nameof(chars)), Environment.GetResourceString("ArgumentNull_Array")); if (byteIndex < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((byteIndex<0 ? "byteIndex" : "byteCount"), + throw new ArgumentOutOfRangeException((byteIndex<0 ? nameof(byteIndex) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (charIndex < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"), + throw new ArgumentOutOfRangeException((charIndex<0 ? nameof(charIndex) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (bytes.Length - byteIndex < byteCount) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (chars.Length - charIndex < charCount) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -315,11 +315,11 @@ namespace System.Text { // Validate input parameters if (chars == null || bytes == null) - throw new ArgumentNullException(chars == null ? "chars" : "bytes", + throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((byteCount<0 ? "byteCount" : "charCount"), + throw new ArgumentOutOfRangeException((byteCount<0 ? nameof(byteCount) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Text/DecoderFallback.cs b/src/mscorlib/src/System/Text/DecoderFallback.cs index 1698fd37ab..24f33b90b1 100644 --- a/src/mscorlib/src/System/Text/DecoderFallback.cs +++ b/src/mscorlib/src/System/Text/DecoderFallback.cs @@ -277,7 +277,7 @@ namespace System.Text // Throw it, using our complete bytes throw new ArgumentException( Environment.GetResourceString("Argument_RecursiveFallbackBytes", - strBytes.ToString()), "bytesUnknown"); + strBytes.ToString()), nameof(bytesUnknown)); } } diff --git a/src/mscorlib/src/System/Text/DecoderNLS.cs b/src/mscorlib/src/System/Text/DecoderNLS.cs index c2e82dd250..56c95de567 100644 --- a/src/mscorlib/src/System/Text/DecoderNLS.cs +++ b/src/mscorlib/src/System/Text/DecoderNLS.cs @@ -82,15 +82,15 @@ namespace System.Text { // Validate Parameters if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (index < 0 || count < 0) - throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"), + throw new ArgumentOutOfRangeException((index<0 ? nameof(index) : nameof(count)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (bytes.Length - index < count) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -109,11 +109,11 @@ namespace System.Text { // Validate parameters if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -137,19 +137,19 @@ namespace System.Text { // Validate Parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (byteIndex < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((byteIndex<0 ? "byteIndex" : "byteCount"), + throw new ArgumentOutOfRangeException((byteIndex<0 ? nameof(byteIndex) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if ( bytes.Length - byteIndex < byteCount) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (charIndex < 0 || charIndex > chars.Length) - throw new ArgumentOutOfRangeException("charIndex", + throw new ArgumentOutOfRangeException(nameof(charIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); @@ -176,11 +176,11 @@ namespace System.Text { // Validate parameters if (chars == null || bytes == null) - throw new ArgumentNullException((chars == null ? "chars" : "bytes"), + throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((byteCount<0 ? "byteCount" : "charCount"), + throw new ArgumentOutOfRangeException((byteCount<0 ? nameof(byteCount) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -201,23 +201,23 @@ namespace System.Text { // Validate parameters if (bytes == null || chars == null) - throw new ArgumentNullException((bytes == null ? "bytes" : "chars"), + throw new ArgumentNullException((bytes == null ? nameof(bytes) : nameof(chars)), Environment.GetResourceString("ArgumentNull_Array")); if (byteIndex < 0 || byteCount < 0) - throw new ArgumentOutOfRangeException((byteIndex<0 ? "byteIndex" : "byteCount"), + throw new ArgumentOutOfRangeException((byteIndex<0 ? nameof(byteIndex) : nameof(byteCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (charIndex < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"), + throw new ArgumentOutOfRangeException((charIndex<0 ? nameof(charIndex) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (bytes.Length - byteIndex < byteCount) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (chars.Length - charIndex < charCount) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -248,11 +248,11 @@ namespace System.Text { // Validate input parameters if (chars == null || bytes == null) - throw new ArgumentNullException(chars == null ? "chars" : "bytes", + throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) - throw new ArgumentOutOfRangeException((byteCount<0 ? "byteCount" : "charCount"), + throw new ArgumentOutOfRangeException((byteCount<0 ? nameof(byteCount) : nameof(charCount)), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Text/DecoderReplacementFallback.cs b/src/mscorlib/src/System/Text/DecoderReplacementFallback.cs index c732d15816..44a34c14d1 100644 --- a/src/mscorlib/src/System/Text/DecoderReplacementFallback.cs +++ b/src/mscorlib/src/System/Text/DecoderReplacementFallback.cs @@ -21,7 +21,7 @@ namespace System.Text public DecoderReplacementFallback(String replacement) { if (replacement == null) - throw new ArgumentNullException("replacement"); + throw new ArgumentNullException(nameof(replacement)); Contract.EndContractBlock(); // Make sure it doesn't have bad surrogate pairs @@ -58,7 +58,7 @@ namespace System.Text break; } if (bFoundHigh) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex", "replacement")); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex", nameof(replacement))); strDefault = replacement; } diff --git a/src/mscorlib/src/System/Text/Encoder.cs b/src/mscorlib/src/System/Text/Encoder.cs index d223dd9d46..0f5ce8f6b3 100644 --- a/src/mscorlib/src/System/Text/Encoder.cs +++ b/src/mscorlib/src/System/Text/Encoder.cs @@ -49,13 +49,13 @@ namespace System.Text set { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); // Can't change fallback if buffer is wrong if (m_fallbackBuffer != null && m_fallbackBuffer.Remaining > 0) throw new ArgumentException( - Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), "value"); + Environment.GetResourceString("Argument_FallbackBufferNotEmpty"), nameof(value)); m_fallback = value; m_fallbackBuffer = null; @@ -127,11 +127,11 @@ namespace System.Text { // Validate input parameters if (chars == null) - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -190,7 +190,7 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) @@ -248,7 +248,7 @@ namespace System.Text { // Validate parameters if (chars == null || bytes == null) - throw new ArgumentNullException((chars == null ? "chars" : "bytes"), + throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), Environment.GetResourceString("ArgumentNull_Array")); if (charIndex < 0 || charCount < 0) @@ -260,11 +260,11 @@ namespace System.Text Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (chars.Length - charIndex < charCount) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (bytes.Length - byteIndex < byteCount) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -308,7 +308,7 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), diff --git a/src/mscorlib/src/System/Text/EncoderBestFitFallback.cs b/src/mscorlib/src/System/Text/EncoderBestFitFallback.cs index 352e9695cf..a2cb2ecb1b 100644 --- a/src/mscorlib/src/System/Text/EncoderBestFitFallback.cs +++ b/src/mscorlib/src/System/Text/EncoderBestFitFallback.cs @@ -117,12 +117,12 @@ namespace System.Text { // Double check input surrogate pair if (!Char.IsHighSurrogate(charUnknownHigh)) - throw new ArgumentOutOfRangeException("charUnknownHigh", + throw new ArgumentOutOfRangeException(nameof(charUnknownHigh), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xD800, 0xDBFF)); if (!Char.IsLowSurrogate(charUnknownLow)) - throw new ArgumentOutOfRangeException("CharUnknownLow", + throw new ArgumentOutOfRangeException(nameof(charUnknownLow), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xDC00, 0xDFFF)); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Text/EncoderExceptionFallback.cs b/src/mscorlib/src/System/Text/EncoderExceptionFallback.cs index 5ab51cb6dd..6735e7a5f8 100644 --- a/src/mscorlib/src/System/Text/EncoderExceptionFallback.cs +++ b/src/mscorlib/src/System/Text/EncoderExceptionFallback.cs @@ -62,13 +62,13 @@ namespace System.Text { if (!Char.IsHighSurrogate(charUnknownHigh)) { - throw new ArgumentOutOfRangeException("charUnknownHigh", + throw new ArgumentOutOfRangeException(nameof(charUnknownHigh), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xD800, 0xDBFF)); } if (!Char.IsLowSurrogate(charUnknownLow)) { - throw new ArgumentOutOfRangeException("CharUnknownLow", + throw new ArgumentOutOfRangeException(nameof(charUnknownLow), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xDC00, 0xDFFF)); } @@ -145,13 +145,13 @@ namespace System.Text { if (!Char.IsHighSurrogate(charUnknownHigh)) { - throw new ArgumentOutOfRangeException("charUnknownHigh", + throw new ArgumentOutOfRangeException(nameof(charUnknownHigh), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xD800, 0xDBFF)); } if (!Char.IsLowSurrogate(charUnknownLow)) { - throw new ArgumentOutOfRangeException("CharUnknownLow", + throw new ArgumentOutOfRangeException(nameof(CharUnknownLow), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xDC00, 0xDFFF)); } diff --git a/src/mscorlib/src/System/Text/EncoderNLS.cs b/src/mscorlib/src/System/Text/EncoderNLS.cs index d5c52f48d8..679898a408 100644 --- a/src/mscorlib/src/System/Text/EncoderNLS.cs +++ b/src/mscorlib/src/System/Text/EncoderNLS.cs @@ -82,7 +82,7 @@ namespace System.Text { // Validate input parameters if (chars == null) - throw new ArgumentNullException( "chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (index < 0 || count < 0) @@ -90,7 +90,7 @@ namespace System.Text Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (chars.Length - index < count) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -112,11 +112,11 @@ namespace System.Text { // Validate input parameters if (chars == null) - throw new ArgumentNullException( "chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -131,7 +131,7 @@ namespace System.Text { // Validate parameters if (chars == null || bytes == null) - throw new ArgumentNullException((chars == null ? "chars" : "bytes"), + throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), Environment.GetResourceString("ArgumentNull_Array")); if (charIndex < 0 || charCount < 0) @@ -139,11 +139,11 @@ namespace System.Text Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (chars.Length - charIndex < charCount) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (byteIndex < 0 || byteIndex > bytes.Length) - throw new ArgumentOutOfRangeException("byteIndex", + throw new ArgumentOutOfRangeException(nameof(byteIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); Contract.EndContractBlock(); @@ -168,7 +168,7 @@ namespace System.Text { // Validate parameters if (chars == null || bytes == null) - throw new ArgumentNullException((chars == null ? "chars" : "bytes"), + throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) @@ -190,7 +190,7 @@ namespace System.Text { // Validate parameters if (chars == null || bytes == null) - throw new ArgumentNullException((chars == null ? "chars" : "bytes"), + throw new ArgumentNullException((chars == null ? nameof(chars) : nameof(bytes)), Environment.GetResourceString("ArgumentNull_Array")); if (charIndex < 0 || charCount < 0) @@ -202,11 +202,11 @@ namespace System.Text Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); if (chars.Length - charIndex < charCount) - throw new ArgumentOutOfRangeException("chars", + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); if (bytes.Length - byteIndex < byteCount) - throw new ArgumentOutOfRangeException("bytes", + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); Contract.EndContractBlock(); @@ -237,7 +237,7 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"), diff --git a/src/mscorlib/src/System/Text/EncoderReplacementFallback.cs b/src/mscorlib/src/System/Text/EncoderReplacementFallback.cs index 15dfee8912..026a642505 100644 --- a/src/mscorlib/src/System/Text/EncoderReplacementFallback.cs +++ b/src/mscorlib/src/System/Text/EncoderReplacementFallback.cs @@ -23,7 +23,7 @@ namespace System.Text { // Must not be null if (replacement == null) - throw new ArgumentNullException("replacement"); + throw new ArgumentNullException(nameof(replacement)); Contract.EndContractBlock(); // Make sure it doesn't have bad surrogate pairs @@ -60,7 +60,7 @@ namespace System.Text break; } if (bFoundHigh) - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex", "replacement")); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex", nameof(replacement))); strDefault = replacement; } @@ -147,12 +147,12 @@ namespace System.Text { // Double check input surrogate pair if (!Char.IsHighSurrogate(charUnknownHigh)) - throw new ArgumentOutOfRangeException("charUnknownHigh", + throw new ArgumentOutOfRangeException(nameof(charUnknownHigh), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xD800, 0xDBFF)); if (!Char.IsLowSurrogate(charUnknownLow)) - throw new ArgumentOutOfRangeException("CharUnknownLow", + throw new ArgumentOutOfRangeException(nameof(charUnknownLow), Environment.GetResourceString("ArgumentOutOfRange_Range", 0xDC00, 0xDFFF)); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Text/Encoding.cs b/src/mscorlib/src/System/Text/Encoding.cs index 8533016293..50fca03ce7 100644 --- a/src/mscorlib/src/System/Text/Encoding.cs +++ b/src/mscorlib/src/System/Text/Encoding.cs @@ -189,7 +189,7 @@ namespace System.Text // Validate code page if (codePage < 0) { - throw new ArgumentOutOfRangeException("codePage"); + throw new ArgumentOutOfRangeException(nameof(codePage)); } Contract.EndContractBlock(); @@ -208,7 +208,7 @@ namespace System.Text // Validate code page if (codePage < 0) { - throw new ArgumentOutOfRangeException("codePage"); + throw new ArgumentOutOfRangeException(nameof(codePage)); } Contract.EndContractBlock(); @@ -275,7 +275,7 @@ namespace System.Text internal void DeserializeEncoding(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All versions have a code page @@ -314,7 +314,7 @@ namespace System.Text internal void SerializeEncoding(SerializationInfo info, StreamingContext context) { // Any Info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // These are new V2.0 Whidbey stuff @@ -344,7 +344,7 @@ namespace System.Text public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes) { if (bytes==null) - throw new ArgumentNullException("bytes"); + throw new ArgumentNullException(nameof(bytes)); Contract.Ensures(Contract.Result<byte[]>() != null); return Convert(srcEncoding, dstEncoding, bytes, 0, bytes.Length); @@ -359,11 +359,11 @@ namespace System.Text public static byte[] Convert(Encoding srcEncoding, Encoding dstEncoding, byte[] bytes, int index, int count) { if (srcEncoding == null || dstEncoding == null) { - throw new ArgumentNullException((srcEncoding == null ? "srcEncoding" : "dstEncoding"), + throw new ArgumentNullException((srcEncoding == null ? nameof(srcEncoding) : nameof(dstEncoding)), Environment.GetResourceString("ArgumentNull_Array")); } if (bytes == null) { - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } Contract.Ensures(Contract.Result<byte[]>() != null); @@ -416,7 +416,7 @@ namespace System.Text // if (codepage < 0 || codepage > 65535) { throw new ArgumentOutOfRangeException( - "codepage", Environment.GetResourceString("ArgumentOutOfRange_Range", + nameof(codepage), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, 65535)); } @@ -795,7 +795,7 @@ namespace System.Text throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); encoderFallback = value; @@ -817,7 +817,7 @@ namespace System.Text throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly")); if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); Contract.EndContractBlock(); decoderFallback = value; @@ -865,7 +865,7 @@ namespace System.Text { if (chars == null) { - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -877,7 +877,7 @@ namespace System.Text public virtual int GetByteCount(String s) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); Contract.EndContractBlock(); char[] chars = s.ToCharArray(); @@ -903,11 +903,11 @@ namespace System.Text { // Validate input parameters if (chars == null) - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -939,7 +939,7 @@ namespace System.Text { if (chars == null) { - throw new ArgumentNullException("chars", + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -976,7 +976,7 @@ namespace System.Text public virtual byte[] GetBytes(String s) { if (s == null) - throw new ArgumentNullException("s", + throw new ArgumentNullException(nameof(s), Environment.GetResourceString("ArgumentNull_String")); Contract.EndContractBlock(); @@ -991,7 +991,7 @@ namespace System.Text byte[] bytes, int byteIndex) { if (s==null) - throw new ArgumentNullException("s"); + throw new ArgumentNullException(nameof(s)); Contract.EndContractBlock(); return GetBytes(s.ToCharArray(), charIndex, charCount, bytes, byteIndex); } @@ -1030,7 +1030,7 @@ namespace System.Text { // Validate input parameters if (bytes == null || chars == null) - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); if (charCount < 0 || byteCount < 0) @@ -1076,7 +1076,7 @@ namespace System.Text { if (bytes == null) { - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -1099,11 +1099,11 @@ namespace System.Text { // Validate input parameters if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (count < 0) - throw new ArgumentOutOfRangeException("count", + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1132,7 +1132,7 @@ namespace System.Text { if (bytes == null) { - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } Contract.EndContractBlock(); @@ -1189,7 +1189,7 @@ namespace System.Text { // Validate input parameters if (chars == null || bytes == null) - throw new ArgumentNullException(chars == null ? "chars" : "bytes", + throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0 || charCount < 0) @@ -1244,10 +1244,10 @@ namespace System.Text public unsafe string GetString(byte* bytes, int byteCount) { if (bytes == null) - throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); return String.CreateStringFromEncoding(bytes, byteCount, this); @@ -1391,7 +1391,7 @@ namespace System.Text public virtual String GetString(byte[] bytes) { if (bytes == null) - throw new ArgumentNullException("bytes", + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); Contract.EndContractBlock(); @@ -1541,7 +1541,7 @@ namespace System.Text // Constructor called by serialization, have to handle deserializing from Everett internal DefaultEncoder(SerializationInfo info, StreamingContext context) { - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1588,7 +1588,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1667,7 +1667,7 @@ namespace System.Text internal DefaultDecoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding @@ -1709,7 +1709,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All we have is our encoding diff --git a/src/mscorlib/src/System/Text/EncodingForwarder.cs b/src/mscorlib/src/System/Text/EncodingForwarder.cs index d4bcf800e3..d085667f97 100644 --- a/src/mscorlib/src/System/Text/EncodingForwarder.cs +++ b/src/mscorlib/src/System/Text/EncodingForwarder.cs @@ -39,7 +39,7 @@ namespace System.Text Contract.Assert(encoding != null); // this parameter should only be affected internally, so just do a debug check here if (chars == null) { - throw new ArgumentNullException("chars", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } if (index < 0 || count < 0) { @@ -47,7 +47,7 @@ namespace System.Text } if (chars.Length - index < count) { - throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } Contract.EndContractBlock(); @@ -90,11 +90,11 @@ namespace System.Text Contract.Assert(encoding != null); if (chars == null) { - throw new ArgumentNullException("chars", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -108,22 +108,22 @@ namespace System.Text Contract.Assert(encoding != null); if (s == null || bytes == null) { - string stringName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the first parameter chars - throw new ArgumentNullException(s == null ? stringName : "bytes", Environment.GetResourceString("ArgumentNull_Array")); + string stringName = encoding is ASCIIEncoding ? "chars" : nameof(s); // ASCIIEncoding calls the first parameter chars + throw new ArgumentNullException(s == null ? stringName : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } if (charIndex < 0 || charCount < 0) { - throw new ArgumentOutOfRangeException(charIndex < 0 ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (s.Length - charIndex < charCount) { - string stringName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the first parameter chars + string stringName = encoding is ASCIIEncoding ? "chars" : nameof(s); // ASCIIEncoding calls the first parameter chars // Duplicate the above check since we don't want the overhead of a type check on the general path throw new ArgumentOutOfRangeException(stringName, Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); } if (byteIndex < 0 || byteIndex > bytes.Length) { - throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(byteIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); @@ -145,19 +145,19 @@ namespace System.Text Contract.Assert(encoding != null); if (chars == null || bytes == null) { - throw new ArgumentNullException(chars == null ? "chars" : "bytes", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(chars == null ? nameof(chars) : nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } if (charIndex < 0 || charCount < 0) { - throw new ArgumentOutOfRangeException(charIndex < 0 ? "charIndex" : "charCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(charIndex < 0 ? nameof(charIndex) : nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (chars.Length - charIndex < charCount) { - throw new ArgumentOutOfRangeException("chars", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); + throw new ArgumentOutOfRangeException(nameof(chars), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } if (byteIndex < 0 || byteIndex > bytes.Length) { - throw new ArgumentOutOfRangeException("byteIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(byteIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); @@ -186,11 +186,11 @@ namespace System.Text Contract.Assert(encoding != null); if (bytes == null || chars == null) { - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } if (charCount < 0 || byteCount < 0) { - throw new ArgumentOutOfRangeException(charCount < 0 ? "charCount" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -203,7 +203,7 @@ namespace System.Text Contract.Assert(encoding != null); if (bytes == null) { - throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } if (index < 0 || count < 0) { @@ -211,7 +211,7 @@ namespace System.Text } if (bytes.Length - index < count) { - throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } Contract.EndContractBlock(); @@ -230,11 +230,11 @@ namespace System.Text Contract.Assert(encoding != null); if (bytes == null) { - throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -247,19 +247,19 @@ namespace System.Text Contract.Assert(encoding != null); if (bytes == null || chars == null) { - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } if (byteIndex < 0 || byteCount < 0) { - throw new ArgumentOutOfRangeException(byteIndex < 0 ? "byteIndex" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(byteIndex < 0 ? nameof(byteIndex) : nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (bytes.Length - byteIndex < byteCount) { - throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } if (charIndex < 0 || charIndex > chars.Length) { - throw new ArgumentOutOfRangeException("charIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(charIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.EndContractBlock(); @@ -286,11 +286,11 @@ namespace System.Text Contract.Assert(encoding != null); if (bytes == null || chars == null) { - throw new ArgumentNullException(bytes == null ? "bytes" : "chars", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(bytes == null ? nameof(bytes) : nameof(chars), Environment.GetResourceString("ArgumentNull_Array")); } if (charCount < 0 || byteCount < 0) { - throw new ArgumentOutOfRangeException(charCount < 0 ? "charCount" : "byteCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(charCount < 0 ? nameof(charCount) : nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.EndContractBlock(); @@ -303,19 +303,19 @@ namespace System.Text Contract.Assert(encoding != null); if (bytes == null) { - throw new ArgumentNullException("bytes", Environment.GetResourceString("ArgumentNull_Array")); + throw new ArgumentNullException(nameof(bytes), Environment.GetResourceString("ArgumentNull_Array")); } if (index < 0 || count < 0) { // ASCIIEncoding has different names for its parameters here (byteIndex, byteCount) bool ascii = encoding is ASCIIEncoding; - string indexName = ascii ? "byteIndex" : "index"; - string countName = ascii ? "byteCount" : "count"; + string indexName = ascii ? "byteIndex" : nameof(index); + string countName = ascii ? "byteCount" : nameof(count); throw new ArgumentOutOfRangeException(index < 0 ? indexName : countName, Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (bytes.Length - index < count) { - throw new ArgumentOutOfRangeException("bytes", Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); + throw new ArgumentOutOfRangeException(nameof(bytes), Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer")); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Text/EncodingProvider.cs b/src/mscorlib/src/System/Text/EncodingProvider.cs index b1dea2cd3c..a7f745a753 100644 --- a/src/mscorlib/src/System/Text/EncodingProvider.cs +++ b/src/mscorlib/src/System/Text/EncodingProvider.cs @@ -45,7 +45,7 @@ namespace System.Text internal static void AddProvider(EncodingProvider provider) { if (provider == null) - throw new ArgumentNullException("provider"); + throw new ArgumentNullException(nameof(provider)); lock (s_InternalSyncObject) { diff --git a/src/mscorlib/src/System/Text/GB18030Encoding.cs b/src/mscorlib/src/System/Text/GB18030Encoding.cs index 98746fcdb0..324d03485c 100644 --- a/src/mscorlib/src/System/Text/GB18030Encoding.cs +++ b/src/mscorlib/src/System/Text/GB18030Encoding.cs @@ -793,7 +793,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -807,7 +807,7 @@ namespace System.Text byteCount *= 4; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -815,7 +815,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -828,7 +828,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } @@ -856,7 +856,7 @@ namespace System.Text internal GB18030Decoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); try @@ -883,7 +883,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Save Whidbey data diff --git a/src/mscorlib/src/System/Text/ISCIIEncoding.cs b/src/mscorlib/src/System/Text/ISCIIEncoding.cs index 89d9c9953a..50f710041c 100644 --- a/src/mscorlib/src/System/Text/ISCIIEncoding.cs +++ b/src/mscorlib/src/System/Text/ISCIIEncoding.cs @@ -111,7 +111,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -125,7 +125,7 @@ namespace System.Text byteCount *= 4; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -135,7 +135,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -149,7 +149,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/ISO2022Encoding.cs b/src/mscorlib/src/System/Text/ISO2022Encoding.cs index fe57e7cc57..f7e0616463 100644 --- a/src/mscorlib/src/System/Text/ISO2022Encoding.cs +++ b/src/mscorlib/src/System/Text/ISO2022Encoding.cs @@ -1754,7 +1754,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1801,7 +1801,7 @@ namespace System.Text byteCount += extraStart + extraEnd; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -1809,7 +1809,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1839,7 +1839,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/Latin1Encoding.cs b/src/mscorlib/src/System/Text/Latin1Encoding.cs index a24f9c00ae..a4b863dd99 100644 --- a/src/mscorlib/src/System/Text/Latin1Encoding.cs +++ b/src/mscorlib/src/System/Text/Latin1Encoding.cs @@ -446,7 +446,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -459,14 +459,14 @@ namespace System.Text // 1 to 1 for most characters. Only surrogates with fallbacks have less. if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -478,7 +478,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/MLangCodePageEncoding.cs b/src/mscorlib/src/System/Text/MLangCodePageEncoding.cs index 53924a936d..e65bceec15 100644 --- a/src/mscorlib/src/System/Text/MLangCodePageEncoding.cs +++ b/src/mscorlib/src/System/Text/MLangCodePageEncoding.cs @@ -46,7 +46,7 @@ namespace System.Text internal MLangCodePageEncoding(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All versions have a code page @@ -115,7 +115,7 @@ namespace System.Text internal MLangEncoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); this.realEncoding = (Encoding)info.GetValue("m_encoding", typeof(Encoding)); @@ -151,7 +151,7 @@ namespace System.Text internal MLangDecoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); this.realEncoding = (Encoding)info.GetValue("m_encoding", typeof(Encoding)); diff --git a/src/mscorlib/src/System/Text/Normalization.Windows.cs b/src/mscorlib/src/System/Text/Normalization.Windows.cs index 832eef547d..7820bbe94e 100644 --- a/src/mscorlib/src/System/Text/Normalization.Windows.cs +++ b/src/mscorlib/src/System/Text/Normalization.Windows.cs @@ -175,7 +175,7 @@ namespace System.Text case ERROR_NO_UNICODE_TRANSLATION: throw new ArgumentException( Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex" ), - "strInput"); + nameof(strInput)); case ERROR_NOT_ENOUGH_MEMORY: throw new OutOfMemoryException( Environment.GetResourceString("Arg_OutOfMemoryException")); @@ -205,7 +205,7 @@ namespace System.Text if (iError == ERROR_INVALID_PARAMETER) throw new ArgumentException( Environment.GetResourceString("Argument_InvalidCharSequenceNoIndex" ), - "strInput"); + nameof(strInput)); // We shouldn't really be able to get here..., guessing length is // a trivial math function... @@ -254,7 +254,7 @@ namespace System.Text // Illegal code point or order found. Ie: FFFE or D800 D800, etc. throw new ArgumentException( Environment.GetResourceString("Argument_InvalidCharSequence", iLength ), - "strInput"); + nameof(strInput)); case ERROR_NOT_ENOUGH_MEMORY: throw new OutOfMemoryException( Environment.GetResourceString("Arg_OutOfMemoryException")); diff --git a/src/mscorlib/src/System/Text/SBCSCodePageEncoding.cs b/src/mscorlib/src/System/Text/SBCSCodePageEncoding.cs index ce611d8b1f..dba223e029 100644 --- a/src/mscorlib/src/System/Text/SBCSCodePageEncoding.cs +++ b/src/mscorlib/src/System/Text/SBCSCodePageEncoding.cs @@ -54,7 +54,7 @@ namespace System.Text { // Actually this can't ever get called, CodePageEncoding is our proxy Contract.Assert(false, "Didn't expect to make it to SBCSCodePageEncoding serialization constructor"); - throw new ArgumentNullException("this"); + throw new ArgumentNullException(nameof(this)); } // We have a managed code page entry, so load our tables @@ -892,7 +892,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -905,14 +905,14 @@ namespace System.Text // 1 to 1 for most characters. Only surrogates with fallbacks have less. if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -924,7 +924,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/StringBuilder.cs b/src/mscorlib/src/System/Text/StringBuilder.cs index e4800e3052..b1ae902d90 100644 --- a/src/mscorlib/src/System/Text/StringBuilder.cs +++ b/src/mscorlib/src/System/Text/StringBuilder.cs @@ -120,15 +120,15 @@ namespace System.Text { [System.Security.SecuritySafeCritical] // auto-generated public StringBuilder(String value, int startIndex, int length, int capacity) { if (capacity<0) { - throw new ArgumentOutOfRangeException("capacity", + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_MustBePositive", "capacity")); } if (length<0) { - throw new ArgumentOutOfRangeException("length", + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "length")); } if (startIndex<0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } Contract.EndContractBlock(); @@ -136,7 +136,7 @@ namespace System.Text { value = String.Empty; } if (startIndex > value.Length - length) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_IndexLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_IndexLength")); } m_MaxCapacity = Int32.MaxValue; if (capacity == 0) { @@ -158,13 +158,13 @@ namespace System.Text { // and a maximum capacity of maxCapacity. public StringBuilder(int capacity, int maxCapacity) { if (capacity>maxCapacity) { - throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_Capacity")); + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_Capacity")); } if (maxCapacity<1) { - throw new ArgumentOutOfRangeException("maxCapacity", Environment.GetResourceString("ArgumentOutOfRange_SmallMaxCapacity")); + throw new ArgumentOutOfRangeException(nameof(maxCapacity), Environment.GetResourceString("ArgumentOutOfRange_SmallMaxCapacity")); } if (capacity<0) { - throw new ArgumentOutOfRangeException("capacity", + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_MustBePositive", "capacity")); } Contract.EndContractBlock(); @@ -180,7 +180,7 @@ namespace System.Text { [System.Security.SecurityCritical] // auto-generated private StringBuilder(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); int persistedCapacity = 0; @@ -244,7 +244,7 @@ namespace System.Text { void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -287,13 +287,13 @@ namespace System.Text { get { return m_ChunkChars.Length + m_ChunkOffset; } set { if (value < 0) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); } if (value > MaxCapacity) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_Capacity")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_Capacity")); } if (value < Length) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); } Contract.EndContractBlock(); @@ -317,7 +317,7 @@ namespace System.Text { // public int EnsureCapacity(int capacity) { if (capacity < 0) { - throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); + throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity")); } Contract.EndContractBlock(); @@ -357,7 +357,7 @@ namespace System.Text { } else { - throw new ArgumentOutOfRangeException("chunkLength", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(chunkLength), Environment.GetResourceString("ArgumentOutOfRange_Index")); } } chunk = chunk.m_ChunkPrevious; @@ -377,19 +377,19 @@ namespace System.Text { int currentLength = this.Length; if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (startIndex > currentLength) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndexLargerThanLength")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndexLargerThanLength")); } if (length < 0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); } if (startIndex > (currentLength - length)) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_IndexLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_IndexLength")); } VerifyClassInvariant(); @@ -433,7 +433,7 @@ namespace System.Text { } else { - throw new ArgumentOutOfRangeException("chunkCount", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(chunkCount), Environment.GetResourceString("ArgumentOutOfRange_Index")); } } } @@ -463,11 +463,11 @@ namespace System.Text { set { //If the new length is less than 0 or greater than our Maximum capacity, bail. if (value<0) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); } if (value>MaxCapacity) { - throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); + throw new ArgumentOutOfRangeException(nameof(value), Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity")); } Contract.EndContractBlock(); @@ -539,13 +539,13 @@ namespace System.Text { if (indexInBlock >= 0) { if (indexInBlock >= chunk.m_ChunkLength) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); chunk.m_ChunkChars[indexInBlock] = value; return; } chunk = chunk.m_ChunkPrevious; if (chunk == null) - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } } } @@ -553,7 +553,7 @@ namespace System.Text { // Appends a character at the end of this string builder. The capacity is adjusted as needed. public StringBuilder Append(char value, int repeatCount) { if (repeatCount<0) { - throw new ArgumentOutOfRangeException("repeatCount", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); + throw new ArgumentOutOfRangeException(nameof(repeatCount), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -594,10 +594,10 @@ namespace System.Text { [System.Security.SecuritySafeCritical] // auto-generated public StringBuilder Append(char[] value, int startIndex, int charCount) { if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if (charCount<0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -606,10 +606,10 @@ namespace System.Text { if (startIndex == 0 && charCount == 0) { return this; } - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (charCount > value.Length - startIndex) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (charCount==0) { @@ -688,11 +688,11 @@ namespace System.Text { [System.Security.SecuritySafeCritical] // auto-generated public StringBuilder Append(String value, int startIndex, int count) { if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); @@ -702,7 +702,7 @@ namespace System.Text { if (startIndex == 0 && count == 0) { return this; } - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } if (count == 0) { @@ -710,7 +710,7 @@ namespace System.Text { } if (startIndex > value.Length - count) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } unsafe @@ -741,15 +741,15 @@ namespace System.Text { [SecuritySafeCritical] public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) { if (destination == null) { - throw new ArgumentNullException("destination"); + throw new ArgumentNullException(nameof(destination)); } if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("Arg_NegativeArgCount")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("Arg_NegativeArgCount")); } if (destinationIndex < 0) { - throw new ArgumentOutOfRangeException("destinationIndex", + throw new ArgumentOutOfRangeException(nameof(destinationIndex), Environment.GetResourceString("ArgumentOutOfRange_MustBeNonNegNum", "destinationIndex")); } @@ -758,7 +758,7 @@ namespace System.Text { } if ((uint)sourceIndex > (uint)Length) { - throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (sourceIndex > Length - count) { @@ -805,7 +805,7 @@ namespace System.Text { [System.Security.SecuritySafeCritical] // auto-generated public StringBuilder Insert(int index, String value, int count) { if (count < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -813,7 +813,7 @@ namespace System.Text { //Range check the index. int currentLength = Length; if ((uint)index > (uint)currentLength) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } //If value is null, empty or count is 0, do nothing. This is ECMA standard. @@ -851,15 +851,15 @@ namespace System.Text { // public StringBuilder Remove(int startIndex, int length) { if (length<0) { - throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NegativeLength")); } if (startIndex<0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (length > Length - startIndex) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -1023,7 +1023,7 @@ namespace System.Text { [System.Security.SecuritySafeCritical] // auto-generated public StringBuilder Insert(int index, String value) { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -1100,7 +1100,7 @@ namespace System.Text { // public StringBuilder Insert(int index, char[] value) { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -1120,7 +1120,7 @@ namespace System.Text { int currentLength = Length; if ((uint)index > (uint)currentLength) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } //If they passed in a null char array, just jump out quickly. @@ -1129,20 +1129,20 @@ namespace System.Text { { return this; } - throw new ArgumentNullException("value", Environment.GetResourceString("ArgumentNull_String")); + throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String")); } //Range check the array. if (startIndex < 0) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_StartIndex")); } if (charCount < 0) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GenericPositive")); } if (startIndex > value.Length - charCount) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (charCount > 0) @@ -1263,7 +1263,7 @@ namespace System.Text { { // To preserve the original exception behavior, throw an exception about format if both // args and format are null. The actual null check for format is in AppendFormatHelper. - throw new ArgumentNullException((format == null) ? "format" : "args"); + throw new ArgumentNullException((format == null) ? nameof(format) : nameof(args)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -1291,7 +1291,7 @@ namespace System.Text { { // To preserve the original exception behavior, throw an exception about format if both // args and format are null. The actual null check for format is in AppendFormatHelper. - throw new ArgumentNullException((format == null) ? "format" : "args"); + throw new ArgumentNullException((format == null) ? nameof(format) : nameof(args)); } Contract.Ensures(Contract.Result<String>() != null); Contract.EndContractBlock(); @@ -1309,7 +1309,7 @@ namespace System.Text { internal StringBuilder AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args) { if (format == null) { - throw new ArgumentNullException("format"); + throw new ArgumentNullException(nameof(format)); } Contract.Ensures(Contract.Result<StringBuilder>() != null); Contract.EndContractBlock(); @@ -1590,19 +1590,19 @@ namespace System.Text { int currentLength = Length; if ((uint)startIndex > (uint)currentLength) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (count < 0 || startIndex > currentLength - count) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (oldValue == null) { - throw new ArgumentNullException("oldValue"); + throw new ArgumentNullException(nameof(oldValue)); } if (oldValue.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "oldValue"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(oldValue)); } if (newValue == null) @@ -1676,11 +1676,11 @@ namespace System.Text { int currentLength = Length; if ((uint)startIndex > (uint)currentLength) { - throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (count < 0 || startIndex > currentLength - count) { - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Index")); } int endIndex = startIndex + count; @@ -1717,7 +1717,7 @@ namespace System.Text { // We don't check null value as this case will throw null reference exception anyway if (valueCount < 0) { - throw new ArgumentOutOfRangeException("valueCount", Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); + throw new ArgumentOutOfRangeException(nameof(valueCount), Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); } // this is where we can check if the valueCount will put us over m_MaxCapacity @@ -1765,7 +1765,7 @@ namespace System.Text { { if ((uint)index > (uint)Length) { - throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_Index")); } if (valueCount > 0) @@ -1915,7 +1915,7 @@ namespace System.Text { } else { - throw new ArgumentOutOfRangeException("destinationIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(destinationIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } } } @@ -1933,7 +1933,7 @@ namespace System.Text { } else { - throw new ArgumentOutOfRangeException("sourceIndex", Environment.GetResourceString("ArgumentOutOfRange_Index")); + throw new ArgumentOutOfRangeException(nameof(sourceIndex), Environment.GetResourceString("ArgumentOutOfRange_Index")); } } } diff --git a/src/mscorlib/src/System/Text/SurrogateEncoder.cs b/src/mscorlib/src/System/Text/SurrogateEncoder.cs index 409e8a34aa..8ee41a3007 100644 --- a/src/mscorlib/src/System/Text/SurrogateEncoder.cs +++ b/src/mscorlib/src/System/Text/SurrogateEncoder.cs @@ -30,7 +30,7 @@ namespace System.Text internal SurrogateEncoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // All versions have a code page diff --git a/src/mscorlib/src/System/Text/UTF32Encoding.cs b/src/mscorlib/src/System/Text/UTF32Encoding.cs index 0bdbaefbf2..6973bb7c66 100644 --- a/src/mscorlib/src/System/Text/UTF32Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF32Encoding.cs @@ -296,7 +296,7 @@ namespace System.Text // Check for overflows. if (byteCount < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString( + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString( "ArgumentOutOfRange_GetByteCountOverflow")); // Shouldn't have anything in fallback buffer for GetByteCount @@ -635,7 +635,7 @@ namespace System.Text // Check for overflows. if (charCount < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); // Shouldn't have anything in fallback buffer for GetCharCount // (don't have to check m_throwOnOverflow for chars or count) @@ -885,7 +885,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -899,7 +899,7 @@ namespace System.Text byteCount *= 4; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -908,7 +908,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -929,7 +929,7 @@ namespace System.Text } if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } diff --git a/src/mscorlib/src/System/Text/UTF7Encoding.cs b/src/mscorlib/src/System/Text/UTF7Encoding.cs index 654fb8b80f..3270ca6b1d 100644 --- a/src/mscorlib/src/System/Text/UTF7Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF7Encoding.cs @@ -599,7 +599,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -623,7 +623,7 @@ namespace System.Text // check for overflow if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -632,7 +632,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -663,7 +663,7 @@ namespace System.Text internal Decoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Get common info @@ -678,7 +678,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Save Whidbey data @@ -727,7 +727,7 @@ namespace System.Text internal Encoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Get common info @@ -741,7 +741,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Save Whidbey data diff --git a/src/mscorlib/src/System/Text/UTF8Encoding.cs b/src/mscorlib/src/System/Text/UTF8Encoding.cs index a527de7b61..ddf8017843 100644 --- a/src/mscorlib/src/System/Text/UTF8Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF8Encoding.cs @@ -2085,7 +2085,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -2099,7 +2099,7 @@ namespace System.Text byteCount *= 3; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -2108,7 +2108,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -2123,7 +2123,7 @@ namespace System.Text } if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } @@ -2174,7 +2174,7 @@ namespace System.Text internal UTF8Encoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Get common info @@ -2198,7 +2198,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Save Whidbey data @@ -2247,7 +2247,7 @@ namespace System.Text internal UTF8Decoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Get common info @@ -2272,7 +2272,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Save new Whidbey data diff --git a/src/mscorlib/src/System/Text/UnicodeEncoding.cs b/src/mscorlib/src/System/Text/UnicodeEncoding.cs index 41d4f3b5ea..4cb1d24fd3 100644 --- a/src/mscorlib/src/System/Text/UnicodeEncoding.cs +++ b/src/mscorlib/src/System/Text/UnicodeEncoding.cs @@ -200,7 +200,7 @@ namespace System.Text // (If they were all invalid chars, this would actually be wrong, // but that's a ridiculously large # so we're not concerned about that case) if (byteCount < 0) - throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); char* charStart = chars; char* charEnd = chars + count; @@ -448,7 +448,7 @@ namespace System.Text // Throw it, using our complete character throw new ArgumentException( Environment.GetResourceString("Argument_RecursiveFallback", - charLeftOver), "chars"); + charLeftOver), nameof(chars)); } else { @@ -851,7 +851,7 @@ namespace System.Text // Throw it, using our complete character throw new ArgumentException( Environment.GetResourceString("Argument_RecursiveFallback", - charLeftOver), "chars"); + charLeftOver), nameof(chars)); } else { @@ -1697,7 +1697,7 @@ namespace System.Text public override int GetMaxByteCount(int charCount) { if (charCount < 0) - throw new ArgumentOutOfRangeException("charCount", + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1711,7 +1711,7 @@ namespace System.Text byteCount <<= 1; if (byteCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("charCount", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(charCount), Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow")); return (int)byteCount; } @@ -1720,7 +1720,7 @@ namespace System.Text public override int GetMaxCharCount(int byteCount) { if (byteCount < 0) - throw new ArgumentOutOfRangeException("byteCount", + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); @@ -1735,7 +1735,7 @@ namespace System.Text charCount *= DecoderFallback.MaxCharCount; if (charCount > 0x7fffffff) - throw new ArgumentOutOfRangeException("byteCount", Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); + throw new ArgumentOutOfRangeException(nameof(byteCount), Environment.GetResourceString("ArgumentOutOfRange_GetCharCountOverflow")); return (int)charCount; } @@ -1781,7 +1781,7 @@ namespace System.Text internal Decoder(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Get Common Info @@ -1807,7 +1807,7 @@ namespace System.Text void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { // Any info? - if (info==null) throw new ArgumentNullException("info"); + if (info==null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); // Save Whidbey data diff --git a/src/mscorlib/src/System/Threading/CancellationToken.cs b/src/mscorlib/src/System/Threading/CancellationToken.cs index 48a2344c31..7f744f8fcf 100644 --- a/src/mscorlib/src/System/Threading/CancellationToken.cs +++ b/src/mscorlib/src/System/Threading/CancellationToken.cs @@ -192,7 +192,7 @@ namespace System.Threading public CancellationTokenRegistration Register(Action callback) { if (callback == null) - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); return Register( s_ActionToActionObjShunt, @@ -227,7 +227,7 @@ namespace System.Threading public CancellationTokenRegistration Register(Action callback, bool useSynchronizationContext) { if (callback == null) - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); return Register( s_ActionToActionObjShunt, @@ -260,7 +260,7 @@ namespace System.Threading public CancellationTokenRegistration Register(Action<Object> callback, Object state) { if (callback == null) - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); return Register( callback, @@ -325,7 +325,7 @@ namespace System.Threading StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; if (callback == null) - throw new ArgumentNullException("callback"); + throw new ArgumentNullException(nameof(callback)); if (CanBeCanceled == false) { diff --git a/src/mscorlib/src/System/Threading/CancellationTokenSource.cs b/src/mscorlib/src/System/Threading/CancellationTokenSource.cs index 954cd38344..961c808cde 100644 --- a/src/mscorlib/src/System/Threading/CancellationTokenSource.cs +++ b/src/mscorlib/src/System/Threading/CancellationTokenSource.cs @@ -275,7 +275,7 @@ namespace System.Threading long totalMilliseconds = (long)delay.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("delay"); + throw new ArgumentOutOfRangeException(nameof(delay)); } InitializeWithTimer((int)totalMilliseconds); @@ -304,7 +304,7 @@ namespace System.Threading { if (millisecondsDelay < -1) { - throw new ArgumentOutOfRangeException("millisecondsDelay"); + throw new ArgumentOutOfRangeException(nameof(millisecondsDelay)); } InitializeWithTimer(millisecondsDelay); @@ -414,7 +414,7 @@ namespace System.Threading long totalMilliseconds = (long)delay.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { - throw new ArgumentOutOfRangeException("delay"); + throw new ArgumentOutOfRangeException(nameof(delay)); } CancelAfter((int)totalMilliseconds); @@ -450,7 +450,7 @@ namespace System.Threading if (millisecondsDelay < -1) { - throw new ArgumentOutOfRangeException("millisecondsDelay"); + throw new ArgumentOutOfRangeException(nameof(millisecondsDelay)); } if (IsCancellationRequested) return; @@ -882,7 +882,7 @@ namespace System.Threading public static CancellationTokenSource CreateLinkedTokenSource(params CancellationToken[] tokens) { if (tokens == null) - throw new ArgumentNullException("tokens"); + throw new ArgumentNullException(nameof(tokens)); if (tokens.Length == 0) throw new ArgumentException(Environment.GetResourceString("CancellationToken_CreateLinkedToken_TokensIsEmpty")); diff --git a/src/mscorlib/src/System/Threading/CountdownEvent.cs b/src/mscorlib/src/System/Threading/CountdownEvent.cs index 1374766863..2e622161dc 100644 --- a/src/mscorlib/src/System/Threading/CountdownEvent.cs +++ b/src/mscorlib/src/System/Threading/CountdownEvent.cs @@ -59,7 +59,7 @@ namespace System.Threading { if (initialCount < 0) { - throw new ArgumentOutOfRangeException("initialCount"); + throw new ArgumentOutOfRangeException(nameof(initialCount)); } m_initialCount = initialCount; @@ -229,7 +229,7 @@ namespace System.Threading { if (signalCount <= 0) { - throw new ArgumentOutOfRangeException("signalCount"); + throw new ArgumentOutOfRangeException(nameof(signalCount)); } ThrowIfDisposed(); @@ -340,7 +340,7 @@ namespace System.Threading { if (signalCount <= 0) { - throw new ArgumentOutOfRangeException("signalCount"); + throw new ArgumentOutOfRangeException(nameof(signalCount)); } ThrowIfDisposed(); @@ -409,7 +409,7 @@ namespace System.Threading if (count < 0) { - throw new ArgumentOutOfRangeException("count"); + throw new ArgumentOutOfRangeException(nameof(count)); } m_currentCount = count; @@ -481,7 +481,7 @@ namespace System.Threading long totalMilliseconds = (long)timeout.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + throw new ArgumentOutOfRangeException(nameof(timeout)); } return Wait((int)totalMilliseconds, new CancellationToken()); @@ -511,7 +511,7 @@ namespace System.Threading long totalMilliseconds = (long)timeout.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + throw new ArgumentOutOfRangeException(nameof(timeout)); } return Wait((int)totalMilliseconds, cancellationToken); @@ -555,7 +555,7 @@ namespace System.Threading { if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout"); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout)); } ThrowIfDisposed(); diff --git a/src/mscorlib/src/System/Threading/EventWaitHandle.cs b/src/mscorlib/src/System/Threading/EventWaitHandle.cs index f56da1fa26..6c14489fc3 100644 --- a/src/mscorlib/src/System/Threading/EventWaitHandle.cs +++ b/src/mscorlib/src/System/Threading/EventWaitHandle.cs @@ -56,7 +56,7 @@ namespace System.Threading #else if (System.IO.Path.MaxPath < name.Length) { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); } #endif } @@ -105,7 +105,7 @@ namespace System.Threading #else if (System.IO.Path.MaxPath < name.Length) { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); } #endif } @@ -216,17 +216,17 @@ namespace System.Threading #else if (name == null) { - throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName")); + throw new ArgumentNullException(nameof(name), Environment.GetResourceString("ArgumentNull_WithParamName")); } if(name.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); } if(null != name && System.IO.Path.MaxPath < name.Length) { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); } Contract.EndContractBlock(); @@ -286,7 +286,7 @@ namespace System.Threading public void SetAccessControl(EventWaitHandleSecurity eventSecurity) { if (eventSecurity == null) - throw new ArgumentNullException("eventSecurity"); + throw new ArgumentNullException(nameof(eventSecurity)); Contract.EndContractBlock(); eventSecurity.Persist(safeWaitHandle); diff --git a/src/mscorlib/src/System/Threading/ExecutionContext.cs b/src/mscorlib/src/System/Threading/ExecutionContext.cs index 0440368608..087ee28223 100644 --- a/src/mscorlib/src/System/Threading/ExecutionContext.cs +++ b/src/mscorlib/src/System/Threading/ExecutionContext.cs @@ -1342,7 +1342,7 @@ namespace System.Threading public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); #if FEATURE_REMOTING diff --git a/src/mscorlib/src/System/Threading/ManualResetEventSlim.cs b/src/mscorlib/src/System/Threading/ManualResetEventSlim.cs index b6114ef917..a95e3680d9 100644 --- a/src/mscorlib/src/System/Threading/ManualResetEventSlim.cs +++ b/src/mscorlib/src/System/Threading/ManualResetEventSlim.cs @@ -218,13 +218,13 @@ namespace System.Threading { if (spinCount < 0) { - throw new ArgumentOutOfRangeException("spinCount"); + throw new ArgumentOutOfRangeException(nameof(spinCount)); } if (spinCount > SpinCountState_MaxValue) { throw new ArgumentOutOfRangeException( - "spinCount", + nameof(spinCount), String.Format(Environment.GetResourceString("ManualResetEventSlim_ctor_SpinCountOutOfRange"), SpinCountState_MaxValue)); } @@ -464,7 +464,7 @@ namespace System.Threading long totalMilliseconds = (long)timeout.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + throw new ArgumentOutOfRangeException(nameof(timeout)); } return Wait((int)totalMilliseconds, new CancellationToken()); @@ -495,7 +495,7 @@ namespace System.Threading long totalMilliseconds = (long)timeout.TotalMilliseconds; if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue) { - throw new ArgumentOutOfRangeException("timeout"); + throw new ArgumentOutOfRangeException(nameof(timeout)); } return Wait((int)totalMilliseconds, cancellationToken); @@ -544,7 +544,7 @@ namespace System.Threading if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout"); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout)); } if (!IsSet) diff --git a/src/mscorlib/src/System/Threading/Monitor.cs b/src/mscorlib/src/System/Threading/Monitor.cs index 415948b425..92176fac35 100644 --- a/src/mscorlib/src/System/Threading/Monitor.cs +++ b/src/mscorlib/src/System/Threading/Monitor.cs @@ -127,7 +127,7 @@ namespace System.Threading { { long tm = (long)timeout.TotalMilliseconds; if (tm < -1 || tm > (long)Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); return (int)tm; } @@ -162,7 +162,7 @@ namespace System.Threading { public static bool IsEntered(object obj) { if (obj == null) - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); return IsEnteredNative(obj); } @@ -190,7 +190,7 @@ namespace System.Threading { public static bool Wait(Object obj, int millisecondsTimeout, bool exitContext) { if (obj == null) - throw (new ArgumentNullException("obj")); + throw (new ArgumentNullException(nameof(obj))); return ObjWait(exitContext, millisecondsTimeout, obj); } @@ -228,7 +228,7 @@ namespace System.Threading { { if (obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); @@ -246,7 +246,7 @@ namespace System.Threading { { if (obj == null) { - throw new ArgumentNullException("obj"); + throw new ArgumentNullException(nameof(obj)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Threading/Mutex.cs b/src/mscorlib/src/System/Threading/Mutex.cs index 2e9b68176d..434ab37b6d 100644 --- a/src/mscorlib/src/System/Threading/Mutex.cs +++ b/src/mscorlib/src/System/Threading/Mutex.cs @@ -60,7 +60,7 @@ namespace System.Threading #if !PLATFORM_UNIX if (name != null && System.IO.Path.MaxPath < name.Length) { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); } #endif Contract.EndContractBlock(); @@ -94,7 +94,7 @@ namespace System.Threading #if !PLATFORM_UNIX if (name != null && System.IO.Path.MaxPath < name.Length) { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); } #endif Contract.EndContractBlock(); @@ -321,17 +321,17 @@ namespace System.Threading { if (name == null) { - throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName")); + throw new ArgumentNullException(nameof(name), Environment.GetResourceString("ArgumentNull_WithParamName")); } if(name.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); } #if !PLATFORM_UNIX if(System.IO.Path.MaxPath < name.Length) { - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); } #endif Contract.EndContractBlock(); @@ -357,7 +357,7 @@ namespace System.Threading if (name != null && errorCode == Win32Native.ERROR_FILENAME_EXCED_RANGE) { // On Unix, length validation is done by CoreCLR's PAL after converting to utf-8 - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPathComponentLength), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPathComponentLength), nameof(name)); } #endif @@ -477,7 +477,7 @@ namespace System.Threading public void SetAccessControl(MutexSecurity mutexSecurity) { if (mutexSecurity == null) - throw new ArgumentNullException("mutexSecurity"); + throw new ArgumentNullException(nameof(mutexSecurity)); Contract.EndContractBlock(); mutexSecurity.Persist(safeWaitHandle); diff --git a/src/mscorlib/src/System/Threading/Overlapped.cs b/src/mscorlib/src/System/Threading/Overlapped.cs index 3f9fbc4989..7b27464258 100644 --- a/src/mscorlib/src/System/Threading/Overlapped.cs +++ b/src/mscorlib/src/System/Threading/Overlapped.cs @@ -392,7 +392,7 @@ namespace System.Threading unsafe public static Overlapped Unpack(NativeOverlapped* nativeOverlappedPtr) { if (nativeOverlappedPtr == null) - throw new ArgumentNullException("nativeOverlappedPtr"); + throw new ArgumentNullException(nameof(nativeOverlappedPtr)); Contract.EndContractBlock(); Overlapped overlapped = OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr).m_overlapped; @@ -405,7 +405,7 @@ namespace System.Threading unsafe public static void Free(NativeOverlapped* nativeOverlappedPtr) { if (nativeOverlappedPtr == null) - throw new ArgumentNullException("nativeOverlappedPtr"); + throw new ArgumentNullException(nameof(nativeOverlappedPtr)); Contract.EndContractBlock(); Overlapped overlapped = OverlappedData.GetOverlappedFromNative(nativeOverlappedPtr).m_overlapped; diff --git a/src/mscorlib/src/System/Threading/ReaderWriterLock.cs b/src/mscorlib/src/System/Threading/ReaderWriterLock.cs index 8cead1a87a..dc1b2fb3a7 100644 --- a/src/mscorlib/src/System/Threading/ReaderWriterLock.cs +++ b/src/mscorlib/src/System/Threading/ReaderWriterLock.cs @@ -103,7 +103,7 @@ namespace System.Threading { { long tm = (long)timeout.TotalMilliseconds; if (tm < -1 || tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); AcquireReaderLockInternal((int)tm); } @@ -128,7 +128,7 @@ namespace System.Threading { { long tm = (long)timeout.TotalMilliseconds; if (tm < -1 || tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); AcquireWriterLockInternal((int)tm); } @@ -184,7 +184,7 @@ namespace System.Threading { { long tm = (long)timeout.TotalMilliseconds; if (tm < -1 || tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); return UpgradeToWriterLock((int)tm); } diff --git a/src/mscorlib/src/System/Threading/Semaphore.cs b/src/mscorlib/src/System/Threading/Semaphore.cs index 303593b776..b0ad4f68f6 100644 --- a/src/mscorlib/src/System/Threading/Semaphore.cs +++ b/src/mscorlib/src/System/Threading/Semaphore.cs @@ -21,12 +21,12 @@ namespace System.Threading { if (initialCount < 0) { - throw new ArgumentOutOfRangeException("initialCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(initialCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (maximumCount < 1) { - throw new ArgumentOutOfRangeException("maximumCount", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); + throw new ArgumentOutOfRangeException(nameof(maximumCount), Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum")); } if (initialCount > maximumCount) @@ -54,12 +54,12 @@ namespace System.Threading { if (initialCount < 0) { - throw new ArgumentOutOfRangeException("initialCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(initialCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (maximumCount < 1) { - throw new ArgumentOutOfRangeException("maximumCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(maximumCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (initialCount > maximumCount) @@ -96,7 +96,7 @@ namespace System.Threading throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_NamedSynchronizationPrimitives")); #else if (name.Length > Path.MaxPath) - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); #endif } @@ -138,11 +138,11 @@ namespace System.Threading throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_NamedSynchronizationPrimitives")); #else if (name == null) - throw new ArgumentNullException("name", Environment.GetResourceString("ArgumentNull_WithParamName")); + throw new ArgumentNullException(nameof(name), Environment.GetResourceString("ArgumentNull_WithParamName")); if (name.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name)); if (name.Length > Path.MaxPath) - throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), "name"); + throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong", Path.MaxPath), nameof(name)); const int SYNCHRONIZE = 0x00100000; const int SEMAPHORE_MODIFY_STATE = 0x00000002; @@ -182,7 +182,7 @@ namespace System.Threading { if (releaseCount < 1) { - throw new ArgumentOutOfRangeException("releaseCount", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(releaseCount), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } //If ReleaseSempahore returns false when the specified value would cause diff --git a/src/mscorlib/src/System/Threading/SemaphoreSlim.cs b/src/mscorlib/src/System/Threading/SemaphoreSlim.cs index 4f34b28ebd..d2cce0335a 100644 --- a/src/mscorlib/src/System/Threading/SemaphoreSlim.cs +++ b/src/mscorlib/src/System/Threading/SemaphoreSlim.cs @@ -182,13 +182,13 @@ namespace System.Threading if (initialCount < 0 || initialCount > maxCount) { throw new ArgumentOutOfRangeException( - "initialCount", initialCount, GetResourceString("SemaphoreSlim_ctor_InitialCountWrong")); + nameof(initialCount), initialCount, GetResourceString("SemaphoreSlim_ctor_InitialCountWrong")); } //validate input if (maxCount <= 0) { - throw new ArgumentOutOfRangeException("maxCount", maxCount, GetResourceString("SemaphoreSlim_ctor_MaxCountWrong")); + throw new ArgumentOutOfRangeException(nameof(maxCount), maxCount, GetResourceString("SemaphoreSlim_ctor_MaxCountWrong")); } m_maxCount = maxCount; @@ -245,7 +245,7 @@ namespace System.Threading if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { throw new System.ArgumentOutOfRangeException( - "timeout", timeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); + nameof(timeout), timeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); } // Call wait with the timeout milliseconds @@ -275,7 +275,7 @@ namespace System.Threading if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { throw new System.ArgumentOutOfRangeException( - "timeout", timeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); + nameof(timeout), timeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); } // Call wait with the timeout milliseconds @@ -318,7 +318,7 @@ namespace System.Threading if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException( - "totalMilliSeconds", millisecondsTimeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); + nameof(millisecondsTimeout), millisecondsTimeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); } cancellationToken.ThrowIfCancellationRequested(); @@ -579,7 +579,7 @@ namespace System.Threading if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { throw new System.ArgumentOutOfRangeException( - "timeout", timeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); + nameof(timeout), timeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); } // Call wait with the timeout milliseconds @@ -612,7 +612,7 @@ namespace System.Threading if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException( - "totalMilliSeconds", millisecondsTimeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); + nameof(millisecondsTimeout), millisecondsTimeout, GetResourceString("SemaphoreSlim_Wait_TimeoutWrong")); } // Bail early for cancellation @@ -776,7 +776,7 @@ namespace System.Threading if (releaseCount < 1) { throw new ArgumentOutOfRangeException( - "releaseCount", releaseCount, GetResourceString("SemaphoreSlim_Release_CountWrong")); + nameof(releaseCount), releaseCount, GetResourceString("SemaphoreSlim_Release_CountWrong")); } int returnCount; diff --git a/src/mscorlib/src/System/Threading/SpinLock.cs b/src/mscorlib/src/System/Threading/SpinLock.cs index 9f5cf686dd..56ff37a826 100644 --- a/src/mscorlib/src/System/Threading/SpinLock.cs +++ b/src/mscorlib/src/System/Threading/SpinLock.cs @@ -225,7 +225,7 @@ namespace System.Threading if (totalMilliseconds < -1 || totalMilliseconds > int.MaxValue) { throw new System.ArgumentOutOfRangeException( - "timeout", timeout, Environment.GetResourceString("SpinLock_TryEnter_ArgumentOutOfRange")); + nameof(timeout), timeout, Environment.GetResourceString("SpinLock_TryEnter_ArgumentOutOfRange")); } // Call reliable enter with the int-based timeout milliseconds @@ -291,7 +291,7 @@ namespace System.Threading if (millisecondsTimeout < -1) { throw new ArgumentOutOfRangeException( - "millisecondsTimeout", millisecondsTimeout, Environment.GetResourceString("SpinLock_TryEnter_ArgumentOutOfRange")); + nameof(millisecondsTimeout), millisecondsTimeout, Environment.GetResourceString("SpinLock_TryEnter_ArgumentOutOfRange")); } diff --git a/src/mscorlib/src/System/Threading/SpinWait.cs b/src/mscorlib/src/System/Threading/SpinWait.cs index c2cd0b6203..1888b606b4 100644 --- a/src/mscorlib/src/System/Threading/SpinWait.cs +++ b/src/mscorlib/src/System/Threading/SpinWait.cs @@ -220,7 +220,7 @@ namespace System.Threading if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue) { throw new System.ArgumentOutOfRangeException( - "timeout", timeout, Environment.GetResourceString("SpinWait_SpinUntil_TimeoutWrong")); + nameof(timeout), timeout, Environment.GetResourceString("SpinWait_SpinUntil_TimeoutWrong")); } // Call wait with the timeout milliseconds @@ -242,11 +242,11 @@ namespace System.Threading if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException( - "millisecondsTimeout", millisecondsTimeout, Environment.GetResourceString("SpinWait_SpinUntil_TimeoutWrong")); + nameof(millisecondsTimeout), millisecondsTimeout, Environment.GetResourceString("SpinWait_SpinUntil_TimeoutWrong")); } if (condition == null) { - throw new ArgumentNullException("condition", Environment.GetResourceString("SpinWait_SpinUntil_ArgumentNull")); + throw new ArgumentNullException(nameof(condition), Environment.GetResourceString("SpinWait_SpinUntil_ArgumentNull")); } uint startTime = 0; if (millisecondsTimeout != 0 && millisecondsTimeout != Timeout.Infinite) diff --git a/src/mscorlib/src/System/Threading/SynchronizationContext.cs b/src/mscorlib/src/System/Threading/SynchronizationContext.cs index a3f28d1d73..2f2dc36087 100644 --- a/src/mscorlib/src/System/Threading/SynchronizationContext.cs +++ b/src/mscorlib/src/System/Threading/SynchronizationContext.cs @@ -151,7 +151,7 @@ namespace System.Threading { if (waitHandles == null) { - throw new ArgumentNullException("waitHandles"); + throw new ArgumentNullException(nameof(waitHandles)); } Contract.EndContractBlock(); return WaitHelper(waitHandles, waitAll, millisecondsTimeout); diff --git a/src/mscorlib/src/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs b/src/mscorlib/src/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs index cb4a22bb2b..dcf73fab68 100644 --- a/src/mscorlib/src/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs +++ b/src/mscorlib/src/System/Threading/Tasks/ConcurrentExclusiveSchedulerPair.cs @@ -101,9 +101,9 @@ namespace System.Threading.Tasks public ConcurrentExclusiveSchedulerPair(TaskScheduler taskScheduler, int maxConcurrencyLevel, int maxItemsPerTask) { // Validate arguments - if (taskScheduler == null) throw new ArgumentNullException("taskScheduler"); - if (maxConcurrencyLevel == 0 || maxConcurrencyLevel < -1) throw new ArgumentOutOfRangeException("maxConcurrencyLevel"); - if (maxItemsPerTask == 0 || maxItemsPerTask < -1) throw new ArgumentOutOfRangeException("maxItemsPerTask"); + if (taskScheduler == null) throw new ArgumentNullException(nameof(taskScheduler)); + if (maxConcurrencyLevel == 0 || maxConcurrencyLevel < -1) throw new ArgumentOutOfRangeException(nameof(maxConcurrencyLevel)); + if (maxItemsPerTask == 0 || maxItemsPerTask < -1) throw new ArgumentOutOfRangeException(nameof(maxItemsPerTask)); Contract.EndContractBlock(); // Store configuration diff --git a/src/mscorlib/src/System/Threading/Tasks/Parallel.cs b/src/mscorlib/src/System/Threading/Tasks/Parallel.cs index 5ec2ae33c0..914c7bfba3 100644 --- a/src/mscorlib/src/System/Threading/Tasks/Parallel.cs +++ b/src/mscorlib/src/System/Threading/Tasks/Parallel.cs @@ -98,7 +98,7 @@ namespace System.Threading.Tasks set { if ((value == 0) || (value < -1)) - throw new ArgumentOutOfRangeException("MaxDegreeOfParallelism"); + throw new ArgumentOutOfRangeException(nameof(MaxDegreeOfParallelism)); m_maxDegreeOfParallelism = value; } } @@ -208,11 +208,11 @@ namespace System.Threading.Tasks { if (actions == null) { - throw new ArgumentNullException("actions"); + throw new ArgumentNullException(nameof(actions)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } // Throw an ODE if we're passed a disposed CancellationToken. @@ -423,7 +423,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker<object>( @@ -452,7 +452,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker64<object>( @@ -491,11 +491,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker<object>( @@ -534,11 +534,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker64<object>( @@ -590,7 +590,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker<object>( @@ -620,7 +620,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker64<object>( @@ -661,11 +661,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker<object>( @@ -707,11 +707,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker64<object>( @@ -765,15 +765,15 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForWorker( @@ -827,15 +827,15 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForWorker64( @@ -900,19 +900,19 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker( @@ -977,19 +977,19 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } @@ -1656,11 +1656,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForEachWorker<TSource, object>( @@ -1701,15 +1701,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, object>( @@ -1741,11 +1741,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForEachWorker<TSource, object>( @@ -1788,15 +1788,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, object>( @@ -1828,11 +1828,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForEachWorker<TSource, object>( @@ -1875,15 +1875,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, object>( @@ -1936,19 +1936,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForEachWorker<TSource, TLocal>( @@ -2013,23 +2013,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, TLocal>( @@ -2082,19 +2082,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForEachWorker<TSource, TLocal>( @@ -2158,23 +2158,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, TLocal>( @@ -2416,11 +2416,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return PartitionerForEachWorker<TSource, object>(source, s_defaultParallelOptions, body, null, null, null, null, null, null); @@ -2475,11 +2475,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return PartitionerForEachWorker<TSource, object>(source, s_defaultParallelOptions, null, body, null, null, null, null, null); @@ -2537,11 +2537,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (!source.KeysNormalized) @@ -2621,19 +2621,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return PartitionerForEachWorker<TSource, TLocal>(source, s_defaultParallelOptions, null, null, null, body, null, localInit, localFinally); @@ -2711,19 +2711,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (!source.KeysNormalized) @@ -2793,15 +2793,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return PartitionerForEachWorker<TSource, object>(source, parallelOptions, body, null, null, null, null, null, null); @@ -2868,15 +2868,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return PartitionerForEachWorker<TSource, object>(source, parallelOptions, null, body, null, null, null, null, null); @@ -2946,15 +2946,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } if (!source.KeysNormalized) @@ -3046,23 +3046,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return PartitionerForEachWorker<TSource, TLocal>(source, parallelOptions, null, null, null, body, null, localInit, localFinally); @@ -3152,23 +3152,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } if (!source.KeysNormalized) diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskExceptionHolder.cs b/src/mscorlib/src/System/Threading/Tasks/TaskExceptionHolder.cs index 198db8e15c..30fa54ccbc 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskExceptionHolder.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskExceptionHolder.cs @@ -297,7 +297,7 @@ namespace System.Threading.Tasks // Anything else is a programming error else { - throw new ArgumentException(Environment.GetResourceString("TaskExceptionHolder_UnknownExceptionType"), "exceptionObject"); + throw new ArgumentException(Environment.GetResourceString("TaskExceptionHolder_UnknownExceptionType"), nameof(exceptionObject)); } } } diff --git a/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs b/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs index 52b471628a..699ab5aa83 100644 --- a/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs +++ b/src/mscorlib/src/System/Threading/Tasks/TaskFactory.cs @@ -225,7 +225,7 @@ namespace System.Threading.Tasks TaskCreationOptions.PreferFairness | TaskCreationOptions.RunContinuationsAsynchronously)) != 0) { - throw new ArgumentOutOfRangeException("creationOptions"); + throw new ArgumentOutOfRangeException(nameof(creationOptions)); } Contract.EndContractBlock(); } @@ -1593,9 +1593,9 @@ namespace System.Threading.Tasks { // Options detected here cause exceptions in FromAsync methods that take beginMethod as a parameter if ((creationOptions & TaskCreationOptions.LongRunning) != 0) - throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("Task_FromAsync_LongRunning")); + throw new ArgumentOutOfRangeException(nameof(creationOptions), Environment.GetResourceString("Task_FromAsync_LongRunning")); if ((creationOptions & TaskCreationOptions.PreferFairness) != 0) - throw new ArgumentOutOfRangeException("creationOptions", Environment.GetResourceString("Task_FromAsync_PreferFairness")); + throw new ArgumentOutOfRangeException(nameof(creationOptions), Environment.GetResourceString("Task_FromAsync_PreferFairness")); } // Check for general validity of options @@ -1606,7 +1606,7 @@ namespace System.Threading.Tasks TaskCreationOptions.PreferFairness | TaskCreationOptions.LongRunning)) != 0) { - throw new ArgumentOutOfRangeException("creationOptions"); + throw new ArgumentOutOfRangeException(nameof(creationOptions)); } } @@ -1801,7 +1801,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1833,7 +1833,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1870,7 +1870,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction, TaskContinuationOptions continuationOptions) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1918,7 +1918,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAll(Task[] tasks, Action<Task[]> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1945,7 +1945,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -1979,7 +1979,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction, CancellationToken cancellationToken) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2018,7 +2018,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction, TaskContinuationOptions continuationOptions) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2067,7 +2067,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAll<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>[]> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2097,7 +2097,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2133,7 +2133,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2174,7 +2174,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2226,7 +2226,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAll<TResult>(Task[] tasks, Func<Task[], TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2258,7 +2258,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2295,7 +2295,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2338,7 +2338,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2391,7 +2391,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAll<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>[], TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2489,7 +2489,7 @@ namespace System.Threading.Tasks for(int i=0; i<numTasks; i++) { var task = tasks[i]; - if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + if (task == null) throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), nameof(tasks)); if (checkArgsOnly) continue; @@ -2531,7 +2531,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2562,7 +2562,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2599,7 +2599,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction, TaskContinuationOptions continuationOptions) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2647,7 +2647,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAny(Task[] tasks, Action<Task> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2678,7 +2678,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2713,7 +2713,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2754,7 +2754,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2806,7 +2806,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAny<TResult>(Task[] tasks, Func<Task, TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2838,7 +2838,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); return TaskFactory<TResult>.ContinueWhenAnyImpl<TAntecedentResult>(tasks, continuationFunction, null, m_defaultContinuationOptions, m_defaultCancellationToken, DefaultScheduler, ref stackMark); } @@ -2872,7 +2872,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction, CancellationToken cancellationToken) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2915,7 +2915,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction, TaskContinuationOptions continuationOptions) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2968,7 +2968,7 @@ namespace System.Threading.Tasks public Task<TResult> ContinueWhenAny<TAntecedentResult, TResult>(Task<TAntecedentResult>[] tasks, Func<Task<TAntecedentResult>, TResult> continuationFunction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationFunction == null) throw new ArgumentNullException("continuationFunction"); + if (continuationFunction == null) throw new ArgumentNullException(nameof(continuationFunction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -2996,7 +2996,7 @@ namespace System.Threading.Tasks [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -3029,7 +3029,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction, CancellationToken cancellationToken) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -3068,7 +3068,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction, TaskContinuationOptions continuationOptions) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -3117,7 +3117,7 @@ namespace System.Threading.Tasks public Task ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[] tasks, Action<Task<TAntecedentResult>> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler) { - if (continuationAction == null) throw new ArgumentNullException("continuationAction"); + if (continuationAction == null) throw new ArgumentNullException(nameof(continuationAction)); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -3129,9 +3129,9 @@ namespace System.Threading.Tasks internal static Task[] CheckMultiContinuationTasksAndCopy(Task[] tasks) { if (tasks == null) - throw new ArgumentNullException("tasks"); + throw new ArgumentNullException(nameof(tasks)); if (tasks.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks"); + throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), nameof(tasks)); Contract.EndContractBlock(); Task[] tasksCopy = new Task[tasks.Length]; @@ -3140,7 +3140,7 @@ namespace System.Threading.Tasks tasksCopy[i] = tasks[i]; if (tasksCopy[i] == null) - throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), nameof(tasks)); } return tasksCopy; @@ -3149,9 +3149,9 @@ namespace System.Threading.Tasks internal static Task<TResult>[] CheckMultiContinuationTasksAndCopy<TResult>(Task<TResult>[] tasks) { if (tasks == null) - throw new ArgumentNullException("tasks"); + throw new ArgumentNullException(nameof(tasks)); if (tasks.Length == 0) - throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), "tasks"); + throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_EmptyTaskList"), nameof(tasks)); Contract.EndContractBlock(); Task<TResult>[] tasksCopy = new Task<TResult>[tasks.Length]; @@ -3160,7 +3160,7 @@ namespace System.Threading.Tasks tasksCopy[i] = tasks[i]; if (tasksCopy[i] == null) - throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), "tasks"); + throw new ArgumentException(Environment.GetResourceString("Task_MultiTaskContinuation_NullTask"), nameof(tasks)); } return tasksCopy; @@ -3179,7 +3179,7 @@ namespace System.Threading.Tasks const TaskContinuationOptions illegalMask = TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.LongRunning; if ((continuationOptions & illegalMask) == illegalMask) { - throw new ArgumentOutOfRangeException("continuationOptions", Environment.GetResourceString("Task_ContinueWith_ESandLR")); + throw new ArgumentOutOfRangeException(nameof(continuationOptions), Environment.GetResourceString("Task_ContinueWith_ESandLR")); } // Check that no nonsensical options are specified. @@ -3193,12 +3193,12 @@ namespace System.Threading.Tasks NotOnAny | TaskContinuationOptions.ExecuteSynchronously)) != 0) { - throw new ArgumentOutOfRangeException("continuationOptions"); + throw new ArgumentOutOfRangeException(nameof(continuationOptions)); } // Check that no "fire" options are specified. if ((continuationOptions & NotOnAny) != 0) - throw new ArgumentOutOfRangeException("continuationOptions", Environment.GetResourceString("Task_MultiTaskContinuation_FireOptions")); + throw new ArgumentOutOfRangeException(nameof(continuationOptions), Environment.GetResourceString("Task_MultiTaskContinuation_FireOptions")); Contract.EndContractBlock(); } } diff --git a/src/mscorlib/src/System/Threading/Thread.cs b/src/mscorlib/src/System/Threading/Thread.cs index c5b38ca9e1..2788a7b327 100644 --- a/src/mscorlib/src/System/Threading/Thread.cs +++ b/src/mscorlib/src/System/Threading/Thread.cs @@ -229,7 +229,7 @@ namespace System.Threading { [System.Security.SecuritySafeCritical] // auto-generated public Thread(ThreadStart start) { if (start == null) { - throw new ArgumentNullException("start"); + throw new ArgumentNullException(nameof(start)); } Contract.EndContractBlock(); SetStartHelper((Delegate)start,0); //0 will setup Thread with default stackSize @@ -238,17 +238,17 @@ namespace System.Threading { [System.Security.SecuritySafeCritical] // auto-generated public Thread(ThreadStart start, int maxStackSize) { if (start == null) { - throw new ArgumentNullException("start"); + throw new ArgumentNullException(nameof(start)); } if (0 > maxStackSize) - throw new ArgumentOutOfRangeException("maxStackSize",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(maxStackSize),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); SetStartHelper((Delegate)start, maxStackSize); } [System.Security.SecuritySafeCritical] // auto-generated public Thread(ParameterizedThreadStart start) { if (start == null) { - throw new ArgumentNullException("start"); + throw new ArgumentNullException(nameof(start)); } Contract.EndContractBlock(); SetStartHelper((Delegate)start, 0); @@ -257,10 +257,10 @@ namespace System.Threading { [System.Security.SecuritySafeCritical] // auto-generated public Thread(ParameterizedThreadStart start, int maxStackSize) { if (start == null) { - throw new ArgumentNullException("start"); + throw new ArgumentNullException(nameof(start)); } if (0 > maxStackSize) - throw new ArgumentOutOfRangeException("maxStackSize",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + throw new ArgumentOutOfRangeException(nameof(maxStackSize),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); Contract.EndContractBlock(); SetStartHelper((Delegate)start, maxStackSize); } @@ -673,7 +673,7 @@ namespace System.Threading { { long tm = (long)timeout.TotalMilliseconds; if (tm < -1 || tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); return Join((int)tm); } @@ -703,7 +703,7 @@ namespace System.Threading { { long tm = (long)timeout.TotalMilliseconds; if (tm < -1 || tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Sleep((int)tm); } @@ -1046,7 +1046,7 @@ namespace System.Threading { [HostProtection(ExternalThreading=true)] set { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); @@ -1157,7 +1157,7 @@ namespace System.Threading { #endif set { if (null==value) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/Threading/ThreadLocal.cs b/src/mscorlib/src/System/Threading/ThreadLocal.cs index b4cf12ab7c..1af377f777 100644 --- a/src/mscorlib/src/System/Threading/ThreadLocal.cs +++ b/src/mscorlib/src/System/Threading/ThreadLocal.cs @@ -107,7 +107,7 @@ namespace System.Threading public ThreadLocal(Func<T> valueFactory) { if (valueFactory == null) - throw new ArgumentNullException("valueFactory"); + throw new ArgumentNullException(nameof(valueFactory)); Initialize(valueFactory, false); } @@ -127,7 +127,7 @@ namespace System.Threading public ThreadLocal(Func<T> valueFactory, bool trackAllValues) { if (valueFactory == null) - throw new ArgumentNullException("valueFactory"); + throw new ArgumentNullException(nameof(valueFactory)); Initialize(valueFactory, trackAllValues); } diff --git a/src/mscorlib/src/System/Threading/ThreadPool.cs b/src/mscorlib/src/System/Threading/ThreadPool.cs index 8262757c59..c11e149f47 100644 --- a/src/mscorlib/src/System/Threading/ThreadPool.cs +++ b/src/mscorlib/src/System/Threading/ThreadPool.cs @@ -1505,7 +1505,7 @@ namespace System.Threading } else { - throw new ArgumentNullException("WaitOrTimerCallback"); + throw new ArgumentNullException(nameof(WaitOrTimerCallback)); } return registeredWaitHandle; } @@ -1522,7 +1522,7 @@ namespace System.Threading ) { if (millisecondsTimeOutInterval < -1) - throw new ArgumentOutOfRangeException("millisecondsTimeOutInterval", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)millisecondsTimeOutInterval,executeOnlyOnce,ref stackMark,true); @@ -1539,7 +1539,7 @@ namespace System.Threading ) { if (millisecondsTimeOutInterval < -1) - throw new ArgumentOutOfRangeException("millisecondsTimeOutInterval", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)millisecondsTimeOutInterval,executeOnlyOnce,ref stackMark,false); @@ -1556,7 +1556,7 @@ namespace System.Threading ) { if (millisecondsTimeOutInterval < -1) - throw new ArgumentOutOfRangeException("millisecondsTimeOutInterval", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)millisecondsTimeOutInterval,executeOnlyOnce,ref stackMark,true); @@ -1573,7 +1573,7 @@ namespace System.Threading ) { if (millisecondsTimeOutInterval < -1) - throw new ArgumentOutOfRangeException("millisecondsTimeOutInterval", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeOutInterval), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)millisecondsTimeOutInterval,executeOnlyOnce,ref stackMark,false); @@ -1591,9 +1591,9 @@ namespace System.Threading { long tm = (long)timeout.TotalMilliseconds; if (tm < -1) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_LessEqualToIntegerMaxVal")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_LessEqualToIntegerMaxVal")); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)tm,executeOnlyOnce,ref stackMark,true); } @@ -1610,9 +1610,9 @@ namespace System.Threading { long tm = (long)timeout.TotalMilliseconds; if (tm < -1) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (tm > (long) Int32.MaxValue) - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_LessEqualToIntegerMaxVal")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_LessEqualToIntegerMaxVal")); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RegisterWaitForSingleObject(waitObject,callBack,state,(UInt32)tm,executeOnlyOnce,ref stackMark,false); } @@ -1687,7 +1687,7 @@ namespace System.Threading } else { - throw new ArgumentNullException("WaitCallback"); + throw new ArgumentNullException(nameof(WaitCallback)); } return success; } @@ -1928,7 +1928,7 @@ namespace System.Threading public static bool BindHandle(SafeHandle osHandle) { if (osHandle == null) - throw new ArgumentNullException("osHandle"); + throw new ArgumentNullException(nameof(osHandle)); bool ret = false; bool mustReleaseSafeHandle = false; diff --git a/src/mscorlib/src/System/Threading/Timer.cs b/src/mscorlib/src/System/Threading/Timer.cs index 99eae69200..c8a1a3b9f0 100644 --- a/src/mscorlib/src/System/Threading/Timer.cs +++ b/src/mscorlib/src/System/Threading/Timer.cs @@ -788,9 +788,9 @@ namespace System.Threading int period) { if (dueTime < -1) - throw new ArgumentOutOfRangeException("dueTime", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(dueTime), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (period < -1 ) - throw new ArgumentOutOfRangeException("period", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(period), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; @@ -806,15 +806,15 @@ namespace System.Threading { long dueTm = (long)dueTime.TotalMilliseconds; if (dueTm < -1) - throw new ArgumentOutOfRangeException("dueTm",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(dueTm),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (dueTm > MAX_SUPPORTED_TIMEOUT) - throw new ArgumentOutOfRangeException("dueTm",Environment.GetResourceString("ArgumentOutOfRange_TimeoutTooLarge")); + throw new ArgumentOutOfRangeException(nameof(dueTm),Environment.GetResourceString("ArgumentOutOfRange_TimeoutTooLarge")); long periodTm = (long)period.TotalMilliseconds; if (periodTm < -1) - throw new ArgumentOutOfRangeException("periodTm",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(periodTm),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (periodTm > MAX_SUPPORTED_TIMEOUT) - throw new ArgumentOutOfRangeException("periodTm",Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); + throw new ArgumentOutOfRangeException(nameof(periodTm),Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; TimerSetup(callback,state,(UInt32)dueTm,(UInt32)periodTm,ref stackMark); @@ -840,13 +840,13 @@ namespace System.Threading long period) { if (dueTime < -1) - throw new ArgumentOutOfRangeException("dueTime",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(dueTime),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (period < -1) - throw new ArgumentOutOfRangeException("period",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(period),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (dueTime > MAX_SUPPORTED_TIMEOUT) - throw new ArgumentOutOfRangeException("dueTime",Environment.GetResourceString("ArgumentOutOfRange_TimeoutTooLarge")); + throw new ArgumentOutOfRangeException(nameof(dueTime),Environment.GetResourceString("ArgumentOutOfRange_TimeoutTooLarge")); if (period > MAX_SUPPORTED_TIMEOUT) - throw new ArgumentOutOfRangeException("period",Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); + throw new ArgumentOutOfRangeException(nameof(period),Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); Contract.EndContractBlock(); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; TimerSetup(callback,state,(UInt32) dueTime, (UInt32) period,ref stackMark); @@ -873,7 +873,7 @@ namespace System.Threading ref StackCrawlMark stackMark) { if (callback == null) - throw new ArgumentNullException("TimerCallback"); + throw new ArgumentNullException(nameof(TimerCallback)); Contract.EndContractBlock(); m_timer = new TimerHolder(new TimerQueueTimer(callback, state, dueTime, period, ref stackMark)); @@ -894,9 +894,9 @@ namespace System.Threading public bool Change(int dueTime, int period) { if (dueTime < -1 ) - throw new ArgumentOutOfRangeException("dueTime",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(dueTime),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (period < -1) - throw new ArgumentOutOfRangeException("period",Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(period),Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); Contract.EndContractBlock(); return m_timer.m_timer.Change((UInt32)dueTime, (UInt32)period); @@ -916,13 +916,13 @@ namespace System.Threading public bool Change(long dueTime, long period) { if (dueTime < -1 ) - throw new ArgumentOutOfRangeException("dueTime", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(dueTime), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (period < -1) - throw new ArgumentOutOfRangeException("period", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(period), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); if (dueTime > MAX_SUPPORTED_TIMEOUT) - throw new ArgumentOutOfRangeException("dueTime", Environment.GetResourceString("ArgumentOutOfRange_TimeoutTooLarge")); + throw new ArgumentOutOfRangeException(nameof(dueTime), Environment.GetResourceString("ArgumentOutOfRange_TimeoutTooLarge")); if (period > MAX_SUPPORTED_TIMEOUT) - throw new ArgumentOutOfRangeException("period", Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); + throw new ArgumentOutOfRangeException(nameof(period), Environment.GetResourceString("ArgumentOutOfRange_PeriodTooLarge")); Contract.EndContractBlock(); return m_timer.m_timer.Change((UInt32)dueTime, (UInt32)period); @@ -931,7 +931,7 @@ namespace System.Threading public bool Dispose(WaitHandle notifyObject) { if (notifyObject==null) - throw new ArgumentNullException("notifyObject"); + throw new ArgumentNullException(nameof(notifyObject)); Contract.EndContractBlock(); return m_timer.Close(notifyObject); diff --git a/src/mscorlib/src/System/Threading/WaitHandle.cs b/src/mscorlib/src/System/Threading/WaitHandle.cs index b8fbe4813f..15d39a0905 100644 --- a/src/mscorlib/src/System/Threading/WaitHandle.cs +++ b/src/mscorlib/src/System/Threading/WaitHandle.cs @@ -175,7 +175,7 @@ namespace System.Threading { if (millisecondsTimeout < -1) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); return WaitOne((long)millisecondsTimeout,exitContext); @@ -186,7 +186,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return WaitOne(tm,exitContext); } @@ -277,7 +277,7 @@ namespace System.Threading { if (waitHandles == null) { - throw new ArgumentNullException("waitHandles", Environment.GetResourceString("ArgumentNull_Waithandles")); + throw new ArgumentNullException(nameof(waitHandles), Environment.GetResourceString("ArgumentNull_Waithandles")); } if(waitHandles.Length == 0) { @@ -293,7 +293,7 @@ namespace System.Threading #if FEATURE_CORECLR throw new ArgumentException(Environment.GetResourceString("Argument_EmptyWaithandleArray")); #else - throw new ArgumentNullException("waitHandles", Environment.GetResourceString("Argument_EmptyWaithandleArray")); + throw new ArgumentNullException(nameof(waitHandles), Environment.GetResourceString("Argument_EmptyWaithandleArray")); #endif } if (waitHandles.Length > MAX_WAITHANDLES) @@ -302,7 +302,7 @@ namespace System.Threading } if (-1 > millisecondsTimeout) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); WaitHandle[] internalWaitHandles = new WaitHandle[waitHandles.Length]; @@ -350,7 +350,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return WaitAll(waitHandles,(int)tm, exitContext); } @@ -390,7 +390,7 @@ namespace System.Threading { if (waitHandles==null) { - throw new ArgumentNullException("waitHandles", Environment.GetResourceString("ArgumentNull_Waithandles")); + throw new ArgumentNullException(nameof(waitHandles), Environment.GetResourceString("ArgumentNull_Waithandles")); } if(waitHandles.Length == 0) { @@ -402,7 +402,7 @@ namespace System.Threading } if (-1 > millisecondsTimeout) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); WaitHandle[] internalWaitHandles = new WaitHandle[waitHandles.Length]; @@ -455,7 +455,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return WaitAny(waitHandles,(int)tm, exitContext); } @@ -515,7 +515,7 @@ namespace System.Threading long tm = (long)timeout.TotalMilliseconds; if (-1 > tm || (long) Int32.MaxValue < tm) { - throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(timeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } return SignalAndWait(toSignal,toWaitOn,(int)tm,exitContext); #endif @@ -534,15 +534,15 @@ namespace System.Threading #else if(null == toSignal) { - throw new ArgumentNullException("toSignal"); + throw new ArgumentNullException(nameof(toSignal)); } if(null == toWaitOn) { - throw new ArgumentNullException("toWaitOn"); + throw new ArgumentNullException(nameof(toWaitOn)); } if (-1 > millisecondsTimeout) { - throw new ArgumentOutOfRangeException("millisecondsTimeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); + throw new ArgumentOutOfRangeException(nameof(millisecondsTimeout), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1")); } Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/ThrowHelper.cs b/src/mscorlib/src/System/ThrowHelper.cs index 4553ab7362..9c471e3d17 100644 --- a/src/mscorlib/src/System/ThrowHelper.cs +++ b/src/mscorlib/src/System/ThrowHelper.cs @@ -10,7 +10,7 @@ namespace System { // The old way to throw an exception generates quite a lot IL code and assembly code. // Following is an example: // C# source - // throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); + // throw new ArgumentNullException(nameof(key), Environment.GetResourceString("ArgumentNull_Key")); // IL code: // IL_0003: ldstr "key" // IL_0008: ldstr "ArgumentNull_Key" @@ -210,11 +210,11 @@ namespace System { } private static ArgumentException GetWrongKeyTypeArgumentException(object key, Type targetType) { - return new ArgumentException(Environment.GetResourceString("Arg_WrongType", key, targetType), "key"); + return new ArgumentException(Environment.GetResourceString("Arg_WrongType", key, targetType), nameof(key)); } private static ArgumentException GetWrongValueTypeArgumentException(object value, Type targetType) { - return new ArgumentException(Environment.GetResourceString("Arg_WrongType", value, targetType), "value"); + return new ArgumentException(Environment.GetResourceString("Arg_WrongType", value, targetType), nameof(value)); } private static ArgumentOutOfRangeException GetArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) { diff --git a/src/mscorlib/src/System/TimeZoneInfo.cs b/src/mscorlib/src/System/TimeZoneInfo.cs index a9d194afab..2a7544db18 100644 --- a/src/mscorlib/src/System/TimeZoneInfo.cs +++ b/src/mscorlib/src/System/TimeZoneInfo.cs @@ -345,7 +345,7 @@ namespace System { // public TimeSpan[] GetAmbiguousTimeOffsets(DateTimeOffset dateTimeOffset) { if (!SupportsDaylightSavingTime) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetIsNotAmbiguous"), "dateTimeOffset"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetIsNotAmbiguous"), nameof(dateTimeOffset)); } Contract.EndContractBlock(); @@ -359,7 +359,7 @@ namespace System { } if (!isAmbiguous) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetIsNotAmbiguous"), "dateTimeOffset"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeOffsetIsNotAmbiguous"), nameof(dateTimeOffset)); } // the passed in dateTime is ambiguous in this TimeZoneInfo instance @@ -382,7 +382,7 @@ namespace System { public TimeSpan[] GetAmbiguousTimeOffsets(DateTime dateTime) { if (!SupportsDaylightSavingTime) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsNotAmbiguous"), "dateTime"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsNotAmbiguous"), nameof(dateTime)); } Contract.EndContractBlock(); @@ -407,7 +407,7 @@ namespace System { } if (!isAmbiguous) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsNotAmbiguous"), "dateTime"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsNotAmbiguous"), nameof(dateTime)); } // the passed in dateTime is ambiguous in this TimeZoneInfo instance @@ -738,7 +738,7 @@ namespace System { static public DateTimeOffset ConvertTime(DateTimeOffset dateTimeOffset, TimeZoneInfo destinationTimeZone) { if (destinationTimeZone == null) { - throw new ArgumentNullException("destinationTimeZone"); + throw new ArgumentNullException(nameof(destinationTimeZone)); } Contract.EndContractBlock(); @@ -762,7 +762,7 @@ namespace System { static public DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone) { if (destinationTimeZone == null) { - throw new ArgumentNullException("destinationTimeZone"); + throw new ArgumentNullException(nameof(destinationTimeZone)); } Contract.EndContractBlock(); @@ -790,17 +790,17 @@ namespace System { static private DateTime ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData) { if (sourceTimeZone == null) { - throw new ArgumentNullException("sourceTimeZone"); + throw new ArgumentNullException(nameof(sourceTimeZone)); } if (destinationTimeZone == null) { - throw new ArgumentNullException("destinationTimeZone"); + throw new ArgumentNullException(nameof(destinationTimeZone)); } Contract.EndContractBlock(); DateTimeKind sourceKind = cachedData.GetCorrespondingKind(sourceTimeZone); if ( ((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == 0) && (dateTime.Kind != DateTimeKind.Unspecified) && (dateTime.Kind != sourceKind) ) { - throw new ArgumentException(Environment.GetResourceString("Argument_ConvertMismatch"), "sourceTimeZone"); + throw new ArgumentException(Environment.GetResourceString("Argument_ConvertMismatch"), nameof(sourceTimeZone)); } // @@ -823,7 +823,7 @@ namespace System { // 'dateTime' might be in an invalid time range since it is in an AdjustmentRule // period that supports DST if (((flags & TimeZoneInfoOptions.NoThrowOnInvalidTime) == 0) && GetIsInvalidTime(dateTime, sourceRule, sourceDaylightTime)) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsInvalid"), "dateTime"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeIsInvalid"), nameof(dateTime)); } sourceIsDaylightSavings = GetIsDaylightSavings(dateTime, sourceRule, sourceDaylightTime, flags); @@ -921,10 +921,10 @@ namespace System { // static public TimeZoneInfo FromSerializedString(string source) { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (source.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSerializedString", source), "source"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSerializedString", source), nameof(source)); } Contract.EndContractBlock(); @@ -1025,7 +1025,7 @@ namespace System { // public Boolean HasSameRules(TimeZoneInfo other) { if (other == null) { - throw new ArgumentNullException("other"); + throw new ArgumentNullException(nameof(other)); } // check the utcOffset and supportsDaylightSavingTime members @@ -1376,7 +1376,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -1392,7 +1392,7 @@ namespace System { TimeZoneInfo(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } m_id = (String)info.GetValue("Id", typeof(String)); @@ -2582,7 +2582,7 @@ namespace System { } if (id == null) { - throw new ArgumentNullException("id"); + throw new ArgumentNullException(nameof(id)); } else if (!IsValidSystemTimeZoneId(id)) { throw new TimeZoneNotFoundException(Environment.GetResourceString("TimeZoneNotFound_MissingData", id)); @@ -4386,20 +4386,20 @@ namespace System { out Boolean adjustmentRulesSupportDst) { if (id == null) { - throw new ArgumentNullException("id"); + throw new ArgumentNullException(nameof(id)); } if (id.Length == 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_InvalidId", id), "id"); + throw new ArgumentException(Environment.GetResourceString("Argument_InvalidId", id), nameof(id)); } if (UtcOffsetOutOfRange(baseUtcOffset)) { - throw new ArgumentOutOfRangeException("baseUtcOffset", Environment.GetResourceString("ArgumentOutOfRange_UtcOffset")); + throw new ArgumentOutOfRangeException(nameof(baseUtcOffset), Environment.GetResourceString("ArgumentOutOfRange_UtcOffset")); } if (baseUtcOffset.Ticks % TimeSpan.TicksPerMinute != 0) { - throw new ArgumentException(Environment.GetResourceString("Argument_TimeSpanHasSeconds"), "baseUtcOffset"); + throw new ArgumentException(Environment.GetResourceString("Argument_TimeSpanHasSeconds"), nameof(baseUtcOffset)); } Contract.EndContractBlock(); @@ -4649,21 +4649,21 @@ namespace System { if (dateStart.Kind != DateTimeKind.Unspecified && dateStart.Kind != DateTimeKind.Utc) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecifiedOrUtc"), "dateStart"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecifiedOrUtc"), nameof(dateStart)); } if (dateEnd.Kind != DateTimeKind.Unspecified && dateEnd.Kind != DateTimeKind.Utc) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecifiedOrUtc"), "dateEnd"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecifiedOrUtc"), nameof(dateEnd)); } if (daylightTransitionStart.Equals(daylightTransitionEnd) && !noDaylightTransitions) { throw new ArgumentException(Environment.GetResourceString("Argument_TransitionTimesAreIdentical"), - "daylightTransitionEnd"); + nameof(daylightTransitionEnd)); } if (dateStart > dateEnd) { - throw new ArgumentException(Environment.GetResourceString("Argument_OutOfOrderDateTimes"), "dateStart"); + throw new ArgumentException(Environment.GetResourceString("Argument_OutOfOrderDateTimes"), nameof(dateStart)); } // This cannot use UtcOffsetOutOfRange to account for the scenario where Samoa moved across the International Date Line, @@ -4671,23 +4671,23 @@ namespace System { // So when trying to describe DaylightDeltas for those times, the DaylightDelta needs // to be -23 (what it takes to go from UTC+13 to UTC-10) if (daylightDelta.TotalHours < -23.0 || daylightDelta.TotalHours > 14.0) { - throw new ArgumentOutOfRangeException("daylightDelta", daylightDelta, + throw new ArgumentOutOfRangeException(nameof(daylightDelta), daylightDelta, Environment.GetResourceString("ArgumentOutOfRange_UtcOffset")); } if (daylightDelta.Ticks % TimeSpan.TicksPerMinute != 0) { throw new ArgumentException(Environment.GetResourceString("Argument_TimeSpanHasSeconds"), - "daylightDelta"); + nameof(daylightDelta)); } if (dateStart != DateTime.MinValue && dateStart.Kind == DateTimeKind.Unspecified && dateStart.TimeOfDay != TimeSpan.Zero) { throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTimeOfDay"), - "dateStart"); + nameof(dateStart)); } if (dateEnd != DateTime.MaxValue && dateEnd.Kind == DateTimeKind.Unspecified && dateEnd.TimeOfDay != TimeSpan.Zero) { throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTimeOfDay"), - "dateEnd"); + nameof(dateEnd)); } Contract.EndContractBlock(); } @@ -4712,7 +4712,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -4727,7 +4727,7 @@ namespace System { AdjustmentRule(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } m_dateStart = (DateTime)info.GetValue("DateStart", typeof(DateTime)); @@ -4930,33 +4930,33 @@ namespace System { DayOfWeek dayOfWeek) { if (timeOfDay.Kind != DateTimeKind.Unspecified) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecified"), "timeOfDay"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeKindMustBeUnspecified"), nameof(timeOfDay)); } // Month range 1-12 if (month < 1 || month > 12) { - throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_MonthParam")); + throw new ArgumentOutOfRangeException(nameof(month), Environment.GetResourceString("ArgumentOutOfRange_MonthParam")); } // Day range 1-31 if (day < 1 || day > 31) { - throw new ArgumentOutOfRangeException("day", Environment.GetResourceString("ArgumentOutOfRange_DayParam")); + throw new ArgumentOutOfRangeException(nameof(day), Environment.GetResourceString("ArgumentOutOfRange_DayParam")); } // Week range 1-5 if (week < 1 || week > 5) { - throw new ArgumentOutOfRangeException("week", Environment.GetResourceString("ArgumentOutOfRange_Week")); + throw new ArgumentOutOfRangeException(nameof(week), Environment.GetResourceString("ArgumentOutOfRange_Week")); } // DayOfWeek range 0-6 if ((int)dayOfWeek < 0 || (int)dayOfWeek > 6) { - throw new ArgumentOutOfRangeException("dayOfWeek", Environment.GetResourceString("ArgumentOutOfRange_DayOfWeek")); + throw new ArgumentOutOfRangeException(nameof(dayOfWeek), Environment.GetResourceString("ArgumentOutOfRange_DayOfWeek")); } Contract.EndContractBlock(); if (timeOfDay.Year != 1 || timeOfDay.Month != 1 || timeOfDay.Day != 1 || (timeOfDay.Ticks % TimeSpan.TicksPerMillisecond != 0)) { - throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTicks"), "timeOfDay"); + throw new ArgumentException(Environment.GetResourceString("Argument_DateTimeHasTicks"), nameof(timeOfDay)); } } @@ -4976,7 +4976,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -4990,7 +4990,7 @@ namespace System { TransitionTime(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } m_timeOfDay = (DateTime)info.GetValue("TimeOfDay", typeof(DateTime)); @@ -5681,7 +5681,7 @@ namespace System { { if (data == null || data.Length < index + c_len) { - throw new ArgumentException(Environment.GetResourceString("Argument_TimeZoneInfoInvalidTZif"), "data"); + throw new ArgumentException(Environment.GetResourceString("Argument_TimeZoneInfoInvalidTZif"), nameof(data)); } Contract.EndContractBlock(); UtcOffset = new TimeSpan(0, 0, TZif_ToInt32(data, index + 00)); @@ -5705,7 +5705,7 @@ namespace System { { if (data == null || data.Length < c_len) { - throw new ArgumentException("bad data", "data"); + throw new ArgumentException("bad data", nameof(data)); } Contract.EndContractBlock(); @@ -5714,7 +5714,7 @@ namespace System { if (Magic != 0x545A6966) { // 0x545A6966 = {0x54, 0x5A, 0x69, 0x66} = "TZif" - throw new ArgumentException(Environment.GetResourceString("Argument_TimeZoneInfoBadTZif"), "data"); + throw new ArgumentException(Environment.GetResourceString("Argument_TimeZoneInfoBadTZif"), nameof(data)); } byte version = data[index + 04]; diff --git a/src/mscorlib/src/System/Tuple.cs b/src/mscorlib/src/System/Tuple.cs index ce92da4e47..6d41a8bc1e 100644 --- a/src/mscorlib/src/System/Tuple.cs +++ b/src/mscorlib/src/System/Tuple.cs @@ -123,7 +123,7 @@ namespace System { Tuple<T1> objTuple = other as Tuple<T1>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } return comparer.Compare(m_Item1, objTuple.m_Item1); @@ -199,7 +199,7 @@ namespace System { Tuple<T1, T2> objTuple = other as Tuple<T1, T2>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; @@ -286,7 +286,7 @@ namespace System { Tuple<T1, T2, T3> objTuple = other as Tuple<T1, T2, T3>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; @@ -382,7 +382,7 @@ namespace System { Tuple<T1, T2, T3, T4> objTuple = other as Tuple<T1, T2, T3, T4>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; @@ -487,7 +487,7 @@ namespace System { Tuple<T1, T2, T3, T4, T5> objTuple = other as Tuple<T1, T2, T3, T4, T5>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; @@ -601,7 +601,7 @@ namespace System { Tuple<T1, T2, T3, T4, T5, T6> objTuple = other as Tuple<T1, T2, T3, T4, T5, T6>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; @@ -724,7 +724,7 @@ namespace System { Tuple<T1, T2, T3, T4, T5, T6, T7> objTuple = other as Tuple<T1, T2, T3, T4, T5, T6, T7>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; @@ -860,7 +860,7 @@ namespace System { Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> objTuple = other as Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>; if (objTuple == null) { - throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), "other"); + throw new ArgumentException(Environment.GetResourceString("ArgumentException_TupleIncorrectType", this.GetType().ToString()), nameof(other)); } int c = 0; diff --git a/src/mscorlib/src/System/Type.cs b/src/mscorlib/src/System/Type.cs index 467a228b67..6b1f363bdf 100644 --- a/src/mscorlib/src/System/Type.cs +++ b/src/mscorlib/src/System/Type.cs @@ -395,11 +395,11 @@ namespace System { { // Must provide some types (Type[0] for nothing) if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i=0;i<types.Length;i++) if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); return GetConstructorImpl(bindingAttr, binder, callConvention, types, modifiers); } @@ -407,11 +407,11 @@ namespace System { public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) { if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i=0;i<types.Length;i++) if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); return GetConstructorImpl(bindingAttr, binder, CallingConventions.Any, types, modifiers); } @@ -464,13 +464,13 @@ namespace System { ParameterModifier[] modifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i = 0; i < types.Length; i++) if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); return GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers); } @@ -481,46 +481,46 @@ namespace System { ParameterModifier[] modifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i = 0; i < types.Length; i++) if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); return GetMethodImpl(name, bindingAttr, binder, CallingConventions.Any, types, modifiers); } public MethodInfo GetMethod(String name, Type[] types, ParameterModifier[] modifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i=0;i<types.Length;i++) if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); return GetMethodImpl(name, Type.DefaultLookup, null, CallingConventions.Any, types, modifiers); } public MethodInfo GetMethod(String name,Type[] types) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); for (int i=0;i<types.Length;i++) if (types[i] == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); return GetMethodImpl(name, Type.DefaultLookup, null, CallingConventions.Any, types, null); } public MethodInfo GetMethod(String name, BindingFlags bindingAttr) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); return GetMethodImpl(name, bindingAttr, null, CallingConventions.Any, null, null); } @@ -528,7 +528,7 @@ namespace System { public MethodInfo GetMethod(String name) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); return GetMethodImpl(name, Type.DefaultLookup, null, CallingConventions.Any, null, null); } @@ -584,7 +584,7 @@ namespace System { public virtual Type[] FindInterfaces(TypeFilter filter,Object filterCriteria) { if (filter == null) - throw new ArgumentNullException("filter"); + throw new ArgumentNullException(nameof(filter)); Contract.EndContractBlock(); Type[] c = GetInterfaces(); int cnt = 0; @@ -631,9 +631,9 @@ namespace System { Type returnType, Type[] types, ParameterModifier[] modifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); return GetPropertyImpl(name,bindingAttr,binder,returnType,types,modifiers); } @@ -641,9 +641,9 @@ namespace System { public PropertyInfo GetProperty(String name, Type returnType, Type[] types,ParameterModifier[] modifiers) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); return GetPropertyImpl(name,Type.DefaultLookup,null,returnType,types,modifiers); } @@ -651,7 +651,7 @@ namespace System { public PropertyInfo GetProperty(String name, BindingFlags bindingAttr) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); return GetPropertyImpl(name,bindingAttr,null,null,null,null); } @@ -659,9 +659,9 @@ namespace System { public PropertyInfo GetProperty(String name, Type returnType, Type[] types) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); return GetPropertyImpl(name,Type.DefaultLookup,null,returnType,types,null); } @@ -669,9 +669,9 @@ namespace System { public PropertyInfo GetProperty(String name, Type[] types) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (types == null) - throw new ArgumentNullException("types"); + throw new ArgumentNullException(nameof(types)); Contract.EndContractBlock(); return GetPropertyImpl(name,Type.DefaultLookup,null,null,types,null); } @@ -679,9 +679,9 @@ namespace System { public PropertyInfo GetProperty(String name, Type returnType) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (returnType == null) - throw new ArgumentNullException("returnType"); + throw new ArgumentNullException(nameof(returnType)); Contract.EndContractBlock(); return GetPropertyImpl(name,Type.DefaultLookup,null,returnType,null,null); } @@ -689,9 +689,9 @@ namespace System { internal PropertyInfo GetProperty(String name, BindingFlags bindingAttr, Type returnType) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); if (returnType == null) - throw new ArgumentNullException("returnType"); + throw new ArgumentNullException(nameof(returnType)); Contract.EndContractBlock(); return GetPropertyImpl(name, bindingAttr, null, returnType, null, null); } @@ -699,7 +699,7 @@ namespace System { public PropertyInfo GetProperty(String name) { if (name == null) - throw new ArgumentNullException("name"); + throw new ArgumentNullException(nameof(name)); Contract.EndContractBlock(); return GetPropertyImpl(name,Type.DefaultLookup,null,null,null,null); } @@ -1472,7 +1472,7 @@ namespace System { public virtual bool IsEnumDefined(object value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (!IsEnum) throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); @@ -1520,7 +1520,7 @@ namespace System { public virtual string GetEnumName(object value) { if (value == null) - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); if (!IsEnum) throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); @@ -1529,7 +1529,7 @@ namespace System { Type valueType = value.GetType(); if (!(valueType.IsEnum || Type.IsIntegerType(valueType))) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), nameof(value)); Array values = GetEnumRawConstantValues(); int index = BinarySearch(values, value); @@ -1750,7 +1750,7 @@ namespace System { // types. public static Type[] GetTypeArray(Object[] args) { if (args == null) - throw new ArgumentNullException("args"); + throw new ArgumentNullException(nameof(args)); Contract.EndContractBlock(); Type[] cls = new Type[args.Length]; for (int i = 0;i < cls.Length;i++) diff --git a/src/mscorlib/src/System/TypeLoadException.cs b/src/mscorlib/src/System/TypeLoadException.cs index 9b5d28dfba..a1eae15172 100644 --- a/src/mscorlib/src/System/TypeLoadException.cs +++ b/src/mscorlib/src/System/TypeLoadException.cs @@ -103,7 +103,7 @@ namespace System { protected TypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); ClassName = info.GetString("TypeLoadClassName"); @@ -122,7 +122,7 @@ namespace System { [System.Security.SecurityCritical] // auto-generated_required public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); base.GetObjectData(info, context); diff --git a/src/mscorlib/src/System/TypeNameParser.cs b/src/mscorlib/src/System/TypeNameParser.cs index fee0f3aa64..0fadf39053 100644 --- a/src/mscorlib/src/System/TypeNameParser.cs +++ b/src/mscorlib/src/System/TypeNameParser.cs @@ -79,7 +79,7 @@ namespace System ref StackCrawlMark stackMark) { if (typeName == null) - throw new ArgumentNullException("typeName"); + throw new ArgumentNullException(nameof(typeName)); if (typeName.Length > 0 && typeName[0] == '\0') throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength")); Contract.EndContractBlock(); diff --git a/src/mscorlib/src/System/TypedReference.cs b/src/mscorlib/src/System/TypedReference.cs index 7c68c4164f..9d3f36f4f4 100644 --- a/src/mscorlib/src/System/TypedReference.cs +++ b/src/mscorlib/src/System/TypedReference.cs @@ -27,9 +27,9 @@ namespace System { [CLSCompliant(false)] public static TypedReference MakeTypedReference(Object target, FieldInfo[] flds) { if (target == null) - throw new ArgumentNullException("target"); + throw new ArgumentNullException(nameof(target)); if (flds == null) - throw new ArgumentNullException("flds"); + throw new ArgumentNullException(nameof(flds)); Contract.EndContractBlock(); if (flds.Length == 0) throw new ArgumentException(Environment.GetResourceString("Arg_ArrayZeroError")); diff --git a/src/mscorlib/src/System/UIntPtr.cs b/src/mscorlib/src/System/UIntPtr.cs index ac3b811b42..141eb4d192 100644 --- a/src/mscorlib/src/System/UIntPtr.cs +++ b/src/mscorlib/src/System/UIntPtr.cs @@ -71,7 +71,7 @@ namespace System { unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); info.AddValue("value", (ulong)m_value); diff --git a/src/mscorlib/src/System/UnitySerializationHolder.cs b/src/mscorlib/src/System/UnitySerializationHolder.cs index ec32fce348..28400043ce 100644 --- a/src/mscorlib/src/System/UnitySerializationHolder.cs +++ b/src/mscorlib/src/System/UnitySerializationHolder.cs @@ -166,7 +166,7 @@ namespace System { internal UnitySerializationHolder(SerializationInfo info, StreamingContext context) { if (info == null) - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); m_unityType = info.GetInt32("UnityType"); diff --git a/src/mscorlib/src/System/Variant.cs b/src/mscorlib/src/System/Variant.cs index 26e2e4aa1a..c75f82f37d 100644 --- a/src/mscorlib/src/System/Variant.cs +++ b/src/mscorlib/src/System/Variant.cs @@ -345,9 +345,9 @@ namespace System { [System.Security.SecurityCritical] // auto-generated unsafe public Variant(void* voidPointer,Type pointerType) { if (pointerType == null) - throw new ArgumentNullException("pointerType"); + throw new ArgumentNullException(nameof(pointerType)); if (!pointerType.IsPointer) - throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),"pointerType"); + throw new ArgumentException(Environment.GetResourceString("Arg_MustBePointer"),nameof(pointerType)); Contract.EndContractBlock(); m_objref = pointerType; diff --git a/src/mscorlib/src/System/Version.cs b/src/mscorlib/src/System/Version.cs index 34f716a724..7a0763b4b7 100644 --- a/src/mscorlib/src/System/Version.cs +++ b/src/mscorlib/src/System/Version.cs @@ -37,16 +37,16 @@ namespace System { public Version(int major, int minor, int build, int revision) { if (major < 0) - throw new ArgumentOutOfRangeException("major",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(major),Environment.GetResourceString("ArgumentOutOfRange_Version")); if (minor < 0) - throw new ArgumentOutOfRangeException("minor",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(minor),Environment.GetResourceString("ArgumentOutOfRange_Version")); if (build < 0) - throw new ArgumentOutOfRangeException("build",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(build),Environment.GetResourceString("ArgumentOutOfRange_Version")); if (revision < 0) - throw new ArgumentOutOfRangeException("revision",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(revision),Environment.GetResourceString("ArgumentOutOfRange_Version")); Contract.EndContractBlock(); _Major = major; @@ -57,13 +57,13 @@ namespace System { public Version(int major, int minor, int build) { if (major < 0) - throw new ArgumentOutOfRangeException("major",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(major),Environment.GetResourceString("ArgumentOutOfRange_Version")); if (minor < 0) - throw new ArgumentOutOfRangeException("minor",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(minor),Environment.GetResourceString("ArgumentOutOfRange_Version")); if (build < 0) - throw new ArgumentOutOfRangeException("build",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(build),Environment.GetResourceString("ArgumentOutOfRange_Version")); Contract.EndContractBlock(); @@ -74,10 +74,10 @@ namespace System { public Version(int major, int minor) { if (major < 0) - throw new ArgumentOutOfRangeException("major",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(major),Environment.GetResourceString("ArgumentOutOfRange_Version")); if (minor < 0) - throw new ArgumentOutOfRangeException("minor",Environment.GetResourceString("ArgumentOutOfRange_Version")); + throw new ArgumentOutOfRangeException(nameof(minor),Environment.GetResourceString("ArgumentOutOfRange_Version")); Contract.EndContractBlock(); _Major = major; @@ -215,7 +215,7 @@ namespace System { return StringBuilderCache.GetStringAndRelease(sb); default: if (_Build == -1) - throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper", "0", "2"), "fieldCount"); + throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper", "0", "2"), nameof(fieldCount)); if (fieldCount == 3) { @@ -229,7 +229,7 @@ namespace System { } if (_Revision == -1) - throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper", "0", "3"), "fieldCount"); + throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper", "0", "3"), nameof(fieldCount)); if (fieldCount == 4) { @@ -244,7 +244,7 @@ namespace System { return StringBuilderCache.GetStringAndRelease(sb); } - throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper", "0", "4"), "fieldCount"); + throw new ArgumentException(Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper", "0", "4"), nameof(fieldCount)); } } @@ -272,7 +272,7 @@ namespace System { public static Version Parse(string input) { if (input == null) { - throw new ArgumentNullException("input"); + throw new ArgumentNullException(nameof(input)); } Contract.EndContractBlock(); @@ -368,14 +368,14 @@ namespace System { public static bool operator <(Version v1, Version v2) { if ((Object) v1 == null) - throw new ArgumentNullException("v1"); + throw new ArgumentNullException(nameof(v1)); Contract.EndContractBlock(); return (v1.CompareTo(v2) < 0); } public static bool operator <=(Version v1, Version v2) { if ((Object) v1 == null) - throw new ArgumentNullException("v1"); + throw new ArgumentNullException(nameof(v1)); Contract.EndContractBlock(); return (v1.CompareTo(v2) <= 0); } diff --git a/src/mscorlib/src/System/WeakReference.cs b/src/mscorlib/src/System/WeakReference.cs index d12ca3e853..27a9ab7744 100644 --- a/src/mscorlib/src/System/WeakReference.cs +++ b/src/mscorlib/src/System/WeakReference.cs @@ -53,7 +53,7 @@ namespace System { protected WeakReference(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -106,7 +106,7 @@ namespace System { public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info==null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); info.AddValue("TrackedObject", Target, typeof(Object)); diff --git a/src/mscorlib/src/System/WeakReferenceOfT.cs b/src/mscorlib/src/System/WeakReferenceOfT.cs index b8195df6d9..da2999eae7 100644 --- a/src/mscorlib/src/System/WeakReferenceOfT.cs +++ b/src/mscorlib/src/System/WeakReferenceOfT.cs @@ -46,7 +46,7 @@ namespace System internal WeakReference(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); @@ -102,7 +102,7 @@ namespace System public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { - throw new ArgumentNullException("info"); + throw new ArgumentNullException(nameof(info)); } Contract.EndContractBlock(); |