Add and use ArgumentNullOrEmptyException
This commit is contained in:
@@ -10,6 +10,7 @@ using NPoco;
|
||||
using Semver;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -270,8 +271,8 @@ namespace Umbraco.Core
|
||||
/// <param name="logger">A logger.</param>
|
||||
private static void SaveConnectionString(string connectionString, string providerName, ILogger logger)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentException("Value cannot be null nor empty.", nameof(connectionString));
|
||||
if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentException("Value cannot be null nor empty.", nameof(providerName));
|
||||
if (string.IsNullOrWhiteSpace(connectionString)) throw new ArgumentNullOrEmptyException(nameof(connectionString));
|
||||
if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullOrEmptyException(nameof(providerName));
|
||||
|
||||
// set the connection string for the new datalayer
|
||||
var connectionStringSettings = new ConnectionStringSettings(GlobalSettings.UmbracoConnectionName, connectionString, providerName);
|
||||
|
||||
30
src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs
Normal file
30
src/Umbraco.Core/Exceptions/ArgumentNullOrEmptyException.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when a null reference, or an empty argument,
|
||||
/// is passed to a method that does not accept it as a valid argument.
|
||||
/// </summary>
|
||||
public class ArgumentNullOrEmptyException : ArgumentNullException
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArgumentNullOrEmptyException"/> class
|
||||
/// with the name of the parameter that caused this exception.
|
||||
/// </summary>
|
||||
/// <param name="paramName">The named of the parameter that caused the exception.</param>
|
||||
public ArgumentNullOrEmptyException(string paramName)
|
||||
: base(paramName)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArgumentNullOrEmptyException"/> class
|
||||
/// with a specified error message and the name of the parameter that caused this exception.
|
||||
/// </summary>
|
||||
/// <param name="paramName">The named of the parameter that caused the exception.</param>
|
||||
/// <param name="message">A message that describes the error.</param>
|
||||
public ArgumentNullOrEmptyException(string paramName, string message)
|
||||
: base(paramName, message)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Core.IO
|
||||
@@ -34,14 +35,9 @@ namespace Umbraco.Core.IO
|
||||
|
||||
public PhysicalFileSystem(string rootPath, string rootUrl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rootPath))
|
||||
throw new ArgumentException("The argument 'rootPath' cannot be null or empty.");
|
||||
|
||||
if (string.IsNullOrEmpty(rootUrl))
|
||||
throw new ArgumentException("The argument 'rootUrl' cannot be null or empty.");
|
||||
|
||||
if (rootPath.StartsWith("~/"))
|
||||
throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
|
||||
if (string.IsNullOrEmpty(rootPath)) throw new ArgumentNullOrEmptyException(nameof(rootPath));
|
||||
if (string.IsNullOrEmpty(rootUrl)) throw new ArgumentNullOrEmptyException(nameof(rootUrl));
|
||||
if (rootPath.StartsWith("~/")) throw new ArgumentException("The rootPath argument cannot be a virtual path and cannot start with '~/'");
|
||||
|
||||
// rootPath should be... rooted, as in, it's a root path!
|
||||
// but the test suite App.config cannot really "root" anything so we'll have to do it here
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Umbraco.Core.Exceptions;
|
||||
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
@@ -16,8 +17,7 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
/// <param name="contentTypeAlias">The content type alias.</param>
|
||||
public PublishedContentModelAttribute(string contentTypeAlias)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(contentTypeAlias))
|
||||
throw new ArgumentException("Argument cannot be null nor empty.", "contentTypeAlias");
|
||||
if (string.IsNullOrWhiteSpace(contentTypeAlias)) throw new ArgumentNullOrEmptyException(nameof(contentTypeAlias));
|
||||
ContentTypeAlias = contentTypeAlias;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading;
|
||||
using NPoco;
|
||||
using NPoco.FluentMappings;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.FaultHandling;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
@@ -73,7 +74,7 @@ namespace Umbraco.Core.Persistence
|
||||
if (sqlSyntaxProviders == null) throw new ArgumentNullException(nameof(sqlSyntaxProviders));
|
||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||
if (umbracoDatabaseAccessor == null) throw new ArgumentNullException(nameof(umbracoDatabaseAccessor));
|
||||
if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentException("Value cannot be null nor empty.", nameof(connectionStringName));
|
||||
if (string.IsNullOrWhiteSpace(connectionStringName)) throw new ArgumentNullOrEmptyException(nameof(connectionStringName));
|
||||
if (mappers == null) throw new ArgumentNullException(nameof(mappers));
|
||||
|
||||
_mappers = mappers;
|
||||
|
||||
@@ -273,6 +273,7 @@
|
||||
<Compile Include="Events\RollbackEventArgs.cs" />
|
||||
<Compile Include="Events\SaveEventArgs.cs" />
|
||||
<Compile Include="Events\SendToPublishEventArgs.cs" />
|
||||
<Compile Include="Exceptions\ArgumentNullOrEmptyException.cs" />
|
||||
<Compile Include="Exceptions\DataOperationException.cs" />
|
||||
<Compile Include="Exceptions\InvalidCompositionException.cs" />
|
||||
<Compile Include="Exceptions\BootFailedException.cs" />
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Core.Xml
|
||||
@@ -26,7 +27,7 @@ namespace Umbraco.Core.Xml
|
||||
{
|
||||
if (xml == null) throw new ArgumentNullException("xml");
|
||||
if (n == null) throw new ArgumentNullException("n");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
if (n.Attributes == null)
|
||||
{
|
||||
@@ -376,7 +377,7 @@ namespace Umbraco.Core.Xml
|
||||
public static XmlAttribute AddAttribute(XmlDocument xd, string name, string value)
|
||||
{
|
||||
if (xd == null) throw new ArgumentNullException("xd");
|
||||
if (string.IsNullOrEmpty(name)) throw new ArgumentException("Value cannot be null or empty.", "name");
|
||||
if (string.IsNullOrEmpty(name)) throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
var temp = xd.CreateAttribute(name);
|
||||
temp.Value = value;
|
||||
@@ -393,7 +394,7 @@ namespace Umbraco.Core.Xml
|
||||
public static XmlNode AddTextNode(XmlDocument xd, string name, string value)
|
||||
{
|
||||
if (xd == null) throw new ArgumentNullException("xd");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
|
||||
temp.AppendChild(xd.CreateTextNode(value));
|
||||
@@ -412,7 +413,7 @@ namespace Umbraco.Core.Xml
|
||||
{
|
||||
if (xd == null) throw new ArgumentNullException("xd");
|
||||
if (parent == null) throw new ArgumentNullException("parent");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
var child = parent.SelectSingleNode(name);
|
||||
if (child != null)
|
||||
@@ -433,7 +434,7 @@ namespace Umbraco.Core.Xml
|
||||
public static XmlNode AddCDataNode(XmlDocument xd, string name, string value)
|
||||
{
|
||||
if (xd == null) throw new ArgumentNullException("xd");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
var temp = xd.CreateNode(XmlNodeType.Element, name, "");
|
||||
temp.AppendChild(xd.CreateCDataSection(value));
|
||||
@@ -452,7 +453,7 @@ namespace Umbraco.Core.Xml
|
||||
{
|
||||
if (xd == null) throw new ArgumentNullException("xd");
|
||||
if (parent == null) throw new ArgumentNullException("parent");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value cannot be null or whitespace.", "name");
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name));
|
||||
|
||||
var child = parent.SelectSingleNode(name);
|
||||
if (child != null)
|
||||
|
||||
Reference in New Issue
Block a user