diff --git a/iothub/device/src/Authentication/DeviceAuthenticationWithRegistrySymmetricKey.cs b/iothub/device/src/Authentication/DeviceAuthenticationWithRegistrySymmetricKey.cs
index 49a3504489..8a2e7d4630 100644
--- a/iothub/device/src/Authentication/DeviceAuthenticationWithRegistrySymmetricKey.cs
+++ b/iothub/device/src/Authentication/DeviceAuthenticationWithRegistrySymmetricKey.cs
@@ -84,7 +84,7 @@ private void SetKey(byte[] key)
private void SetKeyFromBase64String(string key)
{
- if (key.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(key))
{
throw new ArgumentNullException(nameof(key));
}
@@ -99,7 +99,7 @@ private void SetKeyFromBase64String(string key)
private void SetDeviceId(string deviceId)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
diff --git a/iothub/device/src/Authentication/DeviceAuthenticationWithSharedAccessPolicyKey.cs b/iothub/device/src/Authentication/DeviceAuthenticationWithSharedAccessPolicyKey.cs
index 8fc31666eb..0b63bae945 100644
--- a/iothub/device/src/Authentication/DeviceAuthenticationWithSharedAccessPolicyKey.cs
+++ b/iothub/device/src/Authentication/DeviceAuthenticationWithSharedAccessPolicyKey.cs
@@ -77,7 +77,7 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
private void SetDeviceId(string deviceId)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
@@ -87,7 +87,7 @@ private void SetDeviceId(string deviceId)
private void SetKey(string key)
{
- if (key.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(key))
{
throw new ArgumentNullException(nameof(key));
}
@@ -102,7 +102,7 @@ private void SetKey(string key)
private void SetPolicyName(string policyName)
{
- if (policyName.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(policyName))
{
throw new ArgumentNullException(nameof(policyName));
}
diff --git a/iothub/device/src/Authentication/DeviceAuthenticationWithToken.cs b/iothub/device/src/Authentication/DeviceAuthenticationWithToken.cs
index 84abc65a1f..0720915d5f 100644
--- a/iothub/device/src/Authentication/DeviceAuthenticationWithToken.cs
+++ b/iothub/device/src/Authentication/DeviceAuthenticationWithToken.cs
@@ -65,7 +65,7 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
private void SetDeviceId(string deviceId)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
@@ -75,7 +75,7 @@ private void SetDeviceId(string deviceId)
private void SetToken(string token)
{
- if (token.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(token))
{
throw new ArgumentNullException(nameof(token));
}
diff --git a/iothub/device/src/Authentication/DeviceAuthenticationWithTokenRefresh.cs b/iothub/device/src/Authentication/DeviceAuthenticationWithTokenRefresh.cs
index 9b5009f39c..ba01dd380a 100644
--- a/iothub/device/src/Authentication/DeviceAuthenticationWithTokenRefresh.cs
+++ b/iothub/device/src/Authentication/DeviceAuthenticationWithTokenRefresh.cs
@@ -80,7 +80,7 @@ public DeviceAuthenticationWithTokenRefresh(
SetSasTokenRenewalBufferPercentage(timeBufferPercentage),
disposeWithClient)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
diff --git a/iothub/device/src/Authentication/DeviceAuthenticationWithX509Certificate.cs b/iothub/device/src/Authentication/DeviceAuthenticationWithX509Certificate.cs
index 40d23dc202..b94632a4c0 100644
--- a/iothub/device/src/Authentication/DeviceAuthenticationWithX509Certificate.cs
+++ b/iothub/device/src/Authentication/DeviceAuthenticationWithX509Certificate.cs
@@ -78,7 +78,7 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
private void SetDeviceId(string deviceId)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
diff --git a/iothub/device/src/Authentication/IotHubConnectionString.cs b/iothub/device/src/Authentication/IotHubConnectionString.cs
index 8e31d70d84..61e6ddf6e5 100644
--- a/iothub/device/src/Authentication/IotHubConnectionString.cs
+++ b/iothub/device/src/Authentication/IotHubConnectionString.cs
@@ -49,7 +49,7 @@ public IotHubConnectionString(IotHubConnectionStringBuilder builder)
}
else if (!string.IsNullOrEmpty(SharedAccessKey))
{
- if (ModuleId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(ModuleId))
{
// Since the SDK creates the instance of disposable DeviceAuthenticationWithSakRefresh, the SDK needs to
// dispose it once the client is disposed.
diff --git a/iothub/device/src/Authentication/IotHubConnectionStringBuilder.cs b/iothub/device/src/Authentication/IotHubConnectionStringBuilder.cs
index 74417c64d6..bc2e7d94d9 100644
--- a/iothub/device/src/Authentication/IotHubConnectionStringBuilder.cs
+++ b/iothub/device/src/Authentication/IotHubConnectionStringBuilder.cs
@@ -97,7 +97,7 @@ public static IotHubConnectionStringBuilder Create(string hostname, string gatew
/// A new instance of the class with a populated connection string.
public static IotHubConnectionStringBuilder Create(string iotHubConnectionString)
{
- if (iotHubConnectionString.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(iotHubConnectionString))
{
throw new ArgumentNullException(nameof(iotHubConnectionString));
}
@@ -253,12 +253,12 @@ private void Parse(string iotHubConnectionString)
private void Validate()
{
- if (DeviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(DeviceId))
{
throw new ArgumentException("DeviceId must be specified in connection string");
}
- if (!(SharedAccessKey.IsNullOrWhiteSpace() ^ SharedAccessSignature.IsNullOrWhiteSpace()))
+ if (!string.IsNullOrWhiteSpace(SharedAccessKey) ^ string.IsNullOrWhiteSpace(SharedAccessSignature))
{
if (!(UsingX509Cert || AuthenticationMethod is AuthenticationWithTokenRefresh))
{
@@ -268,19 +268,19 @@ private void Validate()
}
if ((UsingX509Cert || Certificate != null) &&
- (!SharedAccessKey.IsNullOrWhiteSpace()
- || !SharedAccessSignature.IsNullOrWhiteSpace()))
+ (!string.IsNullOrWhiteSpace(SharedAccessKey)
+ || !string.IsNullOrWhiteSpace(SharedAccessSignature)))
{
throw new ArgumentException(
"Should not specify either SharedAccessKey or SharedAccessSignature if X.509 certificate is used");
}
- if (IotHubName.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(IotHubName))
{
throw new FormatException("Missing IoT hub name");
}
- if (!SharedAccessKey.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(SharedAccessKey))
{
Convert.FromBase64String(SharedAccessKey);
}
@@ -313,7 +313,7 @@ private void Validate()
private void SetHostName(string hostname)
{
- if (hostname.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(hostname))
{
throw new ArgumentNullException(nameof(hostname));
}
@@ -332,7 +332,7 @@ private void SetIotHubName()
// For transparent gateway scenarios, we can simplify the input credentials to only specify the gateway device hostname,
// instead of having to specify both the IoT hub hostname and the gateway device hostname.
// In this case, the hostname will be of the format "myGatewayDevice", and will not have ".azure-devices.net" suffix.
- if (IotHubName.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(IotHubName))
{
if (Logging.IsEnabled)
Logging.Info(this, $"Connecting to a gateway device with hostname=[{HostName}]");
diff --git a/iothub/device/src/Authentication/ModuleAuthenticationWithRegistrySymmetricKey.cs b/iothub/device/src/Authentication/ModuleAuthenticationWithRegistrySymmetricKey.cs
index 43c56b789e..cd78d33e57 100644
--- a/iothub/device/src/Authentication/ModuleAuthenticationWithRegistrySymmetricKey.cs
+++ b/iothub/device/src/Authentication/ModuleAuthenticationWithRegistrySymmetricKey.cs
@@ -97,7 +97,7 @@ private void SetKey(byte[] key)
private void SetKeyFromBase64String(string key)
{
- if (key.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(key))
{
throw new ArgumentNullException(nameof(key));
}
@@ -112,7 +112,7 @@ private void SetKeyFromBase64String(string key)
private void SetDeviceId(string deviceId)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
@@ -122,7 +122,7 @@ private void SetDeviceId(string deviceId)
private void SetModuleId(string moduleId)
{
- if (moduleId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(moduleId))
{
throw new ArgumentNullException(nameof(moduleId));
}
diff --git a/iothub/device/src/Authentication/ModuleAuthenticationWithToken.cs b/iothub/device/src/Authentication/ModuleAuthenticationWithToken.cs
index 9ddb49a0e1..45abba6284 100644
--- a/iothub/device/src/Authentication/ModuleAuthenticationWithToken.cs
+++ b/iothub/device/src/Authentication/ModuleAuthenticationWithToken.cs
@@ -78,7 +78,7 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH
private void SetDeviceId(string deviceId)
{
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
@@ -88,7 +88,7 @@ private void SetDeviceId(string deviceId)
private void SetModuleId(string moduleId)
{
- if (moduleId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(moduleId))
{
throw new ArgumentNullException(nameof(moduleId));
}
@@ -98,7 +98,7 @@ private void SetModuleId(string moduleId)
private void SetToken(string token)
{
- if (token.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(token))
{
throw new ArgumentNullException(nameof(token));
}
diff --git a/iothub/device/src/Authentication/ModuleAuthenticationWithTokenRefresh.cs b/iothub/device/src/Authentication/ModuleAuthenticationWithTokenRefresh.cs
index 0b63087b4e..a1e5f7bff6 100644
--- a/iothub/device/src/Authentication/ModuleAuthenticationWithTokenRefresh.cs
+++ b/iothub/device/src/Authentication/ModuleAuthenticationWithTokenRefresh.cs
@@ -87,12 +87,12 @@ public ModuleAuthenticationWithTokenRefresh(
SetSasTokenRenewalBufferPercentage(timeBufferPercentage),
disposeWithClient)
{
- if (moduleId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(moduleId))
{
throw new ArgumentNullException(nameof(moduleId));
}
- if (deviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(deviceId))
{
throw new ArgumentNullException(nameof(deviceId));
}
diff --git a/iothub/device/src/Common/Extensions/CommonExtensions.cs b/iothub/device/src/Common/Extensions/CommonExtensions.cs
index 944e21eda8..85d1824913 100644
--- a/iothub/device/src/Common/Extensions/CommonExtensions.cs
+++ b/iothub/device/src/Common/Extensions/CommonExtensions.cs
@@ -167,11 +167,6 @@ public static void AppendKeyValuePairIfNotEmpty(this StringBuilder builder, stri
}
}
- public static bool IsNullOrWhiteSpace(this string value)
- {
- return string.IsNullOrWhiteSpace(value);
- }
-
public static int NthIndexOf(this string str, char value, int startIndex, int n)
{
if (str == null)
diff --git a/iothub/device/src/Common/Security/SharedAccessSignatureBuilder.cs b/iothub/device/src/Common/Security/SharedAccessSignatureBuilder.cs
index 892029ba10..20ccdeb487 100644
--- a/iothub/device/src/Common/Security/SharedAccessSignatureBuilder.cs
+++ b/iothub/device/src/Common/Security/SharedAccessSignatureBuilder.cs
@@ -92,7 +92,7 @@ private string BuildSignature(string keyName, string key, string target, TimeSpa
SharedAccessSignatureConstants.SignatureFieldName, WebUtility.UrlEncode(signature),
SharedAccessSignatureConstants.ExpiryFieldName, WebUtility.UrlEncode(expiresOn));
- if (!keyName.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(keyName))
{
buffer.AppendFormat(CultureInfo.InvariantCulture, "&{0}={1}",
SharedAccessSignatureConstants.KeyNameFieldName, WebUtility.UrlEncode(keyName));
diff --git a/iothub/device/src/Transport/Amqp/AmqpUnit.cs b/iothub/device/src/Transport/Amqp/AmqpUnit.cs
index 9d7634b35b..b41f069d53 100644
--- a/iothub/device/src/Transport/Amqp/AmqpUnit.cs
+++ b/iothub/device/src/Transport/Amqp/AmqpUnit.cs
@@ -498,7 +498,7 @@ public async Task DisposeMessageAsync(string lockToken, AmqpIotD
Logging.Enter(this, lockToken, nameof(DisposeMessageAsync));
AmqpIotOutcome disposeOutcome;
- if (_deviceIdentity.IotHubConnectionString.ModuleId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(_deviceIdentity.IotHubConnectionString.ModuleId))
{
await EnsureMessageReceivingLinkIsOpenAsync(cancellationToken).ConfigureAwait(false);
diff --git a/iothub/device/src/Transport/Amqp/DeviceIdentity.cs b/iothub/device/src/Transport/Amqp/DeviceIdentity.cs
index 79ee3a93e0..ab902a15b9 100644
--- a/iothub/device/src/Transport/Amqp/DeviceIdentity.cs
+++ b/iothub/device/src/Transport/Amqp/DeviceIdentity.cs
@@ -47,9 +47,9 @@ internal DeviceIdentity(
private static string CreateAudience(IotHubConnectionString connectionString)
{
- if (connectionString.SharedAccessKeyName.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(connectionString.SharedAccessKeyName))
{
- return connectionString.ModuleId.IsNullOrWhiteSpace()
+ return string.IsNullOrWhiteSpace(connectionString.ModuleId)
? $"{connectionString.HostName}/devices/{WebUtility.UrlEncode(connectionString.DeviceId)}"
: $"{connectionString.HostName}/devices/{WebUtility.UrlEncode(connectionString.DeviceId)}/modules/{WebUtility.UrlEncode(connectionString.ModuleId)}";
}
diff --git a/iothub/device/src/Transport/AmqpIot/AmqpIotSession.cs b/iothub/device/src/Transport/AmqpIot/AmqpIotSession.cs
index 2db5c1e0ba..0ae5a6a6b0 100644
--- a/iothub/device/src/Transport/AmqpIot/AmqpIotSession.cs
+++ b/iothub/device/src/Transport/AmqpIot/AmqpIotSession.cs
@@ -228,7 +228,7 @@ private static async Task OpenSendingAmqpLinkAsync(
amqpLinkSettings.AddProperty(AmqpIotConstants.ChannelCorrelationId, correlationId);
}
- if (!deviceIdentity.AmqpTransportSettings.AuthenticationChain.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(deviceIdentity.AmqpTransportSettings.AuthenticationChain))
{
amqpLinkSettings.AddProperty(AmqpIotConstants.AuthChain, deviceIdentity.AmqpTransportSettings.AuthenticationChain);
}
@@ -306,7 +306,7 @@ private static async Task OpenReceivingAmqpLinkAsync(
amqpLinkSettings.AddProperty(AmqpIotConstants.ClientVersion, deviceIdentity.ProductInfo.ToString());
amqpLinkSettings.AddProperty(AmqpIotConstants.ApiVersion, ClientApiVersionHelper.ApiVersionString);
- if (!deviceIdentity.AmqpTransportSettings.AuthenticationChain.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(deviceIdentity.AmqpTransportSettings.AuthenticationChain))
{
amqpLinkSettings.AddProperty(AmqpIotConstants.AuthChain, deviceIdentity.AmqpTransportSettings.AuthenticationChain);
}
diff --git a/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs b/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs
index 15283041ae..4e35a17e29 100644
--- a/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs
+++ b/iothub/device/src/Transport/Mqtt/MqttIotHubAdapter.cs
@@ -341,14 +341,14 @@ private async Task ConnectAsync(IChannelHandlerContext context)
string usernameString = $"{_iotHubHostName}/{id}/?{ClientApiVersionHelper.ApiVersionQueryStringLatest}&{DeviceClientTypeParam}={Uri.EscapeDataString(_productInfo.ToString())}";
- if (!_mqttTransportSettings.AuthenticationChain.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(_mqttTransportSettings.AuthenticationChain))
{
usernameString += $"&{AuthChainParam}={Uri.EscapeDataString(_mqttTransportSettings.AuthenticationChain)}";
}
// This check is added to enable the device or module client to available plug and play features. For devices or modules that pass in the model Id,
// the SDK will enable plug and play features by appending the model Id to the MQTT CONNECT packet (in the username).
- if (!(_options?.ModelId).IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(_options?.ModelId))
{
usernameString += $"&{ModelIdParam}={Uri.EscapeDataString(_options.ModelId)}";
}
diff --git a/iothub/service/src/Authentication/IotHubConnectionStringBuilder.cs b/iothub/service/src/Authentication/IotHubConnectionStringBuilder.cs
index a63560dabf..9e345103fa 100644
--- a/iothub/service/src/Authentication/IotHubConnectionStringBuilder.cs
+++ b/iothub/service/src/Authentication/IotHubConnectionStringBuilder.cs
@@ -190,12 +190,12 @@ internal void Parse(string iotHubConnectionString)
internal void Validate()
{
- if (SharedAccessKeyName.IsNullOrWhiteSpace() && DeviceId.IsNullOrWhiteSpace())
+ if (string.IsNullOrWhiteSpace(SharedAccessKeyName) && string.IsNullOrWhiteSpace(DeviceId))
{
throw new ArgumentException("Should specify either SharedAccessKeyName or DeviceId");
}
- if (!(SharedAccessKey.IsNullOrWhiteSpace() ^ SharedAccessSignature.IsNullOrWhiteSpace()))
+ if (!string.IsNullOrWhiteSpace(SharedAccessKey) ^ string.IsNullOrWhiteSpace(SharedAccessSignature))
{
throw new ArgumentException("Should specify either SharedAccessKey or SharedAccessSignature");
}
@@ -205,7 +205,7 @@ internal void Validate()
throw new FormatException("Missing IoT hub name");
}
- if (!SharedAccessKey.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(SharedAccessKey))
{
Convert.FromBase64String(SharedAccessKey);
}
@@ -216,15 +216,15 @@ internal void Validate()
}
ValidateFormat(HostName, HostNamePropertyName, s_hostNameRegex);
- if (!SharedAccessKeyName.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(SharedAccessKeyName))
{
ValidateFormatIfSpecified(SharedAccessKeyName, SharedAccessKeyNamePropertyName, s_sharedAccessKeyNameRegex);
}
- if (!DeviceId.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(DeviceId))
{
ValidateFormatIfSpecified(DeviceId, DeviceIdPropertyName, s_idRegex);
}
- if (!ModuleId.IsNullOrWhiteSpace())
+ if (!string.IsNullOrWhiteSpace(ModuleId))
{
ValidateFormatIfSpecified(ModuleId, ModuleIdPropertyName, s_idRegex);
}
diff --git a/iothub/service/src/Common/Extensions/CommonExtensions.cs b/iothub/service/src/Common/Extensions/CommonExtensions.cs
index 45cd46132d..037b2958a2 100644
--- a/iothub/service/src/Common/Extensions/CommonExtensions.cs
+++ b/iothub/service/src/Common/Extensions/CommonExtensions.cs
@@ -244,16 +244,6 @@ public static void AppendKeyValuePairIfNotEmpty(this StringBuilder builder, stri
}
}
- ///
- /// Check if the value is null or empty.
- ///
- /// The value to check.
- /// Returns true if the value is null or empty, otherwise returns false.
- public static bool IsNullOrWhiteSpace(this string value)
- {
- return string.IsNullOrWhiteSpace(value);
- }
-
///
/// Removes white spaces from a string.
///