{
testPosition = 0;
- if (input == null || input.Length == 0) // nothing to verify.
+ if (string.IsNullOrEmpty(input)) // nothing to verify.
{
resultHint = MaskedTextResultHint.NoEffect;
return true;
protected Type? GetTypeFromName(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string? typeName)
{
- if (typeName == null || typeName.Length == 0)
+ if (string.IsNullOrEmpty(typeName))
{
return null;
}
name = component.Site.Name;
}
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
{
int ci = System.Threading.Interlocked.Increment(ref s_collisionIndex) - 1;
name = ci.ToString(CultureInfo.InvariantCulture);
{ // this means type implements IXmlSerializable
Type? type = null;
string? typeName = xmlReader.GetAttribute(Keywords.MSD_INSTANCETYPE, Keywords.MSDNS);
- if (typeName == null || typeName.Length == 0)
+ if (string.IsNullOrEmpty(typeName))
{ // No CDT polumorphism
string? xsdTypeName = xmlReader.GetAttribute(Keywords.TYPE, Keywords.XSINS); // this xsd type: Base type polymorphism
if (null != xsdTypeName && xsdTypeName.Length > 0)
{
Debug.Assert(column != null, "Invalid (null) argument");
Debug.Assert(column.Table != null, "Invalid (loose) column");
- if (error == null || error.Length == 0)
+ if (string.IsNullOrEmpty(error))
{
// remove error from the collection
Clear(column);
DataCommonEventSource.Log.Trace("<ds.DataSet.set_DataSetName|API> {0}, '{1}'", ObjectID, value);
if (value != _dataSetName)
{
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
throw ExceptionBuilder.SetDataSetNameToEmpty();
}
{
XmlElement typeNode = dc.CreateElement(Keywords.XSD_PREFIX, Keywords.XSD_SIMPLETYPE, Keywords.XSDNS);
- if (_name != null && _name.Length != 0)
+ if (!string.IsNullOrEmpty(_name))
{
// this is a global type
typeNode.SetAttribute(Keywords.NAME, _name);
// Get Locale and CaseSensitive properties
- if (_schemaName == null || _schemaName.Length == 0)
+ if (string.IsNullOrEmpty(_schemaName))
_schemaName = "NewDataSet";
ds.Namespace = _schemaUri;
if (FEqualIdentity(node, Keywords.XDR_ELEMENT, Keywords.XDRNS) ||
FEqualIdentity(node, Keywords.XDR_ATTRIBUTE, Keywords.XDRNS))
{
- if (strType == null || strType.Length == 0)
+ if (string.IsNullOrEmpty(strType))
return null;
// Find an ELEMENTTYPE or ATTRIBUTETYPE with name=strType
Debug.Assert(FEqualIdentity(node, Keywords.XDR_ELEMENTTYPE, Keywords.XDRNS), $"Invalid node type {node.LocalName}");
string value = node.GetAttribute(Keywords.CONTENT);
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
string type = node.GetAttribute(Keywords.DT_TYPE, Keywords.DTNS);
return !string.IsNullOrEmpty(type);
}
NameType nt = FindNameType(strType);
- if (nt == s_enumerationNameType && (dtValues == null || dtValues.Length == 0))
+ if (nt == s_enumerationNameType && string.IsNullOrEmpty(dtValues))
throw ExceptionBuilder.MissingAttribute("type", Keywords.DT_VALUES);
return nt.type;
}
else
{
instanceName = node.GetAttribute(Keywords.TYPE);
- if (instanceName == null || instanceName.Length == 0)
+ if (string.IsNullOrEmpty(instanceName))
throw ExceptionBuilder.MissingAttribute("Element", Keywords.TYPE);
}
strType = typeNode.GetAttribute(Keywords.DT_TYPE, Keywords.DTNS);
strValues = typeNode.GetAttribute(Keywords.DT_VALUES, Keywords.DTNS);
- if (strType == null || strType.Length == 0)
+ if (string.IsNullOrEmpty(strType))
{
strType = string.Empty;
type = typeof(string);
column.Namespace = targetNamespace;
table.Columns.Add(column);
- if (strDefault != null && strDefault.Length != 0)
+ if (!string.IsNullOrEmpty(strDefault))
try
{
column.DefaultValue = SqlConvert.ChangeTypeForXML(strDefault, type);
internal static bool GetBooleanAttribute(XmlElement element, string attrName, string attrNS, bool defVal)
{
string value = element.GetAttribute(attrName, attrNS);
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
return defVal;
}
}
parentName = node.GetAttribute(Keywords.MSD_PARENT, Keywords.MSDNS);
- if (parentName == null || parentName.Length == 0)
+ if (string.IsNullOrEmpty(parentName))
throw ExceptionBuilder.RelationParentNameMissing(strName);
parentName = XmlConvert.DecodeName(parentName);
childName = node.GetAttribute(Keywords.MSD_CHILD, Keywords.MSDNS);
- if (childName == null || childName.Length == 0)
+ if (string.IsNullOrEmpty(childName))
throw ExceptionBuilder.RelationChildNameMissing(strName);
childName = XmlConvert.DecodeName(childName);
value = node.GetAttribute(Keywords.MSD_PARENTKEY, Keywords.MSDNS);
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
throw ExceptionBuilder.RelationTableKeyMissing(strName);
parentNames = value.TrimEnd(null).Split(new char[] { Keywords.MSD_KEYFIELDSEP, Keywords.MSD_KEYFIELDOLDSEP });
value = node.GetAttribute(Keywords.MSD_CHILDKEY, Keywords.MSDNS);
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
throw ExceptionBuilder.RelationChildKeyMissing(strName);
childNames = value.TrimEnd(null).Split(new char[] { Keywords.MSD_KEYFIELDSEP, Keywords.MSD_KEYFIELDOLDSEP });
{
_schemaName = schemaRoot.Id;
- if (_schemaName == null || _schemaName.Length == 0)
+ if (string.IsNullOrEmpty(_schemaName))
{
_schemaName = "NewDataSet";
}
internal static bool GetBooleanAttribute(XmlSchemaAnnotated element, string attrName, bool defVal)
{
string? value = GetMsdataAttribute(element, attrName);
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
return defVal;
}
internal static string GetStringAttribute(XmlSchemaAnnotated element, string attrName, string defVal)
{
string? value = GetMsdataAttribute(element, attrName);
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
return defVal;
}
if (table == null)
return;
- if (refer == null || refer.Length == 0)
+ if (string.IsNullOrEmpty(refer))
throw ExceptionBuilder.MissingRefer(name);
ConstraintTable? key = (ConstraintTable?)_constraintNodes![refer];
{
string relName = XmlConvert.DecodeName(GetStringAttribute(keyref, Keywords.MSD_RELATIONNAME, keyref.Name!));
- if (relName == null || relName.Length == 0)
+ if (string.IsNullOrEmpty(relName))
relName = name;
int iExisting = fKey[0].Table!.DataSet!.Relations.InternalIndexOf(relName);
string? name;
name = XmlConvert.DecodeName(keyNode.Name);
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
throw ExceptionBuilder.MissingAttribute(Keywords.NAME);
if (_constraintNodes!.ContainsKey(name))
if (_typeNs == Keywords.XSDNS)
return null;
XmlSchemaAnnotated? typeNode;
- if (_type == null || _type.Length == 0)
+ if (string.IsNullOrEmpty(_type))
{
_type = isAttr ? attr!.RefName.Name : el!.RefName.Name;
- if (_type == null || _type.Length == 0)
+ if (string.IsNullOrEmpty(_type))
typeNode = isAttr ? attr!.SchemaType : el!.SchemaType;
else
typeNode = isAttr ? FindTypeNode((XmlSchemaAnnotated)_attributes![attr!.RefName]!) : FindTypeNode((XmlSchemaAnnotated)_elementsTable![el!.RefName]!);
SimpleType? xsdType = null;
// if (typeNode.QualifiedName.Namespace != Keywords.XSDNS) { // this means UDSimpleType
- if (typeNode.QualifiedName.Name != null && typeNode.QualifiedName.Name.Length != 0 && typeNode.QualifiedName.Namespace != Keywords.XSDNS)
+ if (!string.IsNullOrEmpty(typeNode.QualifiedName.Name) && typeNode.QualifiedName.Namespace != Keywords.XSDNS)
{ // this means UDSimpleType
xsdType = new SimpleType(typeNode);
strType = typeNode.QualifiedName.ToString(); // use qualified name
{
XmlSchemaSimpleType node = (typeNode as XmlSchemaSimpleType)!;
xsdType = new SimpleType(node);
- if (node.QualifiedName.Name != null && node.QualifiedName.Name.Length != 0 && node.QualifiedName.Namespace != Keywords.XSDNS)
+ if (!string.IsNullOrEmpty(node.QualifiedName.Name) && node.QualifiedName.Namespace != Keywords.XSDNS)
{
// this means UDSimpleType
strType = node.QualifiedName.ToString(); // use qualified name
xsdType = new SimpleType(simpleTypeNode!);
// ((XmlSchemaSimpleType)typeNode).Name != null && ((XmlSchemaSimpleType)typeNode).Name.Length != 0 check is for annonymos simple type,
// it should be user defined Named simple type
- if (((XmlSchemaSimpleType)typeNode).Name != null && ((XmlSchemaSimpleType)typeNode).Name!.Length != 0 && ((XmlSchemaSimpleType)typeNode).QualifiedName.Namespace != Keywords.XSDNS)
+ if (!string.IsNullOrEmpty(((XmlSchemaSimpleType)typeNode).Name) && ((XmlSchemaSimpleType)typeNode).QualifiedName.Namespace != Keywords.XSDNS)
{
strType = ((XmlSchemaSimpleType)typeNode).QualifiedName.ToString(); // use qualified name
type = ParseDataType(strType);
// reuse variable
value = GetMsdataAttribute(node, Keywords.MSD_DATASETNAME);
- if (value != null && value.Length != 0)
+ if (!string.IsNullOrEmpty(value))
{
dsName = value;
}
value = GetMsdataAttribute(node, Keywords.MSD_DATASETNAMESPACE);
- if (value != null && value.Length != 0)
+ if (!string.IsNullOrEmpty(value))
{
dsNamespace = value;
}
SetExtProperties(_ds, node.UnhandledAttributes);
- if (dsName != null && dsName.Length != 0)
+ if (!string.IsNullOrEmpty(dsName))
_ds.DataSetName = XmlConvert.DecodeName(dsName);
// _ds.Namespace = node.QualifiedName.Namespace;
XmlNode type;
string? name = stNode.Name;
- if (name != null && name.Length != 0)
+ if (!string.IsNullOrEmpty(name))
{
// For remoting, always need to work with root schema's namespace
string nSpace = (_schFormat != SchemaFormat.Remoting) ? stNode.Namespace :
else
{
string typeName = XmlDataTypeName(col.DataType); // do not update the hashtable, as it will not write msdata:DataType
- if (typeName == null || typeName.Length == 0)
+ if (string.IsNullOrEmpty(typeName))
{
if (col.DataType == typeof(Guid) || col.DataType == typeof(Type))
{
// the type for this element
DataColumn col = table.Columns[0];
string _typeName = XmlDataTypeName(col.DataType);
- if (_typeName == null || _typeName.Length == 0)
+ if (string.IsNullOrEmpty(_typeName))
{
_typeName = Keywords.XSD_ANYTYPE;
}
DataColumn column = table.Columns[colNum];
string error = row.GetColumnError(column);
string columnPrefix = (column.Namespace.Length != 0) ? column.Prefix : string.Empty;
- if (error == null || error.Length == 0)
+ if (string.IsNullOrEmpty(error))
{
continue;
}
{
DataColumn column = row.Table.Columns[colNum];
string error = row.GetColumnError(column);
- if (error == null || error.Length == 0)
+ if (string.IsNullOrEmpty(error))
{
continue;
}
string prefix = (_ds != null) ? ((_ds.Namespace.Length == 0) ? "" : _ds.Prefix) : ((_dt!.Namespace.Length == 0) ? "" : _dt.Prefix);
- if (_ds == null || _ds.DataSetName == null || _ds.DataSetName.Length == 0)
+ if (_ds == null || string.IsNullOrEmpty(_ds.DataSetName))
_xmlw.WriteStartElement(prefix, Keywords.DOCUMENTELEMENT, (_dt!.Namespace == null) ? "" : _dt.Namespace);
else
_xmlw.WriteStartElement(prefix, XmlConvert.EncodeLocalName(_ds.DataSetName), _ds.Namespace);
}
else
{
- if (_ds.DataSetName == null || _ds.DataSetName.Length == 0)
+ if (string.IsNullOrEmpty(_ds.DataSetName))
_xmlw.WriteStartElement(prefix, Keywords.DOCUMENTELEMENT, _ds.Namespace);
else
_xmlw.WriteStartElement(prefix, XmlConvert.EncodeLocalName(_ds.DataSetName), _ds.Namespace);
throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(machineName), machineName));
}
- if (logName == null || logName.Length == 0)
+ if (string.IsNullOrEmpty(logName))
logName = "Application";
if (!ValidLogName(logName, false))
throw new ArgumentException(SR.BadLogName);
- if (source == null || source.Length == 0)
+ if (string.IsNullOrEmpty(source))
throw new ArgumentException(SR.Format(SR.MissingParameter, nameof(source)));
if (source.Length + EventLogKey.Length > 254)
throw new ArgumentException(SR.Format(SR.ParameterTooLong, nameof(source), 254 - EventLogKey.Length));
{
if (!SyntaxCheck.CheckMachineName(machineName))
throw new ArgumentException(SR.Format(SR.InvalidParameterFormat, nameof(machineName)), nameof(machineName));
- if (logName == null || logName.Length == 0)
+ if (string.IsNullOrEmpty(logName))
throw new ArgumentException(SR.NoLogName);
if (!ValidLogName(logName, false))
throw new InvalidOperationException(SR.BadLogName);
if (!SyntaxCheck.CheckMachineName(machineName))
throw new ArgumentException(SR.Format(SR.InvalidParameterFormat, nameof(machineName)));
- if (logName == null || logName.Length == 0)
+ if (string.IsNullOrEmpty(logName))
return false;
RegistryKey eventkey = null;
private static RegistryKey FindSourceRegistration(string source, string machineName, bool readOnly, bool wantToCreate)
{
- if (source != null && source.Length != 0)
+ if (!string.IsNullOrEmpty(source))
{
RegistryKey eventkey = null;
try
get
{
string helpLinkStr = (string)NativeWrapper.EvtGetPublisherMetadataProperty(_handle, UnsafeNativeMethods.EvtPublisherMetadataPropertyId.EvtPublisherMetadataHelpLink);
- if (helpLinkStr == null || helpLinkStr.Length == 0)
+ if (string.IsNullOrEmpty(helpLinkStr))
return null;
return new Uri(helpLinkStr);
}
_counterType = counterSample._counterType;
if (!categorySample._isMultiInstance)
{
- if (_instanceName != null && _instanceName.Length != 0)
+ if (!string.IsNullOrEmpty(_instanceName))
throw new InvalidOperationException(SR.Format(SR.InstanceNameProhibited, _instanceName));
return counterSample.GetSingleValue();
}
else
{
- if (_instanceName == null || _instanceName.Length == 0)
+ if (string.IsNullOrEmpty(_instanceName))
throw new InvalidOperationException(SR.InstanceNameRequired);
return counterSample.GetInstanceValue(_instanceName);
Hashtable h = new Hashtable();
for (int i = 0; i < counterData.Count; i++)
{
- if (counterData[i].CounterName == null || counterData[i].CounterName.Length == 0)
+ if (string.IsNullOrEmpty(counterData[i].CounterName))
{
throw new ArgumentException(SR.InvalidCounterName);
}
h.Add(counterData[i].CounterName, string.Empty);
// Ensure that all counter help strings aren't null or empty
- if (counterData[i].CounterHelp == null || counterData[i].CounterHelp.Length == 0)
+ if (string.IsNullOrEmpty(counterData[i].CounterHelp))
{
counterData[i].CounterHelp = counterData[i].CounterName;
}
{
int counterNameHashCode = GetWstrHashCode(counterName);
int instanceNameHashCode;
- if (instanceName != null && instanceName.Length != 0)
+ if (!string.IsNullOrEmpty(instanceName))
instanceNameHashCode = GetWstrHashCode(instanceName);
else
{
internal unsafe void RemoveInstance(string instanceName, PerformanceCounterInstanceLifetime instanceLifetime)
{
- if (instanceName == null || instanceName.Length == 0)
+ if (string.IsNullOrEmpty(instanceName))
return;
int instanceNameHashCode = GetWstrHashCode(instanceName);
public ADStoreKey(string domainName, byte[] sid)
{
- Debug.Assert(domainName != null && domainName.Length > 0);
+ Debug.Assert(!string.IsNullOrEmpty(domainName));
Debug.Assert(sid != null && sid.Length != 0);
// Make a copy of the SID, since a byte[] is mutable
}
// Couldn't retrieve the value
- if (version == null || version.Length == 0)
+ if (string.IsNullOrEmpty(version))
return false;
// This string should be in the form "M.N", where M and N are integers.
else if (AuthType == AuthType.Basic)
{
var tempDomainName = new StringBuilder(100);
- if (domainName != null && domainName.Length != 0)
+ if (!string.IsNullOrEmpty(domainName))
{
tempDomainName.Append(domainName);
tempDomainName.Append('\\');
if (_adsObject == null)
{
string pathToUse = Path;
- if (pathToUse == null || pathToUse.Length == 0)
+ if (string.IsNullOrEmpty(pathToUse))
{
// get the default naming context. This should be the default root for the search.
DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE", true, null, null, AuthenticationTypes.Secure);
get => _filter;
set
{
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
value = defaultFilter;
_filter = value;
}
_changeList = ArrayList.Synchronized(tempList);
_allowMultipleChange = entry.allowMultipleChange;
string tempPath = entry.Path;
- if (tempPath == null || tempPath.Length == 0)
+ if (string.IsNullOrEmpty(tempPath))
{
// user does not specify path, so we bind to default naming context using LDAP provider.
_needNewBehavior = true;
private int[] ConvertWin32GroupString(string win32Str)
{
// None of these cases make any sense
- if (win32Str == null || win32Str.Length == 0)
+ if (string.IsNullOrEmpty(win32Str))
{
return (new int[] { 3 });
}
<data name="ZLibErrorUnexpected" xml:space="preserve">
<value>The underlying compression routine returned an unexpected error code.</value>
</data>
- <data name="CannotBeEmpty" xml:space="preserve">
- <value>String cannot be empty.</value>
- </data>
<data name="CDCorrupt" xml:space="preserve">
<value>Central Directory corrupt.</value>
</data>
private ZipArchiveEntry DoCreateEntry(string entryName, CompressionLevel? compressionLevel)
{
- ArgumentNullException.ThrowIfNull(entryName);
-
- if (string.IsNullOrEmpty(entryName))
- throw new ArgumentException(SR.CannotBeEmpty, nameof(entryName));
+ ArgumentException.ThrowIfNullOrEmpty(entryName);
if (_mode == ZipArchiveMode.Read)
throw new NotSupportedException(SR.CreateInReadMode);
PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
HandleInheritability inheritability)
{
- Debug.Assert(pipeName != null && pipeName.Length != 0, "fullPipeName is null or empty");
+ Debug.Assert(!string.IsNullOrEmpty(pipeName), "fullPipeName is null or empty");
Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
Debug.Assert(inBufferSize >= 0, "inBufferSize is negative");
Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");
PipeTransmissionMode transmissionMode, PipeOptions options, int inBufferSize, int outBufferSize,
PipeSecurity? pipeSecurity, HandleInheritability inheritability, PipeAccessRights additionalAccessRights)
{
- Debug.Assert(pipeName != null && pipeName.Length != 0, "fullPipeName is null or empty");
+ Debug.Assert(!string.IsNullOrEmpty(pipeName), "fullPipeName is null or empty");
Debug.Assert(direction >= PipeDirection.In && direction <= PipeDirection.InOut, "invalid pipe direction");
Debug.Assert(inBufferSize >= 0, "inBufferSize is negative");
Debug.Assert(outBufferSize >= 0, "outBufferSize is negative");
cmp.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(propValue)));
}
cc.Members.Add(cmp);
- if (Comment != null && Comment.Length != 0)
+ if (!string.IsNullOrEmpty(Comment))
{
cmp.Comments.Add(new CodeCommentStatement(Comment));
}
new CodeSnippetExpression("value")));
cc.Members.Add(cmp);
- if (Comment != null && Comment.Length != 0)
+ if (!string.IsNullOrEmpty(Comment))
{
cmp.Comments.Add(new CodeCommentStatement(Comment));
}
}
cc.Members.Add(cf);
- if (Comment != null && Comment.Length != 0)
+ if (!string.IsNullOrEmpty(Comment))
{
cf.Comments.Add(new CodeCommentStatement(Comment));
}
{
Cookie cookie = _cookies[index];
string cookieString = cookie.ToServerString();
- if (cookieString == null || cookieString.Length == 0)
+ if (string.IsNullOrEmpty(cookieString))
{
continue;
}
internal void FinishInitialization()
{
string host = UserHostName;
- if (_version > HttpVersion.Version10 && (host == null || host.Length == 0))
+ if (_version > HttpVersion.Version10 && string.IsNullOrEmpty(host))
{
_context.ErrorMessage = "Invalid host name";
return;
else
path = _rawUrl;
- if ((host == null || host.Length == 0))
+ if (string.IsNullOrEmpty(host))
host = UserHostAddress;
if (raw_uri != null)
internal void SetContentTypeName(bool allowUnicode)
{
- if (!allowUnicode && _name != null && _name.Length != 0 && !MimeBasePart.IsAscii(_name, false))
+ if (!allowUnicode && !string.IsNullOrEmpty(_name) && !MimeBasePart.IsAscii(_name, false))
{
Encoding encoding = NameEncoding ?? Encoding.GetEncoding(MimeBasePart.DefaultCharSet);
MimePart.ContentType.Name = MimeBasePart.EncodeHeaderValue(_name, encoding, MimeBasePart.ShouldUseBase64Encoding(encoding));
private void CheckHostAndPort()
{
- if (_host == null || _host.Length == 0)
+ if (string.IsNullOrEmpty(_host))
{
throw new InvalidOperationException(SR.UnspecifiedHost);
}
int offset = 0;
_mediaType = MailBnfHelper.ReadToken(_type, ref offset);
- if (_mediaType == null || _mediaType.Length == 0 || offset >= _type.Length || _type[offset++] != '/')
+ if (string.IsNullOrEmpty(_mediaType) || offset >= _type.Length || _type[offset++] != '/')
{
throw new FormatException(SR.ContentTypeInvalid);
}
_subType = MailBnfHelper.ReadToken(_type, ref offset);
- if (_subType == null || _subType.Length == 0)
+ if (string.IsNullOrEmpty(_subType))
{
throw new FormatException(SR.ContentTypeInvalid);
}
string? paramAttribute = MailBnfHelper.ReadParameterAttribute(_type, ref offset);
- if (paramAttribute == null || paramAttribute.Length == 0)
+ if (string.IsNullOrEmpty(paramAttribute))
{
throw new FormatException(SR.ContentTypeInvalid);
}
// DNS.resolve may return short names even for other inet domains ;-(
// We _don't_ know what the exact domain is, so try also grab short hostname cookies.
// Grab long name from the local domain
- if (m_fqdnMyDomain != null && m_fqdnMyDomain.Length != 0)
+ if (!string.IsNullOrEmpty(m_fqdnMyDomain))
{
domainAttributeMatchAnyCookieVariant.Add(fqdnRemote + m_fqdnMyDomain);
// Grab the local domain itself
<data name="net_ftp_active_address_different" xml:space="preserve">
<value>The data connection was made from an address that is different than the address to which the FTP connection was made.</value>
</data>
- <data name="net_ftp_invalid_method_name" xml:space="preserve">
- <value>FTP Method names cannot be null or empty.</value>
- </data>
- <data name="net_ftp_invalid_renameto" xml:space="preserve">
- <value>The RenameTo filename cannot be null or empty.</value>
- </data>
<data name="net_ftp_invalid_response_filename" xml:space="preserve">
<value>The server returned the filename ({0}) which is not valid.</value>
</data>
get { return _method; }
set
{
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentException(SR.net_badmethod, nameof(value));
- }
+ ArgumentException.ThrowIfNullOrEmpty(value);
_method = value;
}
}
}
set
{
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentException(SR.net_ftp_invalid_method_name, nameof(value));
- }
+ ArgumentException.ThrowIfNullOrEmpty(value);
+
if (InUse)
{
throw new InvalidOperationException(SR.net_reqsubmitted);
throw new InvalidOperationException(SR.net_reqsubmitted);
}
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentException(SR.net_ftp_invalid_renameto, nameof(value));
- }
+ ArgumentException.ThrowIfNullOrEmpty(value);
_renameTo = value;
}
NetworkCredential? networkCredential = null;
_uri = uri;
_methodInfo = FtpMethodInfo.GetMethodInfo(WebRequestMethods.Ftp.DownloadFile);
- if (_uri.UserInfo != null && _uri.UserInfo.Length != 0)
+ if (!string.IsNullOrEmpty(_uri.UserInfo))
{
string userInfo = _uri.UserInfo;
string username = userInfo;
}
set
{
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentException(SR.net_badmethod, nameof(value));
- }
+ ArgumentException.ThrowIfNullOrEmpty(value);
if (HttpValidationHelpers.IsInvalidMethodOrHeaderString(value))
{
{
WebRequest request = WebRequest.Create("file://anything");
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => request.ContentLength = -1);
- AssertExtensions.Throws<ArgumentException>("value", () => request.Method = null);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => request.Method = null);
AssertExtensions.Throws<ArgumentException>("value", () => request.Method = "");
AssertExtensions.Throws<ArgumentOutOfRangeException>("value", () => request.Timeout = -2);
}
public void Method_SetInvalidString_ThrowsArgumentException(Uri remoteServer)
{
HttpWebRequest request = WebRequest.CreateHttp(remoteServer);
- AssertExtensions.Throws<ArgumentException>("value", () => request.Method = null);
+ AssertExtensions.Throws<ArgumentNullException>("value", () => request.Method = null);
AssertExtensions.Throws<ArgumentException>("value", () => request.Method = string.Empty);
AssertExtensions.Throws<ArgumentException>("value", () => request.Method = "Method(2");
}
/// <returns>A string representation of value of the current DateOnly object as specified by format and provider.</returns>
public string ToString([StringSyntax(StringSyntaxAttribute.DateOnlyFormat)] string? format, IFormatProvider? provider)
{
- if (format == null || format.Length == 0)
+ if (string.IsNullOrEmpty(format))
{
format = "d";
}
Type enclosingType = nestings[i];
string name = enclosingType.Name;
- if (i == nestings.Count - 1 && enclosingType.Namespace != null && enclosingType.Namespace.Length != 0)
+ if (i == nestings.Count - 1 && !string.IsNullOrEmpty(enclosingType.Namespace))
name = enclosingType.Namespace + "." + name;
AddName(name);
private static Assembly ValidateAssemblyNameWithSimpleName(Assembly assembly, string? requestedSimpleName)
{
- if (string.IsNullOrEmpty(requestedSimpleName))
- {
- throw new ArgumentException(SR.ArgumentNull_AssemblyNameName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(requestedSimpleName, "AssemblyName.Name");
// Get the name of the loaded assembly
string? loadedSimpleName = null;
/// <remarks>The accepted standard formats are 'r', 'R', 'o', 'O', 't' and 'T'. </remarks>
public string ToString([StringSyntax(StringSyntaxAttribute.TimeOnlyFormat)] string? format, IFormatProvider? provider)
{
- if (format == null || format.Length == 0)
+ if (string.IsNullOrEmpty(format))
{
format = "t";
}
DataMemberAttribute memberAttribute = (DataMemberAttribute)memberAttributes[0];
if (memberAttribute.IsNameSetExplicitly)
{
- if (memberAttribute.Name == null || memberAttribute.Name.Length == 0)
+ if (string.IsNullOrEmpty(memberAttribute.Name))
ThrowInvalidDataContractException(SR.Format(SR.InvalidDataMemberName, member.Name, DataContract.GetClrTypeFullName(type)));
memberContract.Name = memberAttribute.Name;
}
{
if (collectionContractAttribute.IsItemNameSetExplicitly)
{
- if (collectionContractAttribute.ItemName == null || collectionContractAttribute.ItemName.Length == 0)
+ if (string.IsNullOrEmpty(collectionContractAttribute.ItemName))
throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractItemName, DataContract.GetClrTypeFullName(UnderlyingType)));
itemName = DataContract.EncodeLocalName(collectionContractAttribute.ItemName);
_itemNameSetExplicit = true;
}
if (collectionContractAttribute.IsKeyNameSetExplicitly)
{
- if (collectionContractAttribute.KeyName == null || collectionContractAttribute.KeyName.Length == 0)
+ if (string.IsNullOrEmpty(collectionContractAttribute.KeyName))
throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractKeyName, DataContract.GetClrTypeFullName(UnderlyingType)));
if (!isDictionary)
throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractKeyNoDictionary, DataContract.GetClrTypeFullName(UnderlyingType), collectionContractAttribute.KeyName));
}
if (collectionContractAttribute.IsValueNameSetExplicitly)
{
- if (collectionContractAttribute.ValueName == null || collectionContractAttribute.ValueName.Length == 0)
+ if (string.IsNullOrEmpty(collectionContractAttribute.ValueName))
throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractValueName, DataContract.GetClrTypeFullName(UnderlyingType)));
if (!isDictionary)
throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractValueNoDictionary, DataContract.GetClrTypeFullName(UnderlyingType), collectionContractAttribute.ValueName));
if (dataContractAttribute.IsNameSetExplicitly)
{
name = dataContractAttribute.Name;
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
throw new InvalidDataContractException(SR.Format(SR.InvalidDataContractName, DataContract.GetClrTypeFullName(type)));
if (type.IsGenericType && !type.IsGenericTypeDefinition)
name = ExpandGenericParameters(name, type);
if (collectionContractAttribute.IsNameSetExplicitly)
{
name = collectionContractAttribute.Name;
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
throw new InvalidDataContractException(SR.Format(SR.InvalidCollectionContractName, DataContract.GetClrTypeFullName(type)));
if (type.IsGenericType && !type.IsGenericTypeDefinition)
name = ExpandGenericParameters(name, type);
DataMember memberContract = new DataMember(field);
if (memberAttribute.IsValueSetExplicitly)
{
- if (memberAttribute.Value == null || memberAttribute.Value.Length == 0)
+ if (string.IsNullOrEmpty(memberAttribute.Value))
ThrowInvalidDataContractException(SR.Format(SR.InvalidEnumMemberValue, field.Name, DataContract.GetClrTypeFullName(type)));
memberContract.Name = memberAttribute.Value;
}
{
string value = reader.ReadContentAsString();
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
throw new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, "UInt64")));
}
string value = reader.ReadElementContentAsString();
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
{
throw new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, "UInt64")));
}
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.XmlResolver = null;
InvokeSchemaProviderMethod(type, schemas, out xmlName, out xsdType, out hasRoot);
- if (xmlName.Name == null || xmlName.Name.Length == 0)
+ if (string.IsNullOrEmpty(xmlName.Name))
throw new InvalidDataContractException(SR.Format(SR.InvalidXmlDataContractName, DataContract.GetClrTypeFullName(type)));
}
hasRoot = false;
}
string? methodName = provider.MethodName;
- if (methodName == null || methodName.Length == 0)
+ if (string.IsNullOrEmpty(methodName))
{
if (!provider.IsAny)
throw new InvalidDataContractException(SR.Format(SR.InvalidGetSchemaMethod, DataContract.GetClrTypeFullName(clrType)));
{
string? typeName = providerXsdType.Name;
string? typeNs = null;
- if (typeName == null || typeName.Length == 0)
+ if (string.IsNullOrEmpty(typeName))
{
DataContract.GetDefaultXmlName(DataContract.GetClrTypeFullName(clrType), out typeName, out typeNs);
xmlName = new XmlQualifiedName(typeName, typeNs);
}
else
{
- if (schema.Id == null || schema.Id.Length == 0)
+ if (string.IsNullOrEmpty(schema.Id))
throw new InvalidDataContractException(SR.Format(SR.InvalidReturnSchemaOnGetSchemaMethod, DataContract.GetClrTypeFullName(clrType)));
AddDefaultTypedDatasetType(schemas, schema, xmlName.Name, xmlName.Namespace);
}
{
internal static bool NamespacesEqual(string? ns1, string? ns2)
{
- if (ns1 == null || ns1.Length == 0)
- return (ns2 == null || ns2.Length == 0);
+ if (string.IsNullOrEmpty(ns1))
+ return string.IsNullOrEmpty(ns2);
else
return ns1 == ns2;
}
public string SetNamespace(string ns)
{
string? prefix = _namespaces.LookupPrefix(ns);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
prefix = "xg" + (_nextPrefix++).ToString(NumberFormatInfo.InvariantInfo);
Namespaces.AddNamespace(prefix, ns);
XmlRootAttribute xmlRootAttribute = (XmlRootAttribute)xmlRootAttributes[0];
_isTopLevelElementNullable = xmlRootAttribute.IsNullable;
string elementName = xmlRootAttribute.ElementName;
- _topLevelElementName = (elementName == null || elementName.Length == 0) ? Name : dictionary.Add(DataContract.EncodeLocalName(elementName));
+ _topLevelElementName = string.IsNullOrEmpty(elementName) ? Name : dictionary.Add(DataContract.EncodeLocalName(elementName));
string? elementNs = xmlRootAttribute.Namespace;
- _topLevelElementNamespace = (elementNs == null || elementNs.Length == 0) ? DictionaryGlobals.EmptyString : dictionary.Add(elementNs);
+ _topLevelElementNamespace = string.IsNullOrEmpty(elementNs) ? DictionaryGlobals.EmptyString : dictionary.Add(elementNs);
}
else
{
private XmlAttribute AddNamespaceDeclaration(string? prefix, string? ns)
{
- XmlAttribute attribute = (prefix == null || prefix.Length == 0) ?
+ XmlAttribute attribute = string.IsNullOrEmpty(prefix) ?
Document.CreateAttribute(null, Globals.XmlnsPrefix, Globals.XmlnsNamespace) :
Document.CreateAttribute(Globals.XmlnsPrefix, prefix, Globals.XmlnsNamespace);
attribute.Value = ns;
string str = reader.ReadElementContentAsString();
- if (str == null || str.Length == 0)
+ if (string.IsNullOrEmpty(str))
ThrowConversionException(string.Empty, "UInt64");
return XmlConverter.ToUInt64(str);
{
string str = reader.ReadContentAsString();
- if (str == null || str.Length == 0)
+ if (string.IsNullOrEmpty(str))
ThrowConversionException(string.Empty, "UInt64");
return XmlConverter.ToUInt64(str);
{
string name;
string? ns;
- if (str == null || str.Length == 0)
+ if (string.IsNullOrEmpty(str))
name = ns = string.Empty;
else
XmlObjectSerializerReadContext.ParseQualifiedName(str, this, out name, out ns, out _);
_captureXText = null;
}
- if (_captureText == null || _captureText.Length == 0)
+ if (string.IsNullOrEmpty(_captureText))
{
_captureText = s;
}
{
Assert.Throws<ArgumentNullException>(() => XName.Get(null));
Assert.Throws<ArgumentNullException>(() => XName.Get(null, "foo"));
- Assert.Throws<ArgumentNullException>(() => XName.Get(string.Empty, "foo"));
+ Assert.Throws<ArgumentException>(() => XName.Get(string.Empty, "foo"));
AssertExtensions.Throws<ArgumentException>("expandedName", () => XName.Get(string.Empty));
AssertExtensions.Throws<ArgumentException>(null, () => XName.Get("{}"));
AssertExtensions.Throws<ArgumentException>(null, () => XName.Get("{foo}"));
public void XPIEmptyStringShouldNotBeAllowed()
{
var pi = new XProcessingInstruction("PI", "data");
- Assert.Throws<ArgumentNullException>(() => pi.Target = string.Empty);
+ Assert.Throws<ArgumentException>(() => pi.Target = string.Empty);
}
[Fact]
switch (type)
{
case GetNameType.FromString:
- return (ns == null || ns.Length == 0) ? name : "{" + ns + "}" + name;
+ return string.IsNullOrEmpty(ns) ? name : "{" + ns + "}" + name;
case GetNameType.TwoParamGet:
return XName.Get(name, ns);
case GetNameType.ExpandedName:
- return (ns == null || ns.Length == 0) ? XName.Get(name) : XName.Get("{" + ns + "}" + name);
+ return string.IsNullOrEmpty(ns) ? XName.Get(name) : XName.Get("{" + ns + "}" + name);
case GetNameType.XNamespacePlusOperator:
- return (ns == null || ns.Length == 0) ? XName.Get(name) : XNamespace.Get(ns) + name;
+ return string.IsNullOrEmpty(ns) ? XName.Get(name) : XNamespace.Get(ns) + name;
default:
TestLog.Compare(false, "Test failed: Invalid XName creation method specified");
break;
// For the HTML element, it should call this method with ns and prefix as String.Empty
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
_elementScope.Push((byte)_currentElementProperties);
//
public override void WriteStartAttribute(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
if (ns.Length == 0)
{
// HTML PI's use ">" to terminate rather than "?>".
public override void WriteProcessingInstruction(string target, string? text)
{
- Debug.Assert(target != null && target.Length != 0 && text != null);
+ Debug.Assert(!string.IsNullOrEmpty(target) && text != null);
if (_trackTextContent && _inTextContent) { ChangeTextContentMark(false); }
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
if (_trackTextContent && _inTextContent) { ChangeTextContentMark(false); }
internal override void WriteEndElement(string? prefix, string localName, string? ns)
{
bool isBlockWs;
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
_indentLevel--;
// For the HTML element, it should call this method with ns and prefix as String.Empty
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
_elementScope.Push((byte)_currentElementProperties);
//
public override void WriteStartAttribute(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
if (ns.Length == 0)
{
// HTML PI's use ">" to terminate rather than "?>".
public override void WriteProcessingInstruction(string target, string? text)
{
- Debug.Assert(target != null && target.Length != 0 && text != null);<#
+ Debug.Assert(!string.IsNullOrEmpty(target) && text != null);<#
#><#= SetTextContentMark(3, false) #>
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);<#
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);<#
#><#= SetTextContentMark(3, false) #>
internal override void WriteEndElement(string? prefix, string localName, string? ns)
{
bool isBlockWs;
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
_indentLevel--;
// For the HTML element, it should call this method with ns and prefix as String.Empty
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
_elementScope.Push((byte)_currentElementProperties);
//
public override void WriteStartAttribute(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
if (ns.Length == 0)
{
// HTML PI's use ">" to terminate rather than "?>".
public override void WriteProcessingInstruction(string target, string? text)
{
- Debug.Assert(target != null && target.Length != 0 && text != null);
+ Debug.Assert(!string.IsNullOrEmpty(target) && text != null);
_bufBytes[base._bufPos++] = (byte)'<';
_bufBytes[base._bufPos++] = (byte)'?';
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
base._elementScope.Push((byte)base._currentElementProperties);
internal override void WriteEndElement(string? prefix, string localName, string? ns)
{
bool isBlockWs;
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
_indentLevel--;
{
if (_checkNames)
{
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
ValidateNCName(localName);
{
if (_checkNames)
{
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
ValidateNCName(localName);
{
if (_checkNames)
{
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
XmlConvert.VerifyNMTOKEN(name);
}
{
if (_checkNames)
{
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
ValidateNCName(localName);
{
if (_checkNames)
{
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
ValidateNCName(localName);
{
if (_checkNames)
{
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
XmlConvert.VerifyNMTOKEN(name);
}
return writer.WriteNmTokenAsync(name);
if (_trackTextContent && _inTextContent) { ChangeTextContentMark(false); }
_bufChars[_bufPos++] = (char)'<';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
_bufChars[_bufPos++] = (char)':';
_bufChars[_bufPos++] = (char)'<';
_bufChars[_bufPos++] = (char)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
_bufChars[_bufPos++] = (char)':';
_bufChars[_bufPos++] = (char)'<';
_bufChars[_bufPos++] = (char)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
_bufChars[_bufPos++] = (char)':';
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Add indentation
if (!_mixedContent && base._textPos != base._bufPos)
Task task;
_bufChars[_bufPos++] = (char)'<';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
task = RawTextAsync(prefix, ":", localName);
}
_bufChars[_bufPos++] = (char)'<';
_bufChars[_bufPos++] = (char)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return RawTextAsync(prefix, ":", localName, ">");
}
_bufChars[_bufPos++] = (char)'<';
_bufChars[_bufPos++] = (char)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return RawTextAsync(prefix, ":", localName, ">");
}
public override async Task WriteStartElementAsync(string? prefix, string localName, string? ns)
{
CheckAsyncCall();
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Add indentation
if (!_mixedContent && base._textPos != base._bufPos)
#><#= SetTextContentMark(3, false) #>
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)':';
public override void WriteStartElement(string prefix, string localName, string ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Add indentation
if (!_mixedContent && base._textPos != base._bufPos)
Task task;
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
task = RawTextAsync(prefix, ":", localName);
}
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return RawTextAsync(prefix, ":", localName, ">");
}
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return RawTextAsync(prefix, ":", localName, ">");
}
public override async Task WriteStartElementAsync(string prefix, string localName, string ns)
{
CheckAsyncCall();
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Add indentation
if (!_mixedContent && base._textPos != base._bufPos)
ConvertAbsoluteUnixPathToAbsoluteUri(ref url, resolver: null);
_namespaceManager = new XmlNamespaceManager(nt);
- if (url == null || url.Length == 0)
+ if (string.IsNullOrEmpty(url))
{
InitStreamInput(input, null);
}
: this((context != null && context.NameTable != null) ? context.NameTable : new NameTable())
{
Encoding? enc = context?.Encoding;
- if (context == null || context.BaseURI == null || context.BaseURI.Length == 0)
+ if (context == null || string.IsNullOrEmpty(context.BaseURI))
{
InitStreamInput(xmlFragment, enc);
}
if (ns == null)
{
// use defined prefix
- if (prefix != null && prefix.Length != 0 && (LookupNamespace(prefix) == -1))
+ if (!string.IsNullOrEmpty(prefix) && (LookupNamespace(prefix) == -1))
{
throw new ArgumentException(SR.Xml_UndefPrefix);
}
}
}
_stack[_top].prefix = null;
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
_stack[_top].prefix = prefix;
_textWriter.Write(prefix);
}
else
{
- if ((ns != null && ns.Length != 0) || (prefix != null && prefix.Length != 0))
+ if (!string.IsNullOrEmpty(ns) || !string.IsNullOrEmpty(prefix))
{
throw new ArgumentException(SR.Xml_NoNamespaces);
}
throw new ArgumentException(SR.Xml_XmlnsBelongsToReservedNs);
}
- if (localName == null || localName.Length == 0)
+ if (string.IsNullOrEmpty(localName))
{
localName = prefix;
prefix = null;
}
}
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
_textWriter.Write(prefix);
_textWriter.Write(':');
}
else
{
- if ((ns != null && ns.Length != 0) || (prefix != null && prefix.Length != 0))
+ if (!string.IsNullOrEmpty(ns) || !string.IsNullOrEmpty(prefix))
{
throw new ArgumentException(SR.Xml_NoNamespaces);
}
AutoComplete(Token.Content);
if (_namespaces)
{
- if (ns != null && ns.Length != 0 && ns != _stack[_top].defaultNs)
+ if (!string.IsNullOrEmpty(ns) && ns != _stack[_top].defaultNs)
{
string? prefix = FindPrefix(ns);
if (prefix == null)
}
}
}
- else if (ns != null && ns.Length != 0)
+ else if (!string.IsNullOrEmpty(ns))
{
throw new ArgumentException(SR.Xml_NoNamespaces);
}
// Returns the closest prefix defined in the current namespace scope for the specified namespace URI.
public override string? LookupPrefix(string ns)
{
- if (ns == null || ns.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(ns);
string? s = FindPrefix(ns);
if (s == null && ns == _stack[_top].defaultNs)
{
AutoComplete(Token.Content);
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
if (!ValidateNames.IsNmtokenNoNamespaces(name))
{
throw new ArgumentException(SR.Format(SR.Xml_InvalidNameChars, name));
// all valid name characters at that position. This can't be changed because of backwards compatibility.
private void ValidateName(string name, bool isNCName)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
int nameLength = name.Length;
Debug.Assert(prefix != null);
_bufBytes[_bufPos++] = (byte)'<';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
_bufBytes[_bufPos++] = (byte)':';
_bufBytes[_bufPos++] = (byte)'<';
_bufBytes[_bufPos++] = (byte)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
_bufBytes[_bufPos++] = (byte)':';
_bufBytes[_bufPos++] = (byte)'<';
_bufBytes[_bufPos++] = (byte)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
RawText(prefix);
_bufBytes[_bufPos++] = (byte)':';
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Add indentation
if (!_mixedContent && base._textPos != base._bufPos)
Task task;
_bufBytes[_bufPos++] = (byte)'<';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
task = RawTextAsync(prefix, ":", localName);
}
_bufBytes[_bufPos++] = (byte)'<';
_bufBytes[_bufPos++] = (byte)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return RawTextAsync(prefix, ":", localName, ">");
}
_bufBytes[_bufPos++] = (byte)'<';
_bufBytes[_bufPos++] = (byte)'/';
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return RawTextAsync(prefix, ":", localName, ">");
}
public override async Task WriteStartElementAsync(string? prefix, string localName, string? ns)
{
CheckAsyncCall();
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Add indentation
if (!_mixedContent && base._textPos != base._bufPos)
Debug.Assert(_parserContext != null);
Debug.Assert(_coreReaderImpl.DtdInfo == null);
- if (_parserContext.DocTypeName == null || _parserContext.DocTypeName.Length == 0)
+ if (string.IsNullOrEmpty(_parserContext.DocTypeName))
{
return;
}
Debug.Assert(_parserContext != null);
Debug.Assert(_coreReaderImpl.DtdInfo == null);
- if (_parserContext.DocTypeName == null || _parserContext.DocTypeName.Length == 0)
+ if (string.IsNullOrEmpty(_parserContext.DocTypeName))
{
return;
}
{
try
{
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
XmlConvert.VerifyQName(name, ExceptionType.XmlException);
if (_conformanceLevel == ConformanceLevel.Fragment)
try
{
// check local name
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
CheckNCName(localName);
AdvanceState(Token.StartElement);
try
{
// check local name
- if (localName == null || localName.Length == 0)
+ if (string.IsNullOrEmpty(localName))
{
if (prefix == "xmlns")
{
else if (namespaceName.Length > 0)
{
prefix = LookupPrefix(namespaceName);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
prefix = GeneratePrefix();
}
try
{
// check name
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
CheckNCName(name);
// check text
try
{
// check name
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
CheckNCName(name);
AdvanceState(Token.Text);
{
try
{
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
CheckNCName(localName);
AdvanceState(Token.Text);
string? prefix = string.Empty;
- if (ns != null && ns.Length != 0)
+ if (!string.IsNullOrEmpty(ns))
{
prefix = LookupPrefix(ns);
if (prefix == null)
{
try
{
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
XmlConvert.VerifyQName(name, ExceptionType.XmlException);
try
{
// check local name
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
CheckNCName(localName);
Task task = AdvanceStateAsync(Token.StartElement);
try
{
// check local name
- if (localName == null || localName.Length == 0)
+ if (string.IsNullOrEmpty(localName))
{
if (prefix == "xmlns")
{
else if (namespaceName.Length > 0)
{
prefix = LookupPrefix(namespaceName);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
prefix = GeneratePrefix();
}
try
{
// check name
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
CheckNCName(name);
// check text
try
{
// check name
- if (name == null || name.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
-
+ ArgumentException.ThrowIfNullOrEmpty(name);
CheckNCName(name);
await AdvanceStateAsync(Token.Text).ConfigureAwait(false);
{
try
{
- if (localName == null || localName.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(localName);
CheckNCName(localName);
await AdvanceStateAsync(Token.Text).ConfigureAwait(false);
string? prefix = string.Empty;
- if (ns != null && ns.Length != 0)
+ if (!string.IsNullOrEmpty(ns))
{
prefix = LookupPrefix(ns);
if (prefix == null)
// (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).
public virtual void WriteNmToken(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
WriteString(XmlConvert.VerifyNMTOKEN(name, ExceptionType.ArgumentException));
}
// (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).
public virtual Task WriteNmTokenAsync(string name)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
return WriteStringAsync(XmlConvert.VerifyNMTOKEN(name, ExceptionType.ArgumentException));
}
{
Debug.Assert(_cachedNode != null);
string? prefix = _validator.GetDefaultAttributePrefix(_cachedNode.Namespace);
- if (prefix != null && prefix.Length != 0)
+ if (!string.IsNullOrEmpty(prefix))
{
return $"{prefix}:{_cachedNode.LocalName}";
}
{
int i = 0;
string? strTemp = _doc.Version;
- if (strTemp != null && strTemp.Length != 0)
+ if (!string.IsNullOrEmpty(strTemp))
{
decNodeAttributes[i].name = strVersion;
decNodeAttributes[i].value = strTemp;
i++;
}
strTemp = _doc.Encoding;
- if (strTemp != null && strTemp.Length != 0)
+ if (!string.IsNullOrEmpty(strTemp))
{
decNodeAttributes[i].name = strEncoding;
decNodeAttributes[i].value = strTemp;
i++;
}
strTemp = _doc.Standalone;
- if (strTemp != null && strTemp.Length != 0)
+ if (!string.IsNullOrEmpty(strTemp))
{
decNodeAttributes[i].name = strStandalone;
decNodeAttributes[i].value = strTemp;
protected internal XmlProcessingInstruction(string target, string? data, XmlDocument doc) : base(doc)
{
- ArgumentNullException.ThrowIfNull(target);
-
- if (target.Length == 0)
- {
- throw new ArgumentException(SR.Xml_EmptyName, nameof(target));
- }
+ ArgumentException.ThrowIfNullOrEmpty(target);
_target = target;
_data = data ?? string.Empty;
Exception? exception;
typedValue = null;
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
Exception? exception;
typedValue = null;
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
typedValue = null;
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
typedValue = null;
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
typedValue = null;
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
public override object ParseValue(string s, XmlNameTable? nameTable, IXmlNamespaceResolver? nsmgr)
{
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
throw new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
break;
case XmlTypeCode.Language:
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return new XmlSchemaException(SR.Sch_EmptyAttributeValue, string.Empty);
}
SendValidationEvent(SR.Sch_MismatchTargetNamespaceEx, targetNamespace, _rootSchema.TargetNamespace, _rootSchema);
}
}
- else if (targetNamespace != null && targetNamespace.Length != 0)
+ else if (!string.IsNullOrEmpty(targetNamespace))
{ //if schema.TargetNamespace == null & targetNamespace != null, we will force the schema components into targetNamespace
_rootSchema = GetChameleonSchema(targetNamespace, _rootSchema); //Chameleon include at top-level
}
SendValidationEvent(SR.Sch_MismatchTargetNamespaceInclude, externalSchema.TargetNamespace, schema.TargetNamespace, include);
}
}
- else if (targetNamespace != null && targetNamespace.Length != 0)
+ else if (!string.IsNullOrEmpty(targetNamespace))
{ //Chameleon redefine
externalSchema = GetChameleonSchema(targetNamespace, externalSchema);
include.Schema = externalSchema; //Reset the schema property to the cloned schema
private void ValidateNameAttribute(XmlSchemaObject xso)
{
string? name = xso.NameAttribute;
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
{
SendValidationEvent(SR.Sch_InvalidNameAttributeEx, null, SR.Sch_NullValue, xso);
}
private void ValidateNameAttribute(XmlSchemaObject xso)
{
string? name = xso.NameAttribute;
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
{
SendValidationEvent(SR.Sch_InvalidNameAttributeEx, null, SR.Sch_NullValue, xso);
}
{
ns = new XmlSerializerNamespaces();
ns.Add("xs", XmlSchema.Namespace);
- if (_targetNs != null && _targetNs.Length != 0)
+ if (!string.IsNullOrEmpty(_targetNs))
{
ns.Add("tns", _targetNs);
}
{
get
{
- if (_ns == null || _ns.Length == 0)
+ if (string.IsNullOrEmpty(_ns))
{
return "##any";
}
/// </summary>
public XmlSchema? Add(string? ns, [StringSyntax(StringSyntaxAttribute.Uri)] string uri)
{
- if (uri == null || uri.Length == 0)
+ if (string.IsNullOrEmpty(uri))
throw new ArgumentNullException(nameof(uri));
XmlTextReader reader = new XmlTextReader(uri, _nameTable);
reader.XmlResolver = _xmlResolver;
/// </summary>
public XmlSchema? Add(string? targetNamespace, string schemaUri)
{
- if (schemaUri == null || schemaUri.Length == 0)
+ if (string.IsNullOrEmpty(schemaUri))
{
throw new ArgumentNullException(nameof(schemaUri));
}
if (attributeNS.Length > 0)
{
defaultPrefix = GetDefaultAttributePrefix(attributeNS);
- if (defaultPrefix == null || defaultPrefix.Length == 0)
+ if (string.IsNullOrEmpty(defaultPrefix))
{
SendValidationEvent(SR.Sch_DefaultAttributeNotApplied, new string[2] { attdef.Name.ToString(), QNameString(_context.LocalName!, _context.Namespace!) });
continue;
private static void EscapeKeywords(string identifier, StringBuilder sb)
{
- if (identifier == null || identifier.Length == 0)
+ if (string.IsNullOrEmpty(identifier))
return;
int arrayCount = 0;
while (identifier.EndsWith("[]", StringComparison.Ordinal))
[return: NotNullIfNotNull(nameof(identifier))]
private static string? EscapeKeywords(string? identifier)
{
- if (identifier == null || identifier.Length == 0) return identifier;
+ if (string.IsNullOrEmpty(identifier)) return identifier;
string originalIdentifier = identifier;
string[] names = identifier.Split(s_identifierSeparators);
StringBuilder sb = new StringBuilder();
[return: NotNullIfNotNull(nameof(name))]
internal static string? EscapeName(string? name)
{
- if (name == null || name.Length == 0) return name;
+ if (string.IsNullOrEmpty(name)) return name;
return XmlConvert.EncodeLocalName(name);
}
[return: NotNullIfNotNull(nameof(name))]
internal static string? EscapeQName(string? name)
{
- if (name == null || name.Length == 0) return name;
+ if (string.IsNullOrEmpty(name)) return name;
int colon = name.LastIndexOf(':');
if (colon < 0)
return XmlConvert.EncodeLocalName(name);
[MemberNotNullWhen(false, nameof(_typeName))]
internal bool IsAnonymousType
{
- get { return _typeName == null || _typeName.Length == 0; }
+ get { return string.IsNullOrEmpty(_typeName); }
}
internal virtual string DefaultElementName
if (_schema != null)
{
- if (_schema.Id == null || _schema.Id.Length == 0) throw new InvalidOperationException(SR.Format(SR.XmlSerializableNameMissing1, _type!.FullName));
+ if (string.IsNullOrEmpty(_schema.Id)) throw new InvalidOperationException(SR.Format(SR.XmlSerializableNameMissing1, _type!.FullName));
}
}
}
// find anyElement if present.
for (int j = 0; j < mapping.Elements!.Length; j++)
{
- if (mapping.Elements[j].Any && (mapping.Elements[j].Name == null || mapping.Elements[j].Name.Length == 0))
+ if (mapping.Elements[j].Any && string.IsNullOrEmpty(mapping.Elements[j].Name))
{
anyElement = mapping;
break;
{
if (value is string && ((string)value).Length == 0)
{
- string str = (string)o;
- return str == null || str.Length == 0;
+ return string.IsNullOrEmpty((string)o);
}
else
{
}
private void WriteAttribute(string localName, string ns, string? value)
{
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
return;
_w.Append(',');
_w.Append(ns);
- if (ns != null && ns.Length != 0)
+ if (!string.IsNullOrEmpty(ns))
_w.Append(':');
_w.Append(localName);
_w.Append('=');
WriteAttribute(@"fixed", @"", ((string?)o.@FixedValue));
if (o.Parent != null && !(o.Parent is XmlSchema))
{
- if (o.QualifiedName != null && !o.QualifiedName.IsEmpty && o.QualifiedName.Namespace != null && o.QualifiedName.Namespace.Length != 0)
+ if (o.QualifiedName != null && !o.QualifiedName.IsEmpty && !string.IsNullOrEmpty(o.QualifiedName.Namespace))
{
WriteAttribute(@"form", @"", "qualified");
}
WriteAttribute(@"fixed", @"", o.FixedValue);
if (o.Parent != null && !(o.Parent is XmlSchema))
{
- if (o.QualifiedName != null && !o.QualifiedName.IsEmpty && o.QualifiedName.Namespace != null && o.QualifiedName.Namespace.Length != 0)
+ if (o.QualifiedName != null && !o.QualifiedName.IsEmpty && !string.IsNullOrEmpty(o.QualifiedName.Namespace))
{
WriteAttribute(@"form", @"", "qualified");
}
WriteAttribute(@"form", @"", "unqualified");
}
}
- if (o.Name != null && o.Name.Length != 0)
+ if (!string.IsNullOrEmpty(o.Name))
{
WriteAttribute(@"name", @"", o.Name);
}
ArgumentNullException.ThrowIfNull(members);
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
- element.Name = elementName == null || elementName.Length == 0 ? elementName : XmlConvert.EncodeLocalName(elementName);
+ element.Name = string.IsNullOrEmpty(elementName) ? elementName : XmlConvert.EncodeLocalName(elementName);
element.Mapping = ImportMembersMapping(members, ns, hasWrapperElement, writeAccessors, validate, new RecursionLimiter());
element.Mapping.TypeName = elementName;
{
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
- element.Name = mapping.TypeName; //XmlConvert.EncodeLocalName(name == null || name.Length == 0 ? mapping.TypeName : name);
+ element.Name = mapping.TypeName;
element.Namespace = ns;
element.Mapping = mapping;
return element;
}
else if (attrs[i] is XmlAnyElementAttribute any)
{
- if ((any.Name == null || any.Name.Length == 0) && any.GetNamespaceSpecified() && any.Namespace == null)
+ if (string.IsNullOrEmpty(any.Name) && any.GetNamespaceSpecified() && any.Namespace == null)
{
// ignore duplicate wildcards
wildcard = any;
public XmlMembersMapping ImportMembersMapping(string? elementName, string? ns, XmlReflectionMember[] members, bool hasWrapperElement, bool rpc, bool openModel, XmlMappingAccess access)
{
ElementAccessor element = new ElementAccessor();
- element.Name = elementName == null || elementName.Length == 0 ? elementName : XmlConvert.EncodeLocalName(elementName);
+ element.Name = string.IsNullOrEmpty(elementName) ? elementName : XmlConvert.EncodeLocalName(elementName);
element.Namespace = ns;
MembersMapping membersMapping = ImportMembersMapping(members, ns, hasWrapperElement, rpc, openModel, new RecursionLimiter());
private TypeMapping? GetTypeMapping(string? typeName, string? ns, TypeDesc typeDesc, NameTable typeLib, Type? type)
{
TypeMapping? mapping;
- if (typeName == null || typeName.Length == 0)
+ if (string.IsNullOrEmpty(typeName))
mapping = type == null ? null : (TypeMapping?)_anonymous[type];
else
mapping = (TypeMapping?)typeLib[typeName, ns];
private static bool NamespacesEqual(string? ns1, string? ns2)
{
- if (ns1 == null || ns1.Length == 0)
- return (ns2 == null || ns2.Length == 0);
+ if (string.IsNullOrEmpty(ns1))
+ return string.IsNullOrEmpty(ns2);
else
return ns1 == ns2;
}
{
mapping = ImportStructType(type, typeNs, identifier, baseType, false);
- if (mapping != null && type.Name != null && type.Name.Length != 0)
+ if (mapping != null && !string.IsNullOrEmpty(type.Name))
ImportDerivedTypes(new XmlQualifiedName(identifier, typeNs));
}
return mapping;
}
identifier = Accessor.UnescapeName(identifier);
- string typeName = type.Name == null || type.Name.Length == 0 ? GenerateUniqueTypeName(identifier, typeNs) : GenerateUniqueTypeName(identifier);
+ string typeName = string.IsNullOrEmpty(type.Name) ? GenerateUniqueTypeName(identifier, typeNs) : GenerateUniqueTypeName(identifier);
structMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
structMapping.Namespace = typeNs;
- structMapping.TypeName = type.Name == null || type.Name.Length == 0 ? null : identifier;
+ structMapping.TypeName = string.IsNullOrEmpty(type.Name) ? null : identifier;
structMapping.BaseMapping = (StructMapping)baseMapping;
if (!arrayLike)
ImportedMappings.Add(type, structMapping);
if (choiceMember.ChoiceIdentifier != null) return null;
arrayMapping.TypeDesc = choiceMember.TypeDesc;
arrayMapping.Elements = choiceMember.Elements;
- arrayMapping.TypeName = (type.Name == null || type.Name.Length == 0) ? $"ArrayOf{CodeIdentifier.MakePascal(arrayMapping.TypeDesc!.Name)}" : type.Name;
+ arrayMapping.TypeName = string.IsNullOrEmpty(type.Name) ? $"ArrayOf{CodeIdentifier.MakePascal(arrayMapping.TypeDesc!.Name)}" : type.Name;
}
else if (item is XmlSchemaAll || item is XmlSchemaSequence)
{
return null;
arrayMapping.Elements = new ElementAccessor[] { itemAccessor };
arrayMapping.TypeDesc = ((TypeMapping)itemAccessor.Mapping!).TypeDesc!.CreateArrayTypeDesc();
- arrayMapping.TypeName = (type.Name == null || type.Name.Length == 0) ? $"ArrayOf{CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeDesc.Name)}" : type.Name;
+ arrayMapping.TypeName = string.IsNullOrEmpty(type.Name) ? $"ArrayOf{CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeDesc.Name)}" : type.Name;
}
else
{
// for the array-like mappings we need to create a struct mapping for the case when it referenced by the top-level element
arrayMapping.TopLevelMapping = ImportStructType(type, ns, identifier, null, true);
arrayMapping.TopLevelMapping.ReferencedByTopLevelElement = true;
- if (type.Name != null && type.Name.Length != 0)
+ if (!string.IsNullOrEmpty(type.Name))
ImportDerivedTypes(new XmlQualifiedName(identifier, ns));
return arrayMapping;
{
PrimitiveMapping? mapping = null;
TypeDesc? typeDesc;
- if (dataType.Name != null && dataType.Name.Length != 0)
+ if (!string.IsNullOrEmpty(dataType.Name))
{
typeDesc = TypeScope.GetTypeDesc(dataType.Name, ns, flags);
if (typeDesc != null)
private TypeDesc GetDataTypeSource(XmlSchemaSimpleType dataType, TypeFlags flags)
{
TypeDesc? typeDesc;
- if (dataType.Name != null && dataType.Name.Length != 0)
+ if (!string.IsNullOrEmpty(dataType.Name))
{
typeDesc = TypeScope.GetTypeDesc(dataType);
if (typeDesc != null) return typeDesc;
if (schema != null)
{
- if (ns == null || ns.Length == 0)
+ if (string.IsNullOrEmpty(ns))
{
return schema.ElementFormDefault == XmlSchemaForm.None ? XmlSchemaForm.Unqualified : schema.ElementFormDefault;
}
else
{
XmlSchemas.Preprocess(schema);
- return element.QualifiedName.Namespace == null || element.QualifiedName.Namespace.Length == 0 ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified;
+ return string.IsNullOrEmpty(element.QualifiedName.Namespace) ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified;
}
}
return XmlSchemaForm.Qualified;
XmlSchema? schema = parent as XmlSchema;
if (schema != null)
{
- if (ns == null || ns.Length == 0)
+ if (string.IsNullOrEmpty(ns))
{
return schema.AttributeFormDefault == XmlSchemaForm.None ? XmlSchemaForm.Unqualified : schema.AttributeFormDefault;
}
else
{
XmlSchemas.Preprocess(schema);
- return attribute.QualifiedName.Namespace == null || attribute.QualifiedName.Namespace.Length == 0 ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified;
+ return string.IsNullOrEmpty(attribute.QualifiedName.Namespace) ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified;
}
}
return XmlSchemaForm.Unqualified;
{
if (item.Parent is XmlSchemaType type)
{
- if (type.Name != null && type.Name.Length != 0)
+ if (!string.IsNullOrEmpty(type.Name))
{
return type.QualifiedName;
}
{
o = o.Parent;
}
- if (ns == null || ns.Length == 0)
+ if (string.IsNullOrEmpty(ns))
{
XmlSchemaObject tmp = o;
while (tmp.Parent != null)
}
else if (o is XmlSchemaElement e)
{
- if (e.Name == null || e.Name.Length == 0)
+ if (string.IsNullOrEmpty(e.Name))
{
XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
// Element reference '{0}' declared in schema type '{1}' from namespace '{2}'
}
else if (o is XmlSchemaAttribute a)
{
- if (a.Name == null || a.Name.Length == 0)
+ if (string.IsNullOrEmpty(a.Name))
{
XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
// Attribure reference '{0}' declared in schema type '{1}' from namespace '{2}'
prefix = XmlConvert.DecodeName(prefix);
localName = XmlConvert.DecodeName(localName);
}
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
return new XmlQualifiedName(_r.NameTable.Add(value), _r.LookupNamespace(string.Empty));
}
string str = _r.ReadString();
if (str != null && trim)
str = str.Trim();
- if (value == null || value.Length == 0)
+ if (string.IsNullOrEmpty(value))
return str;
return value + str;
}
// find anyElement if present.
for (int j = 0; j < mapping.Elements!.Length; j++)
{
- if (mapping.Elements[j].Any && (mapping.Elements[j].Name == null || mapping.Elements[j].Name.Length == 0))
+ if (mapping.Elements[j].Any && string.IsNullOrEmpty(mapping.Elements[j].Name))
{
anyElement = member;
break;
{
ElementAccessor e = elements[j];
string? ns = e.Form == XmlSchemaForm.Qualified ? e.Namespace : "";
- if (e.Any && (e.Name == null || e.Name.Length == 0)) continue;
+ if (e.Any && string.IsNullOrEmpty(e.Name)) continue;
if (!firstElement)
qnames += ", ";
{
ElementAccessor e = elements[j];
string? ns = e.Form == XmlSchemaForm.Qualified ? e.Namespace : "";
- if (!isSequence && e.Any && (e.Name == null || e.Name.Length == 0)) continue;
+ if (!isSequence && e.Any && string.IsNullOrEmpty(e.Name)) continue;
if (!isSequence)
{
if (firstElement && count == 0)
// find anyElement if present.
for (int j = 0; j < mapping.Elements!.Length; j++)
{
- if (mapping.Elements[j].Any && (mapping.Elements[j].Name == null || mapping.Elements[j].Name.Length == 0))
+ if (mapping.Elements[j].Any && string.IsNullOrEmpty(mapping.Elements[j].Name))
{
anyElement = member;
break;
{
ElementAccessor e = elements[j];
string? ns = e.Form == XmlSchemaForm.Qualified ? e.Namespace : "";
- if (e.Any && (e.Name == null || e.Name.Length == 0)) continue;
+ if (e.Any && string.IsNullOrEmpty(e.Name)) continue;
if (!firstElement)
qnames += ", ";
{
ElementAccessor e = elements[j];
string? ns = e.Form == XmlSchemaForm.Qualified ? e.Namespace : "";
- if (!isSequence && e.Any && (e.Name == null || e.Name.Length == 0)) continue;
+ if (!isSequence && e.Any && string.IsNullOrEmpty(e.Name)) continue;
if (!firstElement || (!isSequence && count > 0))
{
ilg.InitElseIf();
private string GetQualifiedName(string name, string? ns)
{
- if (ns == null || ns.Length == 0) return name;
+ if (string.IsNullOrEmpty(ns)) return name;
string? prefix = _w.LookupPrefix(ns);
if (prefix == null)
{
if (writePrefixed && prefix == null && ns != null && ns.Length > 0)
{
prefix = _w.LookupPrefix(ns);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
prefix = NextPrefix();
}
{
xmlns.TryLookupPrefix(ns, out prefix);
}
- if (needEmptyDefaultNamespace && prefix == null && ns != null && ns.Length != 0)
+ if (needEmptyDefaultNamespace && prefix == null && !string.IsNullOrEmpty(ns))
prefix = NextPrefix();
_w.WriteStartElement(prefix, name, ns);
if (_namespaces != null)
{
string alias = qname.Name;
string? aliasNs = qname.Namespace;
- if (alias.Length == 0 && (aliasNs == null || aliasNs.Length == 0))
+ if (alias.Length == 0 && string.IsNullOrEmpty(aliasNs))
continue;
- if (aliasNs == null || aliasNs.Length == 0)
+ if (string.IsNullOrEmpty(aliasNs))
{
if (alias.Length > 0)
throw new InvalidOperationException(SR.Format(SR.XmlInvalidXmlns, alias));
protected void WriteNullTagEncoded(string? name, string? ns)
{
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
return;
WriteStartElement(name, ns, null, true);
_w.WriteAttributeString("nil", XmlSchema.InstanceNamespace, "true");
protected void WriteNullTagLiteral(string? name, string? ns)
{
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
return;
WriteStartElement(name, ns, null, false);
_w.WriteAttributeString("nil", XmlSchema.InstanceNamespace, "true");
protected void WriteEmptyTag(string? name, string? ns)
{
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
return;
WriteStartElement(name, ns, null, false);
_w.WriteEndElement();
{
string? prefix = _w.LookupPrefix(ns);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
prefix = "xml";
}
protected void WriteElementQualifiedName(string localName, string? ns, XmlQualifiedName? value, XmlQualifiedName? xsiType)
{
if (value == null) return;
- if (value.Namespace == null || value.Namespace.Length == 0)
+ if (string.IsNullOrEmpty(value.Namespace))
{
WriteStartElement(localName, ns, null, true);
WriteAttribute("xmlns", "");
throw new InvalidOperationException(SR.Format(SR.XmlDuplicateNs, prefix, ns));
}
}
- string? oldPrefix = (ns == null || ns.Length == 0) ? null : Writer.LookupPrefix(ns);
+ string? oldPrefix = string.IsNullOrEmpty(ns) ? null : Writer.LookupPrefix(ns);
if (oldPrefix == null || oldPrefix != prefix)
{
createInstance.Append(".NonPublic");
}
- if (arg == null || arg.Length == 0)
+ if (string.IsNullOrEmpty(arg))
{
createInstance.Append(", null, new object[0], null)");
}
string[] values = ((string)defaultValue!).Split(null);
for (int i = 0; i < values.Length; i++)
{
- if (values[i] == null || values[i].Length == 0)
+ if (string.IsNullOrEmpty(values[i]))
continue;
if (i > 0)
Writer.WriteLine(" | ");
}
}
}
- if (enumValue == null || enumValue.Length == 0)
+ if (string.IsNullOrEmpty(enumValue))
{
if (element.Any && element.Name.Length == 0)
{
string[] values = ((string)defaultValue!).Split(null);
for (int i = 0; i < values.Length; i++)
{
- if (values[i] == null || values[i].Length == 0)
+ if (string.IsNullOrEmpty(values[i]))
continue;
if (i > 0)
enumDefaultValue += ", ";
}
}
}
- if (enumValue == null || enumValue.Length == 0)
+ if (string.IsNullOrEmpty(enumValue))
{
if (element.Any && element.Name.Length == 0)
{
/// </devdoc>
public static string VerifyName(string name)
{
- ArgumentNullException.ThrowIfNull(name);
-
- if (name.Length == 0)
- {
- throw new ArgumentNullException(nameof(name), SR.Xml_EmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
// parse name
int endPos = ValidateNames.ParseNameNoNamespaces(name, 0);
internal static string VerifyNCName(string name, ExceptionType exceptionType)
{
- ArgumentNullException.ThrowIfNull(name);
-
- if (name.Length == 0)
- {
- throw new ArgumentNullException(nameof(name), SR.Xml_EmptyLocalName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name);
int end = ValidateNames.ParseNCName(name, 0);
internal static Exception? TryVerifyNMTOKEN(string name)
{
- if (name == null || name.Length == 0)
+ if (string.IsNullOrEmpty(name))
{
return new XmlException(SR.Xml_EmptyName, string.Empty);
}
internal static void VerifyCharData(string? data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType)
{
- if (data == null || data.Length == 0)
+ if (string.IsNullOrEmpty(data))
{
return;
}
/// </devdoc>
public static string ToString(string name, string? ns)
{
- return ns == null || ns.Length == 0 ? name : $"{ns}:{name}";
+ return string.IsNullOrEmpty(ns) ? name : $"{ns}:{name}";
}
// --------- Some useful internal stuff -----------------
}
else
{
- if (relativeUri == null || relativeUri.Length == 0)
+ if (string.IsNullOrEmpty(relativeUri))
{
return baseUri;
}
for (int i = 0; i < paramNames.Length; i++)
{
- if (paramNames[i] != null && paramNames[i]!.Length != 0)
+ if (!string.IsNullOrEmpty(paramNames[i]))
methBldr.DefineParameter(i + (isRaw ? 1 : 2), ParameterAttributes.None, paramNames[i]);
}
return;
}
- if (s != null && s.Length != 0)
- this.writer.WriteComment(name != null && name.Length != 0 ? $"{name}: {s}" : s);
+ if (!string.IsNullOrEmpty(s))
+ this.writer.WriteComment(!string.IsNullOrEmpty(name) ? $"{name}: {s}" : s);
}
/// <summary>
{
int hashCode;
int idx = 0;
- Debug.Assert(localName != null && localName.Length != 0 && prefix != null && ns != null);
+ Debug.Assert(!string.IsNullOrEmpty(localName) && prefix != null && ns != null);
// Compute hashcode based on first letter of the localName
hashCode = (1 << ((int)localName[0] & 31));
/// </summary>
public override void WriteStartElement(string? prefix, string localName, string? ns)
{
- Debug.Assert(prefix != null && localName != null && localName.Length != 0 && ns != null, "Invalid argument");
+ Debug.Assert(prefix != null && !string.IsNullOrEmpty(localName) && ns != null, "Invalid argument");
Debug.Assert(ValidateNames.ValidateName(prefix, localName, ns, XPathNodeType.Element, ValidateNames.Flags.All), "Name validation failed");
// Xml state transitions
private string RemapPrefix(string prefix, string ns, bool isElemPrefix)
{
string? genPrefix;
- Debug.Assert(prefix != null && ns != null && ns.Length != 0);
+ Debug.Assert(prefix != null && !string.IsNullOrEmpty(ns));
_conflictPrefixes ??= new Dictionary<string, string>(16);
internal string? MarkOutError()
{
- if (queryString == null || queryString.Trim(' ').Length == 0)
+ if (queryString == null || queryString.AsSpan().Trim(' ').IsEmpty)
{
return null;
}
// Does not suppress errors
private void ParseWhitespaceRules(string elements, bool preserveSpace)
{
- if (elements != null && elements.Length != 0)
+ if (!string.IsNullOrEmpty(elements))
{
string[] tokens = XmlConvert.SplitString(elements);
for (int i = 0; i < tokens.Length; i++)
{
namespaceName = _compiler.CreatePhantomNamespace();
}
- else if (prefix == null || prefix.Length == 0)
+ else if (string.IsNullOrEmpty(prefix))
{
namespaceName = prefix;
}
internal void ValueAppend(string? s, bool disableEscaping)
{
- if (s == null || s.Length == 0)
+ if (string.IsNullOrEmpty(s))
{
return;
}
// the value is ignored iff forwards-compatible mode is on.
private string[]? ResolvePrefixes(string tokens)
{
- if (tokens == null || tokens.Length == 0)
+ if (string.IsNullOrEmpty(tokens))
{
return null;
}
Debug.Assert(nspace != null);
_scopeStack.AddNamespace(prefix, nspace, _defaultNS);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
_defaultNS = nspace;
}
[return: NotNullIfNotNull(nameof(formatString))]
private static List<FormatInfo?>? ParseFormat(string? formatString)
{
- if (formatString == null || formatString.Length == 0)
+ if (string.IsNullOrEmpty(formatString))
{
return null;
}
Debug.Assert(nspace != null);
CurrentElementScope.AddNamespace(prefix, nspace, _defaultNS);
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
_defaultNS = nspace;
}
Debug.Assert(prefix != null);
thisScope = true;
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
return _defaultNS;
}
// no 'implemented' variations satisfying the filter
testCase = new CXmlDriverEmptyTestCase(testCaseName, testCaseDescription,
" no variations with @Implemented='True' " +
- (_requiredLanguage != null && _requiredLanguage.Length != 0 ? " and @Language='" + _requiredLanguage + "'" : "") +
+ (!string.IsNullOrEmpty(_requiredLanguage) ? " and @Language='" + _requiredLanguage + "'" : "") +
(filterXPath == null ? "" : " and satisfying '" + filterXPath + "'"), _testModule);
// add test case
AddChild(new CVariation(v17) { Attribute = new Variation("Test for VerifyNMTOKEN(null)") { Param = 1 } });
AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyPublicId(String.Empty)") { Params = new object[] { 6, null } } });
AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyWhitespace(String.Empty)") { Params = new object[] { 7, null } } });
- AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyName(String.Empty)") { Params = new object[] { 2, typeof(ArgumentNullException) } } });
- AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyNCName(String.Empty)") { Params = new object[] { 3, typeof(ArgumentNullException) } } });
+ AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyName(String.Empty)") { Params = new object[] { 2, typeof(ArgumentException) } } });
+ AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyNCName(String.Empty)") { Params = new object[] { 3, typeof(ArgumentException) } } });
AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyXmlChars(String.Empty)") { Params = new object[] { 5, null } } });
AddChild(new CVariation(v18) { Attribute = new Variation("Test for VerifyNMTOKEN(String.Empty)") { Params = new object[] { 1, typeof(XmlException) } } });
}
private string EnsureTrailingSlash(string path)
{
- if (string.IsNullOrEmpty(path))
- throw new ArgumentException();
+ ArgumentException.ThrowIfNullOrEmpty(path);
return path[path.Length - 1] == Path.DirectorySeparatorChar ?
path :
{
m_xsltArg.AddParam(szEmpty, szEmpty, "Test1");
}
- catch (System.ArgumentNullException)
+ catch (System.ArgumentException)
{
return;
}
- _output.WriteLine("System.ArgumentNullException not thrown for param name empty string");
+ _output.WriteLine("System.ArgumentException not thrown for param name empty string");
Assert.True(false);
}
{
m_xsltArg.AddParam(szEmpty, szEmpty, "Test1");
}
- catch (System.ArgumentNullException)
+ catch (System.ArgumentException)
{
return;
}
- _output.WriteLine("System.ArgumentNullException not thrown for param name empty string");
+ _output.WriteLine("System.ArgumentException not thrown for param name empty string");
Assert.True(false);
}
<data name="InvalidOperation_AModuleRequired" xml:space="preserve">
<value>Assembly needs at least one module defined.</value>
</data>
- <data name="Argument_NullOrEmptyAssemblyName" xml:space="preserve">
- <value>AssemblyName.Name cannot be null or an empty string.</value>
- </data>
<data name="InvalidOperation_NoMultiModuleAssembly" xml:space="preserve">
<value>You cannot have more than one dynamic module in each dynamic assembly in this version of the runtime.</value>
</data>
<data name="Argument_SizeConstMustBeSpecified" xml:space="preserve">
<value>SizeConst parameter must be specified for UnmanagedType.ByValTStr type.</value>
</data>
-</root>
\ No newline at end of file
+</root>
name = (AssemblyName)name.Clone();
- if (string.IsNullOrEmpty(name.Name))
- {
- throw new ArgumentException(SR.Argument_NullOrEmptyAssemblyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name.Name, "AssemblyName.Name");
_assemblyName = name;
_coreAssembly = coreAssembly;
internal static DllImportData CreateDllImportData(CustomAttributeInfo attr, out bool preserveSig)
{
string? moduleName = (string?)attr._ctorArgs[0];
- if (moduleName == null || moduleName.Length == 0)
+ if (string.IsNullOrEmpty(moduleName))
{
throw new ArgumentException(SR.Argument_DllNameCannotBeEmpty);
}
{
Assembly containingAssembly = this;
string location = containingAssembly.Location;
- if (location == null || location.Length == 0)
+ if (string.IsNullOrEmpty(location))
return null;
string? directoryPath = Path.GetDirectoryName(location);
string modulePath = Path.Combine(directoryPath!, moduleName);
private static string GetClrNamespace(string? dataContractNamespace)
{
- if (dataContractNamespace == null || dataContractNamespace.Length == 0)
+ if (string.IsNullOrEmpty(dataContractNamespace))
return string.Empty;
StringBuilder builder = new StringBuilder();
public void EncodeAttribute(string prefix, string localName, string value)
{
Encode(' ');
- if (prefix == null || prefix.Length == 0)
+ if (string.IsNullOrEmpty(prefix))
{
Encode(localName);
}
public override void WriteQualifiedName(string localName, string ns)
{
- if (localName == null || localName.Length == 0)
+ if (string.IsNullOrEmpty(localName))
{
throw new ArgumentNullException(nameof(localName));
}
ThrowBadStateException("WriteStartElement");
}
- if (localName == null || localName.Length == 0)
+ if (string.IsNullOrEmpty(localName))
{
throw new ArgumentNullException(nameof(localName));
}
throw new Exception("TooManyDataMembers :" + field.DeclaringType.FullName + " :: " + field.Name);
DataMemberAttribute memberAttribute = (DataMemberAttribute)memberAttributes[0];
DataMember memberContract = new DataMember(field);
- if (memberAttribute.Name == null || memberAttribute.Name.Length == 0)
+ if (string.IsNullOrEmpty(memberAttribute.Name))
memberContract.Name = field.Name;
else
memberContract.Name = memberAttribute.Name;
if (_refProcessed[index]) return _refLevelCache[index];
_refProcessed[index] = true;
Reference reference = (Reference)references[index]!;
- if (reference.Uri == null || reference.Uri.Length == 0 || (reference.Uri.Length > 0 && reference.Uri[0] != '#'))
+ if (string.IsNullOrEmpty(reference.Uri) || (reference.Uri.Length > 0 && reference.Uri[0] != '#'))
{
_refLevelCache[index] = 0;
return 0;
// Mimic the behavior of the X509IssuerSerial constructor with null and empty checks
internal static X509IssuerSerial CreateX509IssuerSerial(string? issuerName, string? serialNumber)
{
- if (issuerName == null || issuerName.Length == 0)
+ if (string.IsNullOrEmpty(issuerName))
throw new ArgumentException(SR.Arg_EmptyOrNullString, nameof(issuerName));
- if (serialNumber == null || serialNumber.Length == 0)
+ if (string.IsNullOrEmpty(serialNumber))
throw new ArgumentException(SR.Arg_EmptyOrNullString, nameof(serialNumber));
return new X509IssuerSerial()
{
// the Uri is required
string? uri = Utils.GetAttribute(elem, "URI", Consts.XmlDecryptionTransformNamespaceUrl);
- if (uri == null || uri.Length == 0 || uri[0] != '#')
+ if (string.IsNullOrEmpty(uri) || uri[0] != '#')
throw new CryptographicException(SR.Cryptography_Xml_UriRequired);
if (!Utils.VerifyAttributes(elem, "URI"))
{
<data name="Arg_EmptyOrNullString" xml:space="preserve">
<value>String cannot be empty or null.</value>
</data>
- <data name="Arg_EmptyOrNullString_Named" xml:space="preserve">
- <value>The '{0}' string cannot be empty or null.</value>
- </data>
<data name="Arg_EmptySpan" xml:space="preserve">
<value>Span may not be empty.</value>
</data>
<data name="CryptoConfigNotSupported" xml:space="preserve">
<value>Accessing a hash algorithm by manipulating the HashName property is not supported on this platform. Instead, you must instantiate one of the supplied subtypes (such as HMACSHA1.)</value>
</data>
- <data name="Cryptography_AddNullOrEmptyName" xml:space="preserve">
- <value>CryptoConfig cannot add a mapping for a null or empty name.</value>
- </data>
<data name="Cryptography_AlgKdfRequiresChars" xml:space="preserve">
<value>The KDF for algorithm '{0}' requires a char-based password input.</value>
</data>
// throw an exception if we find an invalid name partway through the list.
foreach (string name in algorithmNames)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.Cryptography_AddNullOrEmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name, nameof(names));
}
// Everything looks valid, so we're safe to add the name mappings.
// exception if an invalid name is found further down the array.
foreach (string name in oidNames)
{
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentException(SR.Cryptography_AddNullOrEmptyName);
- }
+ ArgumentException.ThrowIfNullOrEmpty(name, nameof(names));
}
// Everything is valid, so we're good to lock the hash table and add the application mappings
{
ArgumentNullException.ThrowIfNull(oid);
ArgumentNullException.ThrowIfNull(value);
-
- if (string.IsNullOrEmpty(oid.Value))
- throw new ArgumentException(SR.Format(SR.Arg_EmptyOrNullString_Named, "oid.Value"), nameof(oid));
+ ArgumentException.ThrowIfNullOrEmpty(oid.Value);
UniversalTagNumber tag = GetAndValidateTagNumber(stringEncodingType);
EncodeComponent(oid.Value, value, tag);
public IEnumerable<string> EnumerateUris(Oid accessMethodOid)
{
ArgumentNullException.ThrowIfNull(accessMethodOid);
-
- if (string.IsNullOrEmpty(accessMethodOid.Value))
- {
- throw new ArgumentException(
- SR.Format(SR.Arg_EmptyOrNullString_Named, "accessMethodOid.Value"),
- nameof(accessMethodOid));
- }
+ ArgumentException.ThrowIfNullOrEmpty(accessMethodOid.Value);
return EnumerateUris(accessMethodOid.Value);
}
public X509Extension(Oid oid, ReadOnlySpan<byte> rawData, bool critical)
: base(oid, rawData)
{
- if (base.Oid?.Value == null)
- throw new ArgumentNullException(nameof(oid));
- if (base.Oid.Value.Length == 0)
- throw new ArgumentException(SR.Format(SR.Arg_EmptyOrNullString_Named, "oid.Value"), nameof(oid));
+ ArgumentException.ThrowIfNullOrEmpty(base.Oid?.Value, "oid.Value");
Critical = critical;
}
internal X509Extension(Oid oid, byte[] rawData, bool critical, bool skipCopy)
: base(oid, rawData, skipCopy)
{
- if (base.Oid?.Value == null)
- throw new ArgumentNullException(nameof(oid));
-
- if (base.Oid.Value.Length == 0)
- throw new ArgumentException(SR.Format(SR.Arg_EmptyOrNullString_Named, "oid.Value"), nameof(oid));
+ ArgumentException.ThrowIfNullOrEmpty(base.Oid?.Value, "oid.Value");
Critical = critical;
}
public X509ContentType GetCertContentType(ReadOnlySpan<byte> rawData)
{
- if (rawData == null || rawData.Length == 0)
+ if (rawData.IsEmpty)
throw new CryptographicException();
X509ContentType contentType = Interop.AndroidCrypto.X509GetContentType(rawData);
{
const int errSecUnknownFormat = -25257;
- if (rawData == null || rawData.Length == 0)
+ if (rawData.IsEmpty)
{
// Throw to match Windows and Unix behavior.
throw Interop.AppleCrypto.CreateExceptionForOSStatus(errSecUnknownFormat);
public X509ContentType GetCertContentType(ReadOnlySpan<byte> rawData)
{
const int errSecUnknownFormat = -25257;
- if (rawData == null || rawData.Length == 0)
+ if (rawData.IsEmpty)
{
// Throw to match Windows and Unix behavior.
throw Interop.AppleCrypto.CreateExceptionForOSStatus(errSecUnknownFormat);
[SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public static void AddOID_EmptyString_Throws()
{
- AssertExtensions.Throws<ArgumentException>(null, () => CryptoConfig.AddOID(string.Empty, string.Empty));
+ AssertExtensions.Throws<ArgumentException>("names", () => CryptoConfig.AddOID(string.Empty, string.Empty));
}
[Fact]
[SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")]
public static void AddAlgorithm_EmptyString_Throws()
{
- AssertExtensions.Throws<ArgumentException>(null, () => CryptoConfig.AddAlgorithm(typeof(CryptoConfigTests), string.Empty));
+ AssertExtensions.Throws<ArgumentException>("names", () => CryptoConfig.AddAlgorithm(typeof(CryptoConfigTests), string.Empty));
}
[Fact]
Assert.Throws<ArgumentNullException>("accessMethodOid", () => aia.EnumerateUris((string)null));
Assert.Throws<ArgumentNullException>("accessMethodOid", () => aia.EnumerateUris((Oid)null));
- Assert.Throws<ArgumentException>("accessMethodOid", () => aia.EnumerateUris(new Oid(null, "potato")));
- Assert.Throws<ArgumentException>("accessMethodOid", () => aia.EnumerateUris(new Oid("", "potato")));
+ Assert.Throws<ArgumentNullException>("accessMethodOid.Value", () => aia.EnumerateUris(new Oid(null, "potato")));
+ Assert.Throws<ArgumentException>("accessMethodOid.Value", () => aia.EnumerateUris(new Oid("", "potato")));
}
}
throw new ArgumentException(SR.IdentityReference_DomainNameTooLong, nameof(domainName));
}
- if (domainName == null || domainName.Length == 0)
+ if (string.IsNullOrEmpty(domainName))
{
_name = accountName;
}
public override bool IsInRole(string role)
{
- if (role == null || role.Length == 0)
+ if (string.IsNullOrEmpty(role))
return false;
NTAccount ntAccount = new NTAccount(role);
if (!CheckMachineName(machineName))
throw new ArgumentException(SR.Format(SR.BadMachineName, machineName));
- if (string.IsNullOrEmpty(name))
- throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(name), name));
+ if (name is null)
+ {
+ throw new ArgumentNullException(nameof(name));
+ }
+ if (name.Length == 0)
+ {
+ throw new ArgumentException(SR.Format(SR.InvalidParameter, nameof(name), name), nameof(name));
+ }
_machineName = machineName;
_eitherName = name;
Assert.True(foundOtherSvc, "foundOtherSvc");
}
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- public static void ConstructWithBadServiceName(string value)
+ [Fact]
+ public static void ConstructWithBadServiceName()
{
- Assert.Throws<ArgumentException>(() => new ServiceController(value));
+ Assert.ThrowsAny<ArgumentException>(() => new ServiceController(null));
+ Assert.Throws<ArgumentException>(() => new ServiceController(""));
}
[Fact]
throw new ArgumentOutOfRangeException(SR.Get(SRID.InvalidConfidence));
}
- _text = text == null || text.Length == 0 ? null : text;
+ _text = string.IsNullOrEmpty(text) ? null : text;
_confidence = confidence;
_pronunciation = pronunciation == null || pronunciation.Length == 0 ? null : pronunciation;
_lexicalForm = lexicalForm;
private static OletxTransactionManager CheckTransactionManager(string? nodeName)
{
OletxTransactionManager tm = DistributedTransactionManager;
- if (!((tm.NodeName == null && (nodeName == null || nodeName.Length == 0)) ||
+ if (!((tm.NodeName == null && string.IsNullOrEmpty(nodeName)) ||
(tm.NodeName != null && tm.NodeName.Equals(nodeName))))
{
throw new ArgumentException(SR.InvalidRecoveryInformation, "recoveryInformation");