diff --git a/src/Umbraco.Compat7/Core/Logging/LogHelper.cs b/src/Umbraco.Compat7/Core/Logging/LogHelper.cs index 6d760f6f19..8bfefbedf6 100644 --- a/src/Umbraco.Compat7/Core/Logging/LogHelper.cs +++ b/src/Umbraco.Compat7/Core/Logging/LogHelper.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Web; using Umbraco.Core.Composing; +using Umbraco.Core.Exceptions; using Umbraco.Web; // ReSharper disable once CheckNamespace @@ -38,8 +39,8 @@ namespace Umbraco.Core.Logging [Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")] public static void Warn(Type callingType, string message, bool showHttpTrace, params Func[] formatItems) { - Mandate.ParameterNotNull(callingType, "callingType"); - Mandate.ParameterNotNullOrEmpty(message, "message"); + if (callingType == null) throw new ArgumentNullException(nameof(callingType)); + if (string.IsNullOrEmpty(message)) throw new ArgumentNullOrEmptyException(nameof(message)); if (showHttpTrace && HttpContext.Current != null) { @@ -59,9 +60,9 @@ namespace Umbraco.Core.Logging [Obsolete("Warnings with http trace should not be used. This method will be removed in future versions")] public static void WarnWithException(Type callingType, string message, bool showHttpTrace, Exception e, params Func[] formatItems) { - Mandate.ParameterNotNull(e, "e"); - Mandate.ParameterNotNull(callingType, "callingType"); - Mandate.ParameterNotNullOrEmpty(message, "message"); + if (e == null) throw new ArgumentNullException(nameof(e)); + if (callingType == null) throw new ArgumentNullException(nameof(callingType)); + if (string.IsNullOrEmpty(message)) throw new ArgumentNullOrEmptyException(nameof(message)); if (showHttpTrace && HttpContext.Current != null) { diff --git a/src/Umbraco.Core/Mandate.cs b/src/Umbraco.Core/Mandate.cs deleted file mode 100644 index 15a0e94bc7..0000000000 --- a/src/Umbraco.Core/Mandate.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Umbraco.Core -{ - /// - /// Helper class for mandating values, for example on method parameters. - /// - [Obsolete] - public static class Mandate - { - /// - /// Mandates that the specified parameter is not null. - /// - /// The value. - /// Name of the param. - /// If is null. - public static void ParameterNotNull(T value, string paramName) where T : class - { - That(value != null, () => new ArgumentNullException(paramName)); - } - - - /// - /// Mandates that the specified parameter is not null. - /// - /// The value. - /// Name of the param. - /// If is null or whitespace. - public static void ParameterNotNullOrEmpty(string value, string paramName) - { - That(!string.IsNullOrWhiteSpace(value), () => new ArgumentNullException(paramName)); - } - - /// - /// Mandates that the specified sequence is not null and has at least one element. - /// - /// - /// The sequence. - /// Name of the param. - public static void ParameterNotNullOrEmpty(IEnumerable sequence, string paramName) - { - ParameterNotNull(sequence, paramName); - ParameterCondition(sequence.Any(), paramName); - } - - - /// - /// Mandates that the specified parameter matches the condition. - /// - /// The condition to check. - /// Name of the param. - /// If the condition is false. - public static void ParameterCondition(bool condition, string paramName) - { - ParameterCondition(condition, paramName, (string)null); - } - - /// - /// Mandates that the specified parameter matches the condition. - /// - /// The condition to check. - /// Name of the param. - /// The message. - /// If the condition is false. - public static void ParameterCondition(bool condition, string paramName, string message) - { - // Warning: don't make this method have an optional message parameter (removing the other ParameterCondition overload) as it will - // make binaries compiled against previous Framework libs incompatible unneccesarily - message = message ?? "A parameter passed into a method was not a valid value"; - That(condition, () => new ArgumentException(message, paramName)); - } - - /// - /// Mandates that the specified condition is true, otherwise throws an exception specified in . - /// - /// The type of the exception. - /// if set to true, throws exception . - /// An exception of type is raised if the condition is false. - public static void That(bool condition) where TException : Exception, new() - { - if (!condition) - throw ActivatorHelper.CreateInstance(); - } - - /// - /// Mandates that the specified condition is true, otherwise throws an exception specified in . - /// - /// The type of the exception. - /// if set to true, throws exception . - /// Deffered expression to call if the exception should be raised. - /// An exception of type is raised if the condition is false. - public static void That(bool condition, Func defer) where TException : Exception, new() - { - if (!condition) - { - throw defer.Invoke(); - } - - // Here is an example of how this method is actually called - //object myParam = null; - //Mandate.That(myParam != null, - // textManager => new ArgumentNullException(textManager.Get("blah", new {User = "blah"}))); - } - } -} diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 72668d801b..f7ca42f2e3 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -43,9 +43,7 @@ namespace Umbraco.Core.Models public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties) : base(name, parent, contentType, properties) { - Mandate.ParameterNotNull(contentType, "contentType"); - - _contentType = contentType; + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); PublishedState = PublishedState.Unpublished; } @@ -69,9 +67,7 @@ namespace Umbraco.Core.Models public Content(string name, int parentId, IContentType contentType, PropertyCollection properties) : base(name, parentId, contentType, properties) { - Mandate.ParameterNotNull(contentType, "contentType"); - - _contentType = contentType; + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); PublishedState = PublishedState.Unpublished; } diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index b5a6f2ddc2..71c8e6af21 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -43,17 +43,15 @@ namespace Umbraco.Core.Models /// protected ContentBase(string name, int parentId, IContentTypeComposition contentType, PropertyCollection properties) { - Mandate.ParameterCondition(parentId != 0, "parentId"); - Mandate.ParameterNotNull(contentType, "contentType"); - Mandate.ParameterNotNull(properties, "properties"); + if (parentId == 0) throw new ArgumentOutOfRangeException(nameof(parentId)); - ContentTypeBase = contentType; + ContentTypeBase = contentType ?? throw new ArgumentNullException(nameof(contentType)); Version = Guid.NewGuid(); _parentId = new Lazy(() => parentId); _name = name; _contentTypeId = contentType.Id; - _properties = properties; + _properties = properties ?? throw new ArgumentNullException(nameof(properties)); _properties.EnsurePropertyTypes(PropertyTypes); _additionalData = new Dictionary(); } @@ -67,17 +65,15 @@ namespace Umbraco.Core.Models /// protected ContentBase(string name, IContentBase parent, IContentTypeComposition contentType, PropertyCollection properties) { - Mandate.ParameterNotNull(parent, "parent"); - Mandate.ParameterNotNull(contentType, "contentType"); - Mandate.ParameterNotNull(properties, "properties"); + if (parent == null) throw new ArgumentNullException(nameof(parent)); - ContentTypeBase = contentType; + ContentTypeBase = contentType ?? throw new ArgumentNullException(nameof(contentType)); Version = Guid.NewGuid(); _parentId = new Lazy(() => parent.Id); _name = name; _contentTypeId = contentType.Id; - _properties = properties; + _properties = properties ?? throw new ArgumentNullException(nameof(properties)); _properties.EnsurePropertyTypes(PropertyTypes); _additionalData = new Dictionary(); } diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index b822b66504..9361dc40f3 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -40,7 +40,7 @@ namespace Umbraco.Core.Models protected ContentTypeBase(int parentId) { - Mandate.ParameterCondition(parentId != 0, "parentId"); + if (parentId == 0) throw new ArgumentOutOfRangeException(nameof(parentId)); _parentId = new Lazy(() => parentId); _allowedContentTypes = new List(); @@ -56,7 +56,7 @@ namespace Umbraco.Core.Models protected ContentTypeBase(IContentTypeBase parent, string alias) { - Mandate.ParameterNotNull(parent, "parent"); + if (parent == null) throw new ArgumentNullException(nameof(parent)); _alias = alias; _parentId = new Lazy(() => parent.Id); diff --git a/src/Umbraco.Core/Models/Media.cs b/src/Umbraco.Core/Models/Media.cs index d91fe9fdf8..a67468def1 100644 --- a/src/Umbraco.Core/Models/Media.cs +++ b/src/Umbraco.Core/Models/Media.cs @@ -34,8 +34,7 @@ namespace Umbraco.Core.Models public Media(string name, IMedia parent, IMediaType contentType, PropertyCollection properties) : base(name, parent, contentType, properties) { - Mandate.ParameterNotNull(contentType, "contentType"); - _contentType = contentType; + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); } /// @@ -59,18 +58,14 @@ namespace Umbraco.Core.Models public Media(string name, int parentId, IMediaType contentType, PropertyCollection properties) : base(name, parentId, contentType, properties) { - Mandate.ParameterNotNull(contentType, "contentType"); - _contentType = contentType; + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); } /// /// Gets the ContentType used by this Media object /// [IgnoreDataMember] - public IMediaType ContentType - { - get { return _contentType; } - } + public IMediaType ContentType => _contentType; /// /// Changes the for the current Media object diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index b8d0bb9655..1574379179 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Runtime.Serialization; using Umbraco.Core.Composing; +using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; namespace Umbraco.Core.Models @@ -29,10 +30,8 @@ namespace Umbraco.Core.Models public Member(IMemberType contentType) : base("", -1, contentType, new PropertyCollection()) { - Mandate.ParameterNotNull(contentType, "contentType"); - + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); _contentTypeAlias = contentType.Alias; - _contentType = contentType; IsApproved = true; //this cannot be null but can be empty @@ -47,13 +46,12 @@ namespace Umbraco.Core.Models /// Name of the content /// ContentType for the current Content object public Member(string name, IMemberType contentType) - : this(contentType) + : base(name, -1, contentType, new PropertyCollection()) { - Mandate.ParameterNotNull(contentType, "contentType"); - Mandate.ParameterNotNullOrEmpty(name, "name"); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); _contentTypeAlias = contentType.Alias; - _contentType = contentType; IsApproved = true; //this cannot be null but can be empty @@ -72,13 +70,12 @@ namespace Umbraco.Core.Models public Member(string name, string email, string username, IMemberType contentType) : base(name, -1, contentType, new PropertyCollection()) { - Mandate.ParameterNotNull(contentType, "contentType"); - Mandate.ParameterNotNullOrEmpty(name, "name"); - Mandate.ParameterNotNullOrEmpty(email, "email"); - Mandate.ParameterNotNullOrEmpty(username, "username"); + if (string.IsNullOrWhiteSpace(email)) throw new ArgumentNullOrEmptyException(nameof(email)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); + if (string.IsNullOrWhiteSpace(username)) throw new ArgumentNullOrEmptyException(nameof(username)); + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); _contentTypeAlias = contentType.Alias; - _contentType = contentType; _email = email; _username = username; IsApproved = true; @@ -100,10 +97,9 @@ namespace Umbraco.Core.Models public Member(string name, string email, string username, string rawPasswordValue, IMemberType contentType) : base(name, -1, contentType, new PropertyCollection()) { - Mandate.ParameterNotNull(contentType, "contentType"); - + _contentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); _contentTypeAlias = contentType.Alias; - _contentType = contentType; + _email = email; _username = username; _rawPasswordValue = rawPasswordValue; @@ -195,7 +191,7 @@ namespace Umbraco.Core.Models /// /// For security reasons this value should be encrypted, the encryption process is handled by the memberhip provider /// Alias: umbracoMemberPasswordRetrievalAnswer - /// + /// /// Part of the standard properties collection. /// [IgnoreDataMember] @@ -261,7 +257,7 @@ namespace Umbraco.Core.Models { get { - var a = WarnIfPropertyTypeNotFoundOnGet(Constants.Conventions.Member.IsApproved, "IsApproved", + var a = WarnIfPropertyTypeNotFoundOnGet(Constants.Conventions.Member.IsApproved, "IsApproved", //This is the default value if the prop is not found true); if (a.Success == false) return a.Result; @@ -463,7 +459,7 @@ namespace Umbraco.Core.Models /// User key from the Provider. /// /// - /// When using standard umbraco provider this key will + /// When using standard umbraco provider this key will /// correspond to the guid UniqueId/Key. /// Otherwise it will the one available from the asp.net /// membership provider. @@ -478,7 +474,7 @@ namespace Umbraco.Core.Models set { SetPropertyValueAndDetectChanges(value, ref _providerUserKey, Ps.Value.ProviderUserKeySelector); } } - + /// /// Method to call when Entity is being saved /// @@ -500,7 +496,7 @@ namespace Umbraco.Core.Models get { return _contentType; } } - /* Internal experiment - only used for mapping queries. + /* Internal experiment - only used for mapping queries. * Adding these to have first level properties instead of the Properties collection. */ [IgnoreDataMember] @@ -529,7 +525,7 @@ namespace Umbraco.Core.Models + propertyAlias + " configured on your member type in order to use the '" + propertyName - + "' property on the model correctly."); + + "' property on the model correctly."); //if the property doesn't exist, then do the logging and return a failure if (Properties.Contains(propertyAlias) == false) diff --git a/src/Umbraco.Core/Models/RelationType.cs b/src/Umbraco.Core/Models/RelationType.cs index 04ef897c1f..adc5198f9c 100644 --- a/src/Umbraco.Core/Models/RelationType.cs +++ b/src/Umbraco.Core/Models/RelationType.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.Serialization; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Persistence.Mappers; @@ -19,19 +20,19 @@ namespace Umbraco.Core.Models private Guid _parentObjectType; private Guid _childObjectType; - public RelationType(Guid childObjectType, Guid parentObjectType, string @alias) + public RelationType(Guid childObjectType, Guid parentObjectType, string alias) { - Mandate.ParameterNotNullOrEmpty(@alias, "alias"); + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); _childObjectType = childObjectType; _parentObjectType = parentObjectType; _alias = alias; Name = _alias; } - public RelationType(Guid childObjectType, Guid parentObjectType, string @alias, string name) - :this(childObjectType, parentObjectType, @alias) + public RelationType(Guid childObjectType, Guid parentObjectType, string alias, string name) + : this(childObjectType, parentObjectType, alias) { - Mandate.ParameterNotNullOrEmpty(name, "name"); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); Name = name; } diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index 196cfb534a..513ec7d9c5 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Globalization; using System.Linq; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; @@ -75,7 +76,7 @@ namespace Umbraco.Core.Models internal static bool HasPathAccess(string path, int startNodeId, int recycleBinId) { - Mandate.ParameterNotNullOrEmpty(path, "path"); + if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path)); var formattedPath = "," + path + ","; var formattedStartNodeId = "," + startNodeId.ToInvariantString() + ","; diff --git a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs index c333e676e7..b6c5281442 100644 --- a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs +++ b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs @@ -9,6 +9,7 @@ using NPoco; using Semver; using Umbraco.Core.Configuration; using Umbraco.Core.Events; +using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; using Umbraco.Core.Persistence.Migrations.Syntax.IfDatabase; using Umbraco.Core.Persistence.SqlSyntax; @@ -32,18 +33,13 @@ namespace Umbraco.Core.Persistence.Migrations public MigrationRunner(IMigrationCollectionBuilder builder, IMigrationEntryService migrationEntryService, ILogger logger, SemVersion currentVersion, SemVersion targetVersion, string productName, params IMigration[] migrations) { - if (builder == null) throw new ArgumentNullException("builder"); - if (migrationEntryService == null) throw new ArgumentNullException("migrationEntryService"); - if (logger == null) throw new ArgumentNullException("logger"); - if (currentVersion == null) throw new ArgumentNullException("currentVersion"); - if (targetVersion == null) throw new ArgumentNullException("targetVersion"); - Mandate.ParameterNotNullOrEmpty(productName, "productName"); + if (string.IsNullOrWhiteSpace(productName)) throw new ArgumentNullOrEmptyException(nameof(productName)); - _builder = builder; - _migrationEntryService = migrationEntryService; - _logger = logger; - _currentVersion = currentVersion; - _targetVersion = targetVersion; + _builder = builder ?? throw new ArgumentNullException(nameof(builder)); + _migrationEntryService = migrationEntryService ?? throw new ArgumentNullException(nameof(migrationEntryService)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _currentVersion = currentVersion ?? throw new ArgumentNullException(nameof(currentVersion)); + _targetVersion = targetVersion ?? throw new ArgumentNullException(nameof(targetVersion)); _productName = productName; //ensure this is null if there aren't any _migrations = migrations == null || migrations.Length == 0 ? null : migrations; diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs index 960ed8a701..e4f6e524cf 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs @@ -214,18 +214,13 @@ namespace Umbraco.Core.Persistence.Repositories protected override void PersistNewItem(IContentType entity) { - Mandate.That(string.IsNullOrEmpty(entity.Alias) == false, - () => - { - var message = - string.Format( - "ContentType '{0}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.", - entity.Name); - var exception = new Exception(message); - - Logger.Error(message, exception); - throw exception; - }); + if (string.IsNullOrWhiteSpace(entity.Alias)) + { + var m = $"ContentType '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."; + var e = new Exception(m); + Logger.Error(m, e); + throw e; + } ((ContentType)entity).AddingEntity(); diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepositoryBase.cs index dd841752cf..6eb6b74e7c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentTypeRepositoryBase.cs @@ -520,36 +520,24 @@ AND umbracoNode.id <> @id", protected void ValidateAlias(PropertyType pt) { - Mandate.That(string.IsNullOrEmpty(pt.Alias) == false, - () => - { - var message = - string.Format( - "{0} '{1}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.", - "Property Type", - pt.Name); - var exception = new InvalidOperationException(message); - - Logger.Error>(message, exception); - throw exception; - }); + if (string.IsNullOrWhiteSpace(pt.Alias)) + { + var m = $"Property Type '{pt.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."; + var e = new InvalidOperationException(m); + Logger.Error>(m, e); + throw e; + } } protected void ValidateAlias(TEntity entity) { - Mandate.That(string.IsNullOrEmpty(entity.Alias) == false, - () => - { - var message = - string.Format( - "{0} '{1}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.", - typeof(TEntity).Name, - entity.Name); - var exception = new InvalidOperationException(message); - - Logger.Error>(message, exception); - throw exception; - }); + if (string.IsNullOrWhiteSpace(entity.Alias)) + { + var m = $"{typeof(TEntity).Name} '{entity.Name}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias."; + var e = new InvalidOperationException(m); + Logger.Error>(m, e); + throw e; + } } /// @@ -759,7 +747,7 @@ AND umbracoNode.id <> @id", internal static IEnumerable MapMediaTypes(IDatabase db, ISqlSyntaxProvider sqlSyntax, out IDictionary> parentMediaTypeIds) { - Mandate.ParameterNotNull(db, "db"); + if (db == null) throw new ArgumentNullException(nameof(db)); var sql = @"SELECT cmsContentType.pk as ctPk, cmsContentType.alias as ctAlias, cmsContentType.allowAtRoot as ctAllowAtRoot, cmsContentType.description as ctDesc, cmsContentType.icon as ctIcon, cmsContentType.isContainer as ctIsContainer, cmsContentType.nodeId as ctId, cmsContentType.thumbnail as ctThumb, @@ -898,7 +886,7 @@ AND umbracoNode.id <> @id", out IDictionary> associatedTemplates, out IDictionary> parentContentTypeIds) { - Mandate.ParameterNotNull(db, "db"); + if (db == null) throw new ArgumentNullException(nameof(db)); var sql = @"SELECT cmsDocumentType.IsDefault as dtIsDefault, cmsDocumentType.templateNodeId as dtTemplateId, cmsContentType.pk as ctPk, cmsContentType.alias as ctAlias, cmsContentType.allowAtRoot as ctAllowAtRoot, cmsContentType.description as ctDesc, diff --git a/src/Umbraco.Core/Persistence/Repositories/EntityContainerRepository.cs b/src/Umbraco.Core/Persistence/Repositories/EntityContainerRepository.cs index fe26b23143..dd49b22829 100644 --- a/src/Umbraco.Core/Persistence/Repositories/EntityContainerRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/EntityContainerRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using NPoco; using Umbraco.Core.Cache; +using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Rdbms; @@ -165,8 +166,8 @@ namespace Umbraco.Core.Persistence.Repositories { EnsureContainerType(entity); + if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentNullOrEmptyException("entity.Name"); entity.Name = entity.Name.Trim(); - Mandate.ParameterNotNullOrEmpty(entity.Name, "entity.Name"); // guard against duplicates var nodeDto = Database.FirstOrDefault(Sql().SelectAll() @@ -227,7 +228,7 @@ namespace Umbraco.Core.Persistence.Repositories EnsureContainerType(entity); entity.Name = entity.Name.Trim(); - Mandate.ParameterNotNullOrEmpty(entity.Name, "entity.Name"); + if (string.IsNullOrWhiteSpace(entity.Name)) throw new ArgumentNullOrEmptyException("entity.Name"); // find container to update var nodeDto = Database.FirstOrDefault(Sql().SelectAll() diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs index b43cf9649c..3188cac309 100644 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/ParameterEditorAttribute.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Exceptions; namespace Umbraco.Core.PropertyEditors { @@ -11,9 +12,9 @@ namespace Umbraco.Core.PropertyEditors { public ParameterEditorAttribute(string alias, string name, string editorView) { - Mandate.ParameterNotNullOrEmpty(alias, "alias"); - Mandate.ParameterNotNullOrEmpty(name, "name"); - Mandate.ParameterNotNullOrEmpty(editorView, "editorView"); + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); + if (string.IsNullOrWhiteSpace(editorView)) throw new ArgumentNullOrEmptyException(nameof(editorView)); Alias = alias; Name = name; @@ -22,16 +23,15 @@ namespace Umbraco.Core.PropertyEditors public ParameterEditorAttribute(string alias, string name) { - Mandate.ParameterNotNullOrEmpty(alias, "id"); - Mandate.ParameterNotNullOrEmpty(name, "name"); + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); Alias = alias; Name = name; } - - public string Alias { get; private set; } - public string Name { get; private set; } - public string EditorView { get; private set; } + public string Alias { get; } + public string Name { get; } + public string EditorView { get; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs index 5777eb1dc0..9d14b3ac39 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorAttribute.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Exceptions; namespace Umbraco.Core.PropertyEditors { @@ -10,9 +11,9 @@ namespace Umbraco.Core.PropertyEditors { public PropertyEditorAttribute(string alias, string name, string editorView) { - Mandate.ParameterNotNullOrEmpty(alias, "alias"); - Mandate.ParameterNotNullOrEmpty(name, "name"); - Mandate.ParameterNotNullOrEmpty(editorView, "editorView"); + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); + if (string.IsNullOrWhiteSpace(editorView)) throw new ArgumentNullOrEmptyException(nameof(editorView)); Alias = alias; Name = name; @@ -26,8 +27,8 @@ namespace Umbraco.Core.PropertyEditors public PropertyEditorAttribute(string alias, string name) { - Mandate.ParameterNotNullOrEmpty(alias, "id"); - Mandate.ParameterNotNullOrEmpty(name, "name"); + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); Alias = alias; Name = name; @@ -40,10 +41,10 @@ namespace Umbraco.Core.PropertyEditors public PropertyEditorAttribute(string alias, string name, string valueType, string editorView) { - Mandate.ParameterNotNullOrEmpty(alias, "alias"); - Mandate.ParameterNotNullOrEmpty(name, "name"); - Mandate.ParameterNotNullOrEmpty(valueType, "valueType"); - Mandate.ParameterNotNullOrEmpty(editorView, "editorView"); + if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentNullOrEmptyException(nameof(alias)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); + if (string.IsNullOrWhiteSpace(valueType)) throw new ArgumentNullOrEmptyException(nameof(valueType)); + if (string.IsNullOrWhiteSpace(editorView)) throw new ArgumentNullOrEmptyException(nameof(editorView)); Alias = alias; Name = name; diff --git a/src/Umbraco.Core/Services/LocalizedTextService.cs b/src/Umbraco.Core/Services/LocalizedTextService.cs index 84ff3b745b..5eb2c7ecb0 100644 --- a/src/Umbraco.Core/Services/LocalizedTextService.cs +++ b/src/Umbraco.Core/Services/LocalizedTextService.cs @@ -50,16 +50,14 @@ namespace Umbraco.Core.Services /// /// public LocalizedTextService(IDictionary>> source, ILogger logger) - { - if (source == null) throw new ArgumentNullException("source"); - if (logger == null) throw new ArgumentNullException("logger"); - _dictionarySource = source; - _logger = logger; + { + _dictionarySource = source ?? throw new ArgumentNullException(nameof(source)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public string Localize(string key, CultureInfo culture, IDictionary tokens = null) { - Mandate.ParameterNotNull(culture, "culture"); + if (culture == null) throw new ArgumentNullException(nameof(culture)); //TODO: Hack, see notes on ConvertToSupportedCultureWithRegionCode culture = ConvertToSupportedCultureWithRegionCode(culture); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index eb1b7b0b15..1ac25a0c3f 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -438,7 +438,6 @@ - diff --git a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs index 7802ddc438..a2e0ff6fb5 100644 --- a/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs +++ b/src/Umbraco.Core/Xml/UmbracoXPathPathSyntaxParser.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Umbraco.Core.Exceptions; namespace Umbraco.Core.Xml { @@ -36,9 +37,9 @@ namespace Umbraco.Core.Xml // allowed 'inline', not just at the beginning... whether or not we want to support that is up // for discussion. - Mandate.ParameterNotNullOrEmpty(xpathExpression, "xpathExpression"); - Mandate.ParameterNotNull(getPath, "getPath"); - Mandate.ParameterNotNull(publishedContentExists, "publishedContentExists"); + if (string.IsNullOrWhiteSpace(xpathExpression)) throw new ArgumentNullOrEmptyException(nameof(xpathExpression)); + if (getPath == null) throw new ArgumentNullException(nameof(getPath)); + if (publishedContentExists == null) throw new ArgumentNullException(nameof(publishedContentExists)); //no need to parse it if (xpathExpression.StartsWith("$") == false) diff --git a/src/Umbraco.Web/GridTemplateExtensions.cs b/src/Umbraco.Web/GridTemplateExtensions.cs index 25fbc87a5b..069aa6c483 100644 --- a/src/Umbraco.Web/GridTemplateExtensions.cs +++ b/src/Umbraco.Web/GridTemplateExtensions.cs @@ -10,6 +10,7 @@ using System.Web.Mvc; using Umbraco.Web.Templates; using System.IO; using System.Web.Routing; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Mvc; @@ -34,14 +35,14 @@ namespace Umbraco.Web public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent contentItem, string propertyAlias) { - Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias"); + if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias)); return html.GetGridHtml(contentItem, propertyAlias, "bootstrap3"); } public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedContent contentItem, string propertyAlias, string framework) { - Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias"); + if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias)); var view = "Grid/" + framework; var prop = contentItem.GetProperty(propertyAlias); @@ -68,13 +69,13 @@ namespace Umbraco.Web } public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, HtmlHelper html, string propertyAlias) { - Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias"); + if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias)); return GetGridHtml(contentItem, html, propertyAlias, "bootstrap3"); } public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, HtmlHelper html, string propertyAlias, string framework) { - Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias"); + if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias)); var view = "Grid/" + framework; var prop = contentItem.GetProperty(propertyAlias); @@ -107,7 +108,7 @@ namespace Umbraco.Web [Obsolete("This should not be used, GetGridHtml methods accepting HtmlHelper as a parameter or GetGridHtml extensions on HtmlHelper should be used instead")] public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias) { - Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias"); + if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias)); return GetGridHtml(contentItem, propertyAlias, "bootstrap3"); } @@ -115,7 +116,7 @@ namespace Umbraco.Web [Obsolete("This should not be used, GetGridHtml methods accepting HtmlHelper as a parameter or GetGridHtml extensions on HtmlHelper should be used instead")] public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias, string framework) { - Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias"); + if (string.IsNullOrWhiteSpace(propertyAlias)) throw new ArgumentNullOrEmptyException(nameof(propertyAlias)); var prop = contentItem.GetProperty(propertyAlias); if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias); diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index dc0758531e..2e0b176061 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -9,6 +9,7 @@ using System.Web.Mvc.Html; using System.Web.Routing; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Exceptions; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; @@ -172,8 +173,8 @@ namespace Umbraco.Web /// public static IHtmlString Action(this HtmlHelper htmlHelper, string actionName, Type surfaceType) { - Mandate.ParameterNotNull(surfaceType, "surfaceType"); - Mandate.ParameterNotNullOrEmpty(actionName, "actionName"); + if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType)); + if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName)); var routeVals = new RouteValueDictionary(new {area = ""}); @@ -412,8 +413,8 @@ namespace Umbraco.Web IDictionary htmlAttributes, FormMethod method) { - Mandate.ParameterNotNullOrEmpty(action, "action"); - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); + if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action)); + if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes, method); } @@ -431,10 +432,10 @@ namespace Umbraco.Web object additionalRouteVals, IDictionary htmlAttributes) { - Mandate.ParameterNotNullOrEmpty(action, "action"); - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); + if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action)); + if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); - return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes); + return html.BeginUmbracoForm(action, controllerName, "", additionalRouteVals, htmlAttributes); } /// @@ -632,8 +633,8 @@ namespace Umbraco.Web IDictionary htmlAttributes, FormMethod method) { - Mandate.ParameterNotNullOrEmpty(action, "action"); - Mandate.ParameterNotNull(surfaceType, "surfaceType"); + if (string.IsNullOrWhiteSpace(action)) throw new ArgumentNullOrEmptyException(nameof(action)); + if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType)); var area = ""; @@ -744,8 +745,8 @@ namespace Umbraco.Web IDictionary htmlAttributes, FormMethod method) { - Mandate.ParameterNotNullOrEmpty(action, "action"); - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); + if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action)); + if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); var formAction = UmbracoContext.Current.OriginalRequestUrl.PathAndQuery; return html.RenderForm(formAction, method, htmlAttributes, controllerName, action, area, additionalRouteVals); diff --git a/src/Umbraco.Web/HttpUrlHelperExtensions.cs b/src/Umbraco.Web/HttpUrlHelperExtensions.cs index e4cfee9989..436f987541 100644 --- a/src/Umbraco.Web/HttpUrlHelperExtensions.cs +++ b/src/Umbraco.Web/HttpUrlHelperExtensions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Linq.Expressions; using System.Web.Http.Routing; using Umbraco.Core; +using Umbraco.Core.Exceptions; using Umbraco.Web.Composing; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; @@ -52,8 +53,8 @@ namespace Umbraco.Web /// public static string GetUmbracoApiService(this UrlHelper url, string actionName, Type apiControllerType, object id = null) { - Mandate.ParameterNotNullOrEmpty(actionName, "actionName"); - Mandate.ParameterNotNull(apiControllerType, "apiControllerType"); + if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName)); + if (apiControllerType == null) throw new ArgumentNullException(nameof(apiControllerType)); var area = ""; @@ -94,8 +95,8 @@ namespace Umbraco.Web /// public static string GetUmbracoApiService(this UrlHelper url, string actionName, string controllerName, string area, object id = null) { - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); - Mandate.ParameterNotNullOrEmpty(actionName, "actionName"); + if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName)); + if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); string routeName; if (area.IsNullOrWhiteSpace()) diff --git a/src/Umbraco.Web/Models/Trees/ActionMenuItemAttribute.cs b/src/Umbraco.Web/Models/Trees/ActionMenuItemAttribute.cs index f27cc65eda..1bc9d68051 100644 --- a/src/Umbraco.Web/Models/Trees/ActionMenuItemAttribute.cs +++ b/src/Umbraco.Web/Models/Trees/ActionMenuItemAttribute.cs @@ -1,5 +1,5 @@ using System; -using Umbraco.Core; +using Umbraco.Core.Exceptions; namespace Umbraco.Web.Models.Trees { @@ -16,8 +16,8 @@ namespace Umbraco.Web.Models.Trees /// public ActionMenuItemAttribute(string serviceName, string methodName) { - Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName"); - Mandate.ParameterNotNullOrEmpty(methodName, "methodName"); + if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName)); + if (string.IsNullOrWhiteSpace(methodName)) throw new ArgumentNullOrEmptyException(nameof(methodName)); MethodName = methodName; ServiceName = serviceName; } @@ -28,12 +28,12 @@ namespace Umbraco.Web.Models.Trees /// public ActionMenuItemAttribute(string serviceName) { - Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName"); + if (string.IsNullOrWhiteSpace(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName)); MethodName = ""; ServiceName = serviceName; } - public string MethodName { get; private set; } - public string ServiceName { get; private set; } + public string MethodName { get; } + public string ServiceName { get; } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Models/Trees/TreeNode.cs b/src/Umbraco.Web/Models/Trees/TreeNode.cs index 5c8d36dd6b..70c193665b 100644 --- a/src/Umbraco.Web/Models/Trees/TreeNode.cs +++ b/src/Umbraco.Web/Models/Trees/TreeNode.cs @@ -3,6 +3,7 @@ using Umbraco.Core.IO; using System.Collections.Generic; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Exceptions; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Trees @@ -25,8 +26,8 @@ namespace Umbraco.Web.Models.Trees /// internal TreeNode(string nodeId, string parentId, string getChildNodesUrl, string menuUrl) { - Mandate.ParameterNotNullOrEmpty(nodeId, "nodeId"); - + if (string.IsNullOrWhiteSpace(nodeId)) throw new ArgumentNullOrEmptyException(nameof(nodeId)); + Id = nodeId; ParentId = parentId; ChildNodesUrl = getChildNodesUrl; diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index f1c27ffb96..4f6d928c23 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -6,6 +6,7 @@ using System.Web.Routing; using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Exceptions; using Umbraco.Web.WebApi; namespace Umbraco.Web.Mvc @@ -44,12 +45,12 @@ namespace Umbraco.Web.Mvc bool isMvc = true, string areaPathPrefix = "") { - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); - Mandate.ParameterNotNull(controllerSuffixName, "controllerSuffixName"); - - Mandate.ParameterNotNull(controllerType, "controllerType"); - Mandate.ParameterNotNull(routes, "routes"); - Mandate.ParameterNotNull(defaultId, "defaultId"); + if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); + if (controllerSuffixName == null) throw new ArgumentNullException(nameof(controllerSuffixName)); + + if (controllerType == null) throw new ArgumentNullException(nameof(controllerType)); + if (routes == null) throw new ArgumentNullException(nameof(routes)); + if (defaultId == null) throw new ArgumentNullException(nameof(defaultId)); var umbracoArea = GlobalSettings.UmbracoMvcArea; diff --git a/src/Umbraco.Web/Security/Identity/AuthenticationOptionsExtensions.cs b/src/Umbraco.Web/Security/Identity/AuthenticationOptionsExtensions.cs index dc48aba336..dd04ce7392 100644 --- a/src/Umbraco.Web/Security/Identity/AuthenticationOptionsExtensions.cs +++ b/src/Umbraco.Web/Security/Identity/AuthenticationOptionsExtensions.cs @@ -4,6 +4,7 @@ using Microsoft.Owin.Security; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Composing; +using Umbraco.Core.Exceptions; namespace Umbraco.Web.Security.Identity { @@ -75,7 +76,7 @@ namespace Umbraco.Web.Security.Identity /// public static void ForUmbracoBackOffice(this AuthenticationOptions options, string style, string icon, string callbackPath = null) { - Mandate.ParameterNotNullOrEmpty(options.AuthenticationType, "options.AuthenticationType"); + if (string.IsNullOrEmpty(options.AuthenticationType)) throw new ArgumentNullOrEmptyException("options.AuthenticationType"); //Ensure the prefix is set if (options.AuthenticationType.StartsWith(Constants.Security.BackOfficeExternalAuthenticationTypePrefix) == false) diff --git a/src/Umbraco.Web/Security/Identity/ExternalSignInAutoLinkOptions.cs b/src/Umbraco.Web/Security/Identity/ExternalSignInAutoLinkOptions.cs index 832f0b3a30..32dd13c209 100644 --- a/src/Umbraco.Web/Security/Identity/ExternalSignInAutoLinkOptions.cs +++ b/src/Umbraco.Web/Security/Identity/ExternalSignInAutoLinkOptions.cs @@ -3,6 +3,7 @@ using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models.Identity; namespace Umbraco.Web.Security.Identity @@ -18,7 +19,7 @@ namespace Umbraco.Web.Security.Identity string[] defaultAllowedSections = null, string defaultCulture = null) { - Mandate.ParameterNotNullOrEmpty(defaultUserType, "defaultUserType"); + if (string.IsNullOrEmpty(defaultUserType)) throw new ArgumentNullOrEmptyException(nameof(defaultUserType)); _defaultUserType = defaultUserType; _defaultAllowedSections = defaultAllowedSections ?? new[] { "content", "media" }; diff --git a/src/Umbraco.Web/UmbracoComponentRenderer.cs b/src/Umbraco.Web/UmbracoComponentRenderer.cs index 5ce2c1d2a0..af37b2f066 100644 --- a/src/Umbraco.Web/UmbracoComponentRenderer.cs +++ b/src/Umbraco.Web/UmbracoComponentRenderer.cs @@ -10,6 +10,7 @@ using Umbraco.Web.Templates; using umbraco; using System.Collections.Generic; using umbraco.presentation.templateControls; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; using Umbraco.Web.Macros; @@ -217,8 +218,8 @@ namespace Umbraco.Web //TODO: commented out until as it is not implemented by umbraco:item yet //,string formatString = "") { - Mandate.ParameterNotNull(currentPage, "currentPage"); - Mandate.ParameterNotNullOrEmpty(fieldAlias, "fieldAlias"); + if (currentPage == null) throw new ArgumentNullException(nameof(currentPage)); + if (string.IsNullOrEmpty(fieldAlias)) throw new ArgumentNullOrEmptyException(nameof(fieldAlias)); //TODO: This is real nasty and we should re-write the 'item' and 'ItemRenderer' class but si fine for now diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 68619a3c99..0e0fa4d93d 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -15,6 +15,7 @@ using System.IO; using System.Linq; using System.Web.Mvc; using Umbraco.Core.Cache; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; @@ -1030,9 +1031,9 @@ namespace Umbraco.Web /// internal static string CreateEncryptedRouteString(string controllerName, string controllerAction, string area, object additionalRouteVals = null) { - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); - Mandate.ParameterNotNullOrEmpty(controllerAction, "controllerAction"); - Mandate.ParameterNotNull(area, "area"); + if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); + if (string.IsNullOrEmpty(controllerAction)) throw new ArgumentNullOrEmptyException(nameof(controllerAction)); + if (area == null) throw new ArgumentNullException(nameof(area)); //need to create a params string as Base64 to put into our hidden field to use during the routes var surfaceRouteParams = $"c={HttpUtility.UrlEncode(controllerName)}&a={HttpUtility.UrlEncode(controllerAction)}&ar={area}"; diff --git a/src/Umbraco.Web/UrlHelperExtensions.cs b/src/Umbraco.Web/UrlHelperExtensions.cs index dd381658ae..706b8359ae 100644 --- a/src/Umbraco.Web/UrlHelperExtensions.cs +++ b/src/Umbraco.Web/UrlHelperExtensions.cs @@ -8,6 +8,7 @@ using System.Web.Routing; using ClientDependency.Core.Config; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Exceptions; using Umbraco.Web.Composing; using Umbraco.Web.Mvc; using Umbraco.Web.WebApi; @@ -92,8 +93,8 @@ namespace Umbraco.Web /// public static string GetUmbracoApiService(this UrlHelper url, string actionName, Type apiControllerType, RouteValueDictionary routeVals = null) { - Mandate.ParameterNotNullOrEmpty(actionName, "actionName"); - Mandate.ParameterNotNull(apiControllerType, "apiControllerType"); + if (string.IsNullOrEmpty(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName)); + if (apiControllerType == null) throw new ArgumentNullException(nameof(apiControllerType)); var area = ""; @@ -134,8 +135,8 @@ namespace Umbraco.Web /// public static string GetUmbracoApiService(this UrlHelper url, string actionName, string controllerName, string area, RouteValueDictionary routeVals = null) { - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); - Mandate.ParameterNotNullOrEmpty(actionName, "actionName"); + if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); + if (string.IsNullOrEmpty(actionName)) throw new ArgumentNullOrEmptyException(nameof(actionName)); if (routeVals == null) { diff --git a/src/Umbraco.Web/UrlHelperRenderExtensions.cs b/src/Umbraco.Web/UrlHelperRenderExtensions.cs index ef923d1465..04e86fce79 100644 --- a/src/Umbraco.Web/UrlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/UrlHelperRenderExtensions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Core; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; @@ -266,8 +267,8 @@ namespace Umbraco.Web /// public static string SurfaceAction(this UrlHelper url, string action, string controllerName, string area, object additionalRouteVals) { - Mandate.ParameterNotNullOrEmpty(action, "action"); - Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); + if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action)); + if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); var encryptedRoute = UmbracoHelper.CreateEncryptedRouteString(controllerName, action, area, additionalRouteVals); @@ -297,8 +298,8 @@ namespace Umbraco.Web /// public static string SurfaceAction(this UrlHelper url, string action, Type surfaceType, object additionalRouteVals) { - Mandate.ParameterNotNullOrEmpty(action, "action"); - Mandate.ParameterNotNull(surfaceType, "surfaceType"); + if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action)); + if (surfaceType == null) throw new ArgumentNullException(nameof(surfaceType)); var area = ""; diff --git a/src/Umbraco.Web/WebApi/CustomDateTimeConvertor.cs b/src/Umbraco.Web/WebApi/CustomDateTimeConvertor.cs index 00216e2ece..94ba3047ed 100644 --- a/src/Umbraco.Web/WebApi/CustomDateTimeConvertor.cs +++ b/src/Umbraco.Web/WebApi/CustomDateTimeConvertor.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Umbraco.Core; +using Umbraco.Core.Exceptions; namespace Umbraco.Web.WebApi { @@ -14,7 +15,7 @@ namespace Umbraco.Web.WebApi public CustomDateTimeConvertor(string dateTimeFormat) { - Mandate.ParameterNotNullOrEmpty(dateTimeFormat, "dateTimeFormat"); + if (string.IsNullOrEmpty(dateTimeFormat)) throw new ArgumentNullOrEmptyException(nameof(dateTimeFormat)); _dateTimeFormat = dateTimeFormat; } diff --git a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs index b9a426e253..a0ab720e64 100644 --- a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs @@ -1,18 +1,10 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; using System.Web.Http; using System.Web.Http.Controllers; using System.Web.Http.Filters; -using Umbraco.Core; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Services; +using Umbraco.Core.Exceptions; using Umbraco.Web.Composing; using Umbraco.Web.Editors; -using Umbraco.Web.Models.ContentEditing; using Umbraco.Web._Legacy.Actions; namespace Umbraco.Web.WebApi.Filters @@ -43,7 +35,7 @@ namespace Umbraco.Web.WebApi.Filters public EnsureUserPermissionForContentAttribute(string paramName) { - Mandate.ParameterNotNullOrEmpty(paramName, "paramName"); + if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName)); _paramName = paramName; _permissionToCheck = ActionBrowse.Instance.Letter; } @@ -53,10 +45,7 @@ namespace Umbraco.Web.WebApi.Filters _permissionToCheck = permissionToCheck; } - public override bool AllowMultiple - { - get { return true; } - } + public override bool AllowMultiple => true; public override void OnActionExecuting(HttpActionContext actionContext) { @@ -69,7 +58,7 @@ namespace Umbraco.Web.WebApi.Filters int nodeId; if (_nodeId.HasValue == false) { - var parts = _paramName.Split(new char[] {'.'}, StringSplitOptions.RemoveEmptyEntries); + var parts = _paramName.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries); if (actionContext.ActionArguments[parts[0]] == null) { diff --git a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs index f99f1cb32f..95af3f89e3 100644 --- a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs @@ -1,12 +1,10 @@ using System; -using System.Collections.Generic; using System.Web.Http; using System.Web.Http.Controllers; using System.Web.Http.Filters; using Umbraco.Core; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models; -using Umbraco.Core.Models.Membership; -using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.Editors; @@ -40,21 +38,18 @@ namespace Umbraco.Web.WebApi.Filters public EnsureUserPermissionForMediaAttribute(string paramName) { - Mandate.ParameterNotNullOrEmpty(paramName, "paramName"); + if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName)); _paramName = paramName; } // fixme v8 guess this is not used anymore, source is ignored?! public EnsureUserPermissionForMediaAttribute(string paramName, DictionarySource source) { - Mandate.ParameterNotNullOrEmpty(paramName, "paramName"); + if (string.IsNullOrEmpty(paramName)) throw new ArgumentNullOrEmptyException(nameof(paramName)); _paramName = paramName; } - public override bool AllowMultiple - { - get { return true; } - } + public override bool AllowMultiple => true; private int GetNodeIdFromParameter(object parameterValue) { diff --git a/src/Umbraco.Web/WebApi/Filters/OutgoingDateTimeFormatAttribute.cs b/src/Umbraco.Web/WebApi/Filters/OutgoingDateTimeFormatAttribute.cs index 4c4d831241..73532dd67b 100644 --- a/src/Umbraco.Web/WebApi/Filters/OutgoingDateTimeFormatAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/OutgoingDateTimeFormatAttribute.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Net.Http.Formatting; using System.Web.Http.Controllers; using Umbraco.Core; +using Umbraco.Core.Exceptions; namespace Umbraco.Web.WebApi.Filters { @@ -19,7 +20,7 @@ namespace Umbraco.Web.WebApi.Filters /// public OutgoingDateTimeFormatAttribute(string format) { - Mandate.ParameterNotNullOrEmpty(format, "format"); + if (string.IsNullOrEmpty(format)) throw new ArgumentNullOrEmptyException(nameof(format)); _format = format; } diff --git a/src/Umbraco.Web/_Legacy/Actions/LegacyActionMenuItemAttribute.cs b/src/Umbraco.Web/_Legacy/Actions/LegacyActionMenuItemAttribute.cs index c3b785d47d..173cf9088d 100644 --- a/src/Umbraco.Web/_Legacy/Actions/LegacyActionMenuItemAttribute.cs +++ b/src/Umbraco.Web/_Legacy/Actions/LegacyActionMenuItemAttribute.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core; +using Umbraco.Core.Exceptions; namespace Umbraco.Web._Legacy.Actions { @@ -20,8 +21,9 @@ namespace Umbraco.Web._Legacy.Actions /// public LegacyActionMenuItemAttribute(string serviceName, string methodName) { - Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName"); - Mandate.ParameterNotNullOrEmpty(methodName, "methodName"); + if (string.IsNullOrEmpty(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName)); + if (string.IsNullOrEmpty(methodName)) throw new ArgumentNullOrEmptyException(nameof(methodName)); + MethodName = methodName; ServiceName = serviceName; } @@ -32,12 +34,13 @@ namespace Umbraco.Web._Legacy.Actions /// public LegacyActionMenuItemAttribute(string serviceName) { - Mandate.ParameterNotNullOrEmpty(serviceName, "serviceName"); + if (string.IsNullOrEmpty(serviceName)) throw new ArgumentNullOrEmptyException(nameof(serviceName)); + MethodName = ""; ServiceName = serviceName; } - public string MethodName { get; private set; } - public string ServiceName { get; private set; } + public string MethodName { get; } + public string ServiceName { get; } } } \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/member/Member.cs b/src/umbraco.cms/businesslogic/member/Member.cs index 2692ebd477..6fdb93b267 100644 --- a/src/umbraco.cms/businesslogic/member/Member.cs +++ b/src/umbraco.cms/businesslogic/member/Member.cs @@ -17,6 +17,7 @@ using System.Text; using System.Security.Cryptography; using System.Linq; using Umbraco.Core.Composing; +using Umbraco.Core.Exceptions; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Core.Xml; @@ -255,7 +256,7 @@ namespace umbraco.cms.businesslogic.member /// The member with the specified loginname - null if no Member with the login exists public static Member GetMemberFromLoginName(string loginName) { - Mandate.ParameterNotNullOrEmpty(loginName, "loginName"); + if (string.IsNullOrEmpty(loginName)) throw new ArgumentNullOrEmptyException(nameof(loginName)); var found = Current.Services.MemberService.GetByUsername(loginName); if (found == null) return null; @@ -374,7 +375,7 @@ namespace umbraco.cms.businesslogic.member /// True if the member exists public static bool IsMember(string loginName) { - Mandate.ParameterNotNullOrEmpty(loginName, "loginName"); + if (string.IsNullOrWhiteSpace(loginName)) throw new ArgumentNullOrEmptyException(nameof(loginName)); return Current.Services.MemberService.Exists(loginName); }