diff --git a/src/Umbraco.Core/Configuration/Models/CharItem.cs b/src/Umbraco.Core/Configuration/Models/CharItem.cs index e269e0a83e..a74b0c0a8b 100644 --- a/src/Umbraco.Core/Configuration/Models/CharItem.cs +++ b/src/Umbraco.Core/Configuration/Models/CharItem.cs @@ -7,11 +7,11 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// The character to replace /// - public string Char { get; set; } + public string Char { get; set; } = null!; /// /// The replacement character /// - public string Replacement { get; set; } + public string Replacement { get; set; } = null!; } } diff --git a/src/Umbraco.Core/Configuration/Models/ContentDashboardSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentDashboardSettings.cs index 768f7c2088..19d636ed34 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentDashboardSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentDashboardSettings.cs @@ -31,6 +31,6 @@ namespace Umbraco.Cms.Core.Configuration /// Gets the allowed addresses to retrieve data for the content dashboard. /// /// The URLs. - public string[] ContentDashboardUrlAllowlist { get; set; } + public string[]? ContentDashboardUrlAllowlist { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index f9922459c3..0cd5ca5670 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -113,7 +113,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// If the value is a virtual path, it's resolved relative to the webroot. /// - public string UmbracoMediaPhysicalRootPath { get; set; } + public string UmbracoMediaPhysicalRootPath { get; set; } = null!; /// /// Gets or sets a value indicating whether to install the database when it is missing. diff --git a/src/Umbraco.Core/Configuration/Models/HelpPageSettings.cs b/src/Umbraco.Core/Configuration/Models/HelpPageSettings.cs index 3bd518b37e..b608b5c155 100644 --- a/src/Umbraco.Core/Configuration/Models/HelpPageSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HelpPageSettings.cs @@ -6,6 +6,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets the allowed addresses to retrieve data for the content dashboard. /// - public string[] HelpPageUrlAllowList { get; set; } + public string[]? HelpPageUrlAllowList { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index cd62655f58..8f5f47a566 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -35,6 +35,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value specifying the name of the site. /// - public string SiteName { get; set; } + public string? SiteName { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs index 54db8d42ed..45a9bc98ed 100644 --- a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -85,18 +85,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Add additional character replacements, or override defaults /// - public IEnumerable UserDefinedCharCollection { get; set; } - - [Obsolete("Use CharItem in the Umbraco.Cms.Core.Configuration.Models namespace instead. Scheduled for removal in V10.")] - public class CharItem : IChar - { - /// - [Required] - public string Char { get; set; } = null!; - - /// - [Required] - public string Replacement { get; set; } = null!; - } + public IEnumerable? UserDefinedCharCollection { get; set; } } } diff --git a/src/Umbraco.Core/Editors/BackOfficePreviewModel.cs b/src/Umbraco.Core/Editors/BackOfficePreviewModel.cs index 74cc590e83..d8bd73aca9 100644 --- a/src/Umbraco.Core/Editors/BackOfficePreviewModel.cs +++ b/src/Umbraco.Core/Editors/BackOfficePreviewModel.cs @@ -16,6 +16,6 @@ namespace Umbraco.Cms.Core.Editors public IEnumerable Languages { get; } public bool DisableDevicePreview => _features.Disabled.DisableDevicePreview; - public string PreviewExtendedHeaderView => _features.Enabled.PreviewExtendedView; + public string? PreviewExtendedHeaderView => _features.Enabled.PreviewExtendedView; } } diff --git a/src/Umbraco.Core/Events/MacroErrorEventArgs.cs b/src/Umbraco.Core/Events/MacroErrorEventArgs.cs index b1558482a8..8d0e8dbfe1 100644 --- a/src/Umbraco.Core/Events/MacroErrorEventArgs.cs +++ b/src/Umbraco.Core/Events/MacroErrorEventArgs.cs @@ -9,22 +9,22 @@ namespace Umbraco.Cms.Core.Events /// /// Name of the faulting macro. /// - public string Name { get; set; } + public string? Name { get; set; } /// /// Alias of the faulting macro. /// - public string Alias { get; set; } + public string? Alias { get; set; } /// /// Filename, file path, fully qualified class name, or other key used by the macro engine to do it's processing of the faulting macro. /// - public string MacroSource { get; set; } + public string? MacroSource { get; set; } /// /// Exception raised. /// - public Exception Exception { get; set; } + public Exception? Exception { get; set; } /// /// Gets or sets the desired behaviour when a matching macro causes an error. See @@ -37,6 +37,6 @@ namespace Umbraco.Cms.Core.Events /// /// The HTML code to display when Behavior is Content. /// - public string Html { get; set; } + public string? Html { get; set; } } } diff --git a/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs b/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs index 7b077b73a5..c850583834 100644 --- a/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs +++ b/src/Umbraco.Core/Extensions/ClaimsIdentityExtensions.cs @@ -17,7 +17,7 @@ namespace Umbraco.Extensions { var strId = identity.GetUserId(); var converted = strId.TryConvertTo(); - return converted.ResultOr(default); + return converted.Result ?? default; } /// @@ -62,11 +62,11 @@ namespace Umbraco.Extensions return username; } - public static string GetEmail(this IIdentity identity) + public static string? GetEmail(this IIdentity identity) { if (identity == null) throw new ArgumentNullException(nameof(identity)); - string email = null; + string? email = null; if (identity is ClaimsIdentity claimsIdentity) { email = claimsIdentity.FindFirstValue(ClaimTypes.Email); diff --git a/src/Umbraco.Core/Extensions/ContentExtensions.cs b/src/Umbraco.Core/Extensions/ContentExtensions.cs index 184957fdf4..0bd1e36d9e 100644 --- a/src/Umbraco.Core/Extensions/ContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/ContentExtensions.cs @@ -90,7 +90,7 @@ namespace Umbraco.Extensions /// public static void SanitizeEntityPropertiesForXmlStorage(this IContentBase entity) { - entity.Name = entity.Name.ToValidXmlString(); + entity.Name = entity.Name?.ToValidXmlString(); foreach (var property in entity.Properties) { foreach (var propertyValue in property.Values) @@ -238,7 +238,7 @@ namespace Umbraco.Extensions { //get the properties for the current tab return content.Properties - .Where(property => propertyGroup.PropertyTypes + .Where(property => propertyGroup.PropertyTypes is not null && propertyGroup.PropertyTypes .Select(propertyType => propertyType.Id) .Contains(property.PropertyTypeId)); } diff --git a/src/Umbraco.Core/Extensions/ObjectExtensions.cs b/src/Umbraco.Core/Extensions/ObjectExtensions.cs index ec2257e637..1265052308 100644 --- a/src/Umbraco.Core/Extensions/ObjectExtensions.cs +++ b/src/Umbraco.Core/Extensions/ObjectExtensions.cs @@ -538,10 +538,8 @@ namespace Umbraco.Extensions { return "[{0}]".InvariantFormat(obj); } - if (obj is IEnumerable) + if (obj is IEnumerable enumerable) { - var enumerable = (obj as IEnumerable); - var items = (from object enumItem in enumerable let value = GetEnumPropertyDebugString(enumItem, levels) where value != null select value).Take(10).ToList(); return items.Any() diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index aaae931727..0e0c77f811 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -166,7 +166,7 @@ namespace Umbraco.Extensions } var template = fileService.GetTemplate(content.TemplateId.Value); - return template.Alias ?? string.Empty; + return template?.Alias ?? string.Empty; } public static bool IsAllowedTemplate(this IPublishedContent content, IContentTypeService contentTypeService, @@ -511,7 +511,7 @@ namespace Umbraco.Extensions /// The content. /// The ancestor of the content. /// This method is here for consistency purposes but does not make much sense. - public static IPublishedContent Ancestor(this IPublishedContent content) + public static IPublishedContent? Ancestor(this IPublishedContent content) { return content.Parent; } @@ -641,7 +641,7 @@ namespace Umbraco.Extensions /// The content. /// Indicates whether the content should be included. /// Enumerates bottom-up ie walking up the tree (parent, grand-parent, etc). - internal static IEnumerable EnumerateAncestors(this IPublishedContent content, bool orSelf) + internal static IEnumerable EnumerateAncestors(this IPublishedContent? content, bool orSelf) { if (content == null) throw new ArgumentNullException(nameof(content)); if (orSelf) yield return content; @@ -819,7 +819,7 @@ namespace Umbraco.Extensions public static IPublishedContent? Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { - return content.Children(variationContextAccessor, culture).FirstOrDefault(); + return content.Children(variationContextAccessor, culture)?.FirstOrDefault(); } public static IPublishedContent? Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) @@ -881,16 +881,23 @@ namespace Umbraco.Extensions if (content == null) throw new ArgumentNullException(nameof(content)); if (orSelf) yield return content; - foreach (var desc in content.Children(variationContextAccessor, culture).SelectMany(x => x.EnumerateDescendants(variationContextAccessor, culture))) - yield return desc; + var children = content.Children(variationContextAccessor, culture); + if (children is not null) + { + foreach (var desc in children.SelectMany(x => x.EnumerateDescendants(variationContextAccessor, culture))) + yield return desc; + } } internal static IEnumerable EnumerateDescendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { yield return content; - - foreach (var desc in content.Children(variationContextAccessor, culture).SelectMany(x => x.EnumerateDescendants(variationContextAccessor, culture))) - yield return desc; + var children = content.Children(variationContextAccessor, culture); + if (children is not null) + { + foreach (var desc in children.SelectMany(x => x.EnumerateDescendants(variationContextAccessor, culture))) + yield return desc; + } } #endregion @@ -920,7 +927,7 @@ namespace Umbraco.Extensions /// However, if an empty string is specified only invariant children are returned. /// /// - public static IEnumerable Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) + public static IEnumerable? Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { // handle context culture for variant if (culture == null) @@ -929,7 +936,7 @@ namespace Umbraco.Extensions var children = content.ChildrenForAllCultures; return culture == "*" ? children - : children.Where(x => x.IsInvariantOrHasCulture(culture)); + : children?.Where(x => x.IsInvariantOrHasCulture(culture)); } /// @@ -943,9 +950,9 @@ namespace Umbraco.Extensions /// /// Children are sorted by their sortOrder. /// - public static IEnumerable Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) + public static IEnumerable? Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) { - return content.Children(variationContextAccessor, culture).Where(predicate); + return content.Children(variationContextAccessor, culture)?.Where(predicate); } /// @@ -956,7 +963,7 @@ namespace Umbraco.Extensions /// The specific culture to filter for. If null is used the current culture is used. (Default is null) /// The content type alias. /// The children of the content, of any of the specified types. - public static IEnumerable ChildrenOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) + public static IEnumerable? ChildrenOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { return content.Children(variationContextAccessor, x => x.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); } @@ -972,15 +979,15 @@ namespace Umbraco.Extensions /// /// Children are sorted by their sortOrder. /// - public static IEnumerable Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) + public static IEnumerable? Children(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { - return content.Children(variationContextAccessor, culture).OfType(); + return content.Children(variationContextAccessor, culture)?.OfType(); } public static IPublishedContent? FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { - return content.Children(variationContextAccessor, culture).FirstOrDefault(); + return content.Children(variationContextAccessor, culture)?.FirstOrDefault(); } /// @@ -988,29 +995,29 @@ namespace Umbraco.Extensions /// public static IPublishedContent? FirstChildOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { - return content.ChildrenOfType(variationContextAccessor, contentTypeAlias, culture).FirstOrDefault(); + return content.ChildrenOfType(variationContextAccessor, contentTypeAlias, culture)?.FirstOrDefault(); } public static IPublishedContent? FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) { - return content.Children(variationContextAccessor, predicate, culture).FirstOrDefault(); + return content.Children(variationContextAccessor, predicate, culture)?.FirstOrDefault(); } public static IPublishedContent? FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Guid uniqueId, string? culture = null) { - return content.Children(variationContextAccessor, x => x.Key == uniqueId, culture).FirstOrDefault(); + return content.Children(variationContextAccessor, x => x.Key == uniqueId, culture)?.FirstOrDefault(); } public static T? FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { - return content.Children(variationContextAccessor, culture).FirstOrDefault(); + return content.Children(variationContextAccessor, culture)?.FirstOrDefault(); } public static T? FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) where T : class, IPublishedContent { - return content.Children(variationContextAccessor, culture).FirstOrDefault(predicate); + return content.Children(variationContextAccessor, culture)?.FirstOrDefault(predicate); } #endregion @@ -1047,9 +1054,9 @@ namespace Umbraco.Extensions /// /// Note that in V7 this method also return the content node self. /// - public static IEnumerable Siblings(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) + public static IEnumerable? Siblings(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) { - return SiblingsAndSelf(content, publishedSnapshot, variationContextAccessor, culture).Where(x => x.Id != content.Id); + return SiblingsAndSelf(content, publishedSnapshot, variationContextAccessor, culture)?.Where(x => x.Id != content.Id); } /// @@ -1064,9 +1071,9 @@ namespace Umbraco.Extensions /// /// Note that in V7 this method also return the content node self. /// - public static IEnumerable SiblingsOfType(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) + public static IEnumerable? SiblingsOfType(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { - return SiblingsAndSelfOfType(content, publishedSnapshot, variationContextAccessor, contentTypeAlias, culture).Where(x => x.Id != content.Id); + return SiblingsAndSelfOfType(content, publishedSnapshot, variationContextAccessor, contentTypeAlias, culture)?.Where(x => x.Id != content.Id); } /// @@ -1081,10 +1088,10 @@ namespace Umbraco.Extensions /// /// Note that in V7 this method also return the content node self. /// - public static IEnumerable Siblings(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) + public static IEnumerable? Siblings(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { - return SiblingsAndSelf(content, publishedSnapshot, variationContextAccessor, culture).Where(x => x.Id != content.Id); + return SiblingsAndSelf(content, publishedSnapshot, variationContextAccessor, culture)?.Where(x => x.Id != content.Id); } /// @@ -1095,7 +1102,7 @@ namespace Umbraco.Extensions /// Variation context accessor. /// The specific culture to filter for. If null is used the current culture is used. (Default is null) /// The siblings of the content including the node itself. - public static IEnumerable SiblingsAndSelf(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) + public static IEnumerable? SiblingsAndSelf(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) { return content.Parent != null ? content.Parent.Children(variationContextAccessor, culture) @@ -1111,7 +1118,7 @@ namespace Umbraco.Extensions /// The specific culture to filter for. If null is used the current culture is used. (Default is null) /// The content type alias. /// The siblings of the content including the node itself, of the given content type. - public static IEnumerable SiblingsAndSelfOfType(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) + public static IEnumerable? SiblingsAndSelfOfType(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { return content.Parent != null ? content.Parent.ChildrenOfType(variationContextAccessor, contentTypeAlias, culture) @@ -1127,7 +1134,7 @@ namespace Umbraco.Extensions /// Variation context accessor. /// The specific culture to filter for. If null is used the current culture is used. (Default is null) /// The siblings of the content including the node itself, of the given content type. - public static IEnumerable SiblingsAndSelf(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) + public static IEnumerable? SiblingsAndSelf(this IPublishedContent content, IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return content.Parent != null @@ -1261,10 +1268,10 @@ namespace Umbraco.Extensions IPublishedUrlProvider publishedUrlProvider, string contentTypeAliasFilter = "", string? culture = null) { var firstNode = contentTypeAliasFilter.IsNullOrWhiteSpace() - ? content.Children(variationContextAccessor, culture).Any() - ? content.Children(variationContextAccessor, culture).ElementAt(0) + ? content.Children(variationContextAccessor, culture)?.Any() ?? false + ? content.Children(variationContextAccessor, culture)?.ElementAt(0) : null - : content.Children(variationContextAccessor, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAliasFilter)); + : content.Children(variationContextAccessor, culture)?.FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAliasFilter)); if (firstNode == null) return new DataTable(); //no children found @@ -1279,16 +1286,19 @@ namespace Umbraco.Extensions { //create all row data var tableData = DataTableExtensions.CreateTableData(); - //loop through each child and create row data for it - foreach (var n in content.Children(variationContextAccessor).OrderBy(x => x.SortOrder)) + var children = content.Children(variationContextAccessor)?.OrderBy(x => x.SortOrder); + if (children is not null) { - if (contentTypeAliasFilter.IsNullOrWhiteSpace() == false) + //loop through each child and create row data for it + foreach (var n in children) { - if (n.ContentType.Alias.InvariantEquals(contentTypeAliasFilter) == false) - continue; //skip this one, it doesn't match the filter - } + if (contentTypeAliasFilter.IsNullOrWhiteSpace() == false) + { + if (n.ContentType.Alias.InvariantEquals(contentTypeAliasFilter) == false) + continue; //skip this one, it doesn't match the filter + } - var standardVals = new Dictionary + var standardVals = new Dictionary { { "Id", n.Id }, { "NodeName", n.Name(variationContextAccessor) }, @@ -1300,14 +1310,16 @@ namespace Umbraco.Extensions { "Url", n.Url(publishedUrlProvider) } }; - var userVals = new Dictionary(); - foreach (var p in from IPublishedProperty p in n.Properties where p.GetSourceValue() != null select p) - { - // probably want the "object value" of the property here... - userVals[p.Alias] = p.GetValue(); + var userVals = new Dictionary(); + var properties = n.Properties?.Where(p => p.GetSourceValue() is not null) ?? Array.Empty(); + foreach (var p in properties) + { + // probably want the "object value" of the property here... + userVals[p.Alias] = p.GetValue(); + } + //add the row data + DataTableExtensions.AddRowData(tableData, standardVals, userVals); } - //add the row data - DataTableExtensions.AddRowData(tableData, standardVals, userVals); } return tableData; diff --git a/src/Umbraco.Core/Features/EnabledFeatures.cs b/src/Umbraco.Core/Features/EnabledFeatures.cs index 9645f94cdf..5fb7a581dc 100644 --- a/src/Umbraco.Core/Features/EnabledFeatures.cs +++ b/src/Umbraco.Core/Features/EnabledFeatures.cs @@ -11,6 +11,6 @@ namespace Umbraco.Cms.Core.Features /// /// This is set to a virtual path of a razor view file /// - public string PreviewExtendedView { get; set; } + public string? PreviewExtendedView { get; set; } } } diff --git a/src/Umbraco.Core/HealthChecks/AcceptableConfiguration.cs b/src/Umbraco.Core/HealthChecks/AcceptableConfiguration.cs index 043850203e..93cdea7c0b 100644 --- a/src/Umbraco.Core/HealthChecks/AcceptableConfiguration.cs +++ b/src/Umbraco.Core/HealthChecks/AcceptableConfiguration.cs @@ -2,7 +2,7 @@ { public class AcceptableConfiguration { - public string Value { get; set; } + public string? Value { get; set; } public bool IsRecommended { get; set; } } } diff --git a/src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs b/src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs index b7e5e867c4..bb60fd353c 100644 --- a/src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs +++ b/src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.HealthChecks.Checks.Security private readonly string _header; private readonly string _localizedTextPrefix; private readonly bool _metaTagOptionAvailable; - private static HttpClient s_httpClient; + private static HttpClient? s_httpClient; [Obsolete("Use ctor without value.")] protected BaseHttpHeaderCheck( diff --git a/src/Umbraco.Core/HealthChecks/ConfigurationServiceResult.cs b/src/Umbraco.Core/HealthChecks/ConfigurationServiceResult.cs index 79cd61bced..a5d3ae82da 100644 --- a/src/Umbraco.Core/HealthChecks/ConfigurationServiceResult.cs +++ b/src/Umbraco.Core/HealthChecks/ConfigurationServiceResult.cs @@ -3,6 +3,6 @@ public class ConfigurationServiceResult { public bool Success { get; set; } - public string Result { get; set; } + public string? Result { get; set; } } } diff --git a/src/Umbraco.Core/HealthChecks/HealthCheckGroup.cs b/src/Umbraco.Core/HealthChecks/HealthCheckGroup.cs index 17d585f256..aee97647d9 100644 --- a/src/Umbraco.Core/HealthChecks/HealthCheckGroup.cs +++ b/src/Umbraco.Core/HealthChecks/HealthCheckGroup.cs @@ -7,9 +7,9 @@ namespace Umbraco.Cms.Core.HealthChecks public class HealthCheckGroup { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "checks")] - public List Checks { get; set; } + public List? Checks { get; set; } } } diff --git a/src/Umbraco.Core/IO/IOHelperExtensions.cs b/src/Umbraco.Core/IO/IOHelperExtensions.cs index d50c779f81..1625c239ff 100644 --- a/src/Umbraco.Core/IO/IOHelperExtensions.cs +++ b/src/Umbraco.Core/IO/IOHelperExtensions.cs @@ -13,7 +13,7 @@ namespace Umbraco.Extensions /// /// /// - public static string ResolveRelativeOrVirtualUrl(this IIOHelper ioHelper, string path) + public static string? ResolveRelativeOrVirtualUrl(this IIOHelper ioHelper, string? path) { if (string.IsNullOrWhiteSpace(path)) return path; return path.StartsWith("~/") ? ioHelper.ResolveUrl(path) : path; diff --git a/src/Umbraco.Core/Install/Models/DatabaseModel.cs b/src/Umbraco.Core/Install/Models/DatabaseModel.cs index b87941e590..616ad5dc8b 100644 --- a/src/Umbraco.Core/Install/Models/DatabaseModel.cs +++ b/src/Umbraco.Core/Install/Models/DatabaseModel.cs @@ -9,21 +9,21 @@ namespace Umbraco.Cms.Core.Install.Models public DatabaseType DatabaseType { get; set; } = DatabaseType.SqlServer; [DataMember(Name = "server")] - public string Server { get; set; } + public string? Server { get; set; } [DataMember(Name = "databaseName")] - public string DatabaseName { get; set; } + public string? DatabaseName { get; set; } [DataMember(Name = "login")] - public string Login { get; set; } + public string? Login { get; set; } [DataMember(Name = "password")] - public string Password { get; set; } + public string? Password { get; set; } [DataMember(Name = "integratedAuth")] public bool IntegratedAuth { get; set; } [DataMember(Name = "connectionString")] - public string ConnectionString { get; set; } + public string? ConnectionString { get; set; } } } diff --git a/src/Umbraco.Core/Install/Models/InstallInstructions.cs b/src/Umbraco.Core/Install/Models/InstallInstructions.cs index 41ef0bacc4..9dc42553e0 100644 --- a/src/Umbraco.Core/Install/Models/InstallInstructions.cs +++ b/src/Umbraco.Core/Install/Models/InstallInstructions.cs @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.Install.Models public class InstallInstructions { [DataMember(Name = "instructions")] - public IDictionary Instructions { get; set; } + public IDictionary? Instructions { get; set; } [DataMember(Name = "installId")] public Guid InstallId { get; set; } diff --git a/src/Umbraco.Core/Install/Models/Package.cs b/src/Umbraco.Core/Install/Models/Package.cs index 60676e9564..3b9a204f10 100644 --- a/src/Umbraco.Core/Install/Models/Package.cs +++ b/src/Umbraco.Core/Install/Models/Package.cs @@ -7,9 +7,9 @@ namespace Umbraco.Cms.Core.Install.Models public class Package { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "thumbnail")] - public string Thumbnail { get; set; } + public string? Thumbnail { get; set; } [DataMember(Name = "id")] public Guid Id { get; set; } } diff --git a/src/Umbraco.Core/Install/Models/UserModel.cs b/src/Umbraco.Core/Install/Models/UserModel.cs index 1c36b711d4..5c13c5c932 100644 --- a/src/Umbraco.Core/Install/Models/UserModel.cs +++ b/src/Umbraco.Core/Install/Models/UserModel.cs @@ -6,13 +6,13 @@ namespace Umbraco.Cms.Core.Install.Models public class UserModel { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "email")] - public string Email { get; set; } + public string? Email { get; set; } [DataMember(Name = "password")] - public string Password { get; set; } + public string? Password { get; set; } [DataMember(Name = "subscribeToNewsLetter")] public bool SubscribeToNewsLetter { get; set; } diff --git a/src/Umbraco.Core/Macros/MacroContent.cs b/src/Umbraco.Core/Macros/MacroContent.cs index a7f8b003b4..7998b00fd7 100644 --- a/src/Umbraco.Core/Macros/MacroContent.cs +++ b/src/Umbraco.Core/Macros/MacroContent.cs @@ -6,7 +6,7 @@ namespace Umbraco.Cms.Core.Macros public class MacroContent { // gets or sets the text content - public string Text { get; set; } + public string? Text { get; set; } // gets or sets the date the content was generated public DateTime Date { get; set; } = DateTime.Now; diff --git a/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs b/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs index d3f915603d..ed44742bc0 100644 --- a/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs +++ b/src/Umbraco.Core/Manifest/ManifestContentAppDefinition.cs @@ -27,13 +27,13 @@ namespace Umbraco.Cms.Core.Manifest [DataContract(Name = "appdef", Namespace = "")] public class ManifestContentAppDefinition { - private string _view; + private string? _view; /// /// Gets or sets the name of the content app. /// [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } /// /// Gets or sets the unique alias of the content app. @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Core.Manifest /// Must be a valid javascript identifier, ie no spaces etc. /// [DataMember(Name = "alias")] - public string Alias { get; set; } + public string? Alias { get; set; } /// /// Gets or sets the weight of the content app. @@ -57,13 +57,13 @@ namespace Umbraco.Cms.Core.Manifest /// Must be a valid helveticons class name (see http://hlvticons.ch/). /// [DataMember(Name = "icon")] - public string Icon { get; set; } + public string? Icon { get; set; } /// /// Gets or sets the view for rendering the content app. /// [DataMember(Name = "view")] - public string View { get; set; } + public string? View { get; set; } /// /// Gets or sets the list of 'show' conditions for the content app. diff --git a/src/Umbraco.Core/Manifest/ManifestDashboard.cs b/src/Umbraco.Core/Manifest/ManifestDashboard.cs index 50df4bb15e..a10c3a2177 100644 --- a/src/Umbraco.Core/Manifest/ManifestDashboard.cs +++ b/src/Umbraco.Core/Manifest/ManifestDashboard.cs @@ -8,13 +8,13 @@ namespace Umbraco.Cms.Core.Manifest public class ManifestDashboard : IDashboard { [DataMember(Name = "alias", IsRequired = true)] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [DataMember(Name = "weight")] public int Weight { get; set; } = 100; [DataMember(Name = "view", IsRequired = true)] - public string View { get; set; } + public string View { get; set; } = null!; [DataMember(Name = "sections")] public string[] Sections { get; set; } = Array.Empty(); diff --git a/src/Umbraco.Core/Manifest/ManifestSection.cs b/src/Umbraco.Core/Manifest/ManifestSection.cs index 0422d6c5b6..864a0734e2 100644 --- a/src/Umbraco.Core/Manifest/ManifestSection.cs +++ b/src/Umbraco.Core/Manifest/ManifestSection.cs @@ -7,9 +7,9 @@ namespace Umbraco.Cms.Core.Manifest public class ManifestSection : ISection { [DataMember(Name = "alias")] - public string Alias { get; set; } + public string Alias { get; set; } = string.Empty; [DataMember(Name = "name")] - public string Name { get; set; } + public string Name { get; set; } = string.Empty; } } diff --git a/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs b/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs index e7507c3bf2..7fafc232df 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Media.EmbedProviders _jsonSerializer = jsonSerializer; } - private static HttpClient _httpClient; + private static HttpClient? _httpClient; public abstract string ApiEndpoint { get; } diff --git a/src/Umbraco.Core/Media/EmbedProviders/OEmbedResponse.cs b/src/Umbraco.Core/Media/EmbedProviders/OEmbedResponse.cs index 80ae4f7a14..f003aa841c 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/OEmbedResponse.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/OEmbedResponse.cs @@ -10,28 +10,28 @@ namespace Umbraco.Cms.Core.Media.EmbedProviders public class OEmbedResponse { [DataMember(Name ="type")] - public string Type { get; set; } + public string? Type { get; set; } [DataMember(Name ="version")] - public string Version { get; set; } + public string? Version { get; set; } [DataMember(Name ="title")] - public string Title { get; set; } + public string? Title { get; set; } [DataMember(Name ="author_name")] - public string AuthorName { get; set; } + public string? AuthorName { get; set; } [DataMember(Name ="author_url")] - public string AuthorUrl { get; set; } + public string? AuthorUrl { get; set; } [DataMember(Name ="provider_name")] - public string ProviderName { get; set; } + public string? ProviderName { get; set; } [DataMember(Name ="provider_url")] - public string ProviderUrl { get; set; } + public string? ProviderUrl { get; set; } [DataMember(Name ="thumbnail_url")] - public string ThumbnailUrl { get; set; } + public string? ThumbnailUrl { get; set; } [DataMember(Name ="thumbnail_height")] public double? ThumbnailHeight { get; set; } @@ -40,10 +40,10 @@ namespace Umbraco.Cms.Core.Media.EmbedProviders public double? ThumbnailWidth { get; set; } [DataMember(Name ="html")] - public string Html { get; set; } + public string? Html { get; set; } [DataMember(Name ="url")] - public string Url { get; set; } + public string? Url { get; set; } [DataMember(Name ="height")] public double? Height { get; set; } diff --git a/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs b/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs index cb5ffe450e..7114b2eb14 100644 --- a/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs +++ b/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text; namespace Umbraco.Cms.Core.Media.Exif @@ -264,7 +265,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// /// /// is null. - public bool TryGetValue (ExifTag key, out ExifProperty value) + public bool TryGetValue (ExifTag key, [MaybeNullWhen(false)] out ExifProperty value) { return items.TryGetValue (key, out value); } diff --git a/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs b/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs index a66cee1b36..6a5ea84944 100644 --- a/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs +++ b/src/Umbraco.Core/Media/Exif/ExifTagFactory.cs @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// public static string GetTagName(ExifTag tag) { - string name = Enum.GetName(typeof(ExifTag), tag); + string? name = Enum.GetName(typeof(ExifTag), tag); if (name == null) return "Unknown"; else @@ -56,8 +56,8 @@ namespace Umbraco.Cms.Core.Media.Exif /// public static string GetTagLongName(ExifTag tag) { - string ifdname = Enum.GetName(typeof(IFD), GetTagIFD(tag)); - string name = Enum.GetName(typeof(ExifTag), tag); + string? ifdname = Enum.GetName(typeof(IFD), GetTagIFD(tag)); + string? name = Enum.GetName(typeof(ExifTag), tag); if (name == null) name = "Unknown"; string tagidname = GetTagID(tag).ToString(); diff --git a/src/Umbraco.Core/Media/Exif/JPEGFile.cs b/src/Umbraco.Core/Media/Exif/JPEGFile.cs index 61cc166184..f0f732b520 100644 --- a/src/Umbraco.Core/Media/Exif/JPEGFile.cs +++ b/src/Umbraco.Core/Media/Exif/JPEGFile.cs @@ -344,9 +344,15 @@ namespace Umbraco.Cms.Core.Media.Exif ms.Close(); // Return APP0 header - jfifApp0.Header = ms.ToArray(); - return true; + if (jfifApp0 is not null) + { + jfifApp0.Header = ms.ToArray(); + return true; + } + + return false; } + /// /// Reads the APP0 section containing JFIF extension metadata. /// @@ -436,9 +442,14 @@ namespace Umbraco.Cms.Core.Media.Exif ms.Close(); - // Return APP0 header - jfxxApp0.Header = ms.ToArray(); - return true; + if (jfxxApp0 is not null) + { + // Return APP0 header + jfxxApp0.Header = ms.ToArray(); + return true; + } + + return false; } /// @@ -758,9 +769,14 @@ namespace Umbraco.Cms.Core.Media.Exif ms.Close(); - // Return APP1 header - exifApp1.Header = ms.ToArray(); - return true; + if (exifApp1 is not null) + { + // Return APP1 header + exifApp1.Header = ms.ToArray(); + return true; + } + + return false; } private void WriteIFD(MemoryStream stream, Dictionary ifd, IFD ifdtype, long tiffoffset, bool preserveMakerNote) diff --git a/src/Umbraco.Core/Media/Exif/MathEx.cs b/src/Umbraco.Core/Media/Exif/MathEx.cs index 6c73f44df0..d49ccf924f 100644 --- a/src/Umbraco.Core/Media/Exif/MathEx.cs +++ b/src/Umbraco.Core/Media/Exif/MathEx.cs @@ -518,7 +518,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// /// format is invalid or not supported. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string? format, IFormatProvider? formatProvider) { StringBuilder sb = new StringBuilder(); sb.Append(((mIsNegative ? -1 : 1) * mNumerator).ToString(format, formatProvider)); @@ -592,7 +592,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// Greater than zero: This instance is greater than obj or obj is null. /// /// obj is not a Fraction. - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (!(obj is Fraction32)) throw new ArgumentException("obj must be of type Fraction", "obj"); @@ -1100,7 +1100,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// Another object to compare to. /// true if obj and this instance are the same type and represent /// the same value; otherwise, false. - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj == null) return false; @@ -1146,7 +1146,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// /// format is invalid or not supported. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString(string? format, IFormatProvider? formatProvider) { StringBuilder sb = new StringBuilder(); sb.Append(mNumerator.ToString(format, formatProvider)); @@ -1220,7 +1220,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// Greater than zero: This instance is greater than obj or obj is null. /// /// obj is not a Fraction. - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (!(obj is UFraction32)) throw new ArgumentException("obj must be of type UFraction32", "obj"); diff --git a/src/Umbraco.Core/Media/IImageDimensionExtractor.cs b/src/Umbraco.Core/Media/IImageDimensionExtractor.cs index abbe8806b3..2eaf632e54 100644 --- a/src/Umbraco.Core/Media/IImageDimensionExtractor.cs +++ b/src/Umbraco.Core/Media/IImageDimensionExtractor.cs @@ -5,6 +5,6 @@ namespace Umbraco.Cms.Core.Media { public interface IImageDimensionExtractor { - public Size? GetDimensions(Stream stream); + public Size? GetDimensions(Stream? stream); } } diff --git a/src/Umbraco.Core/Media/OEmbedResult.cs b/src/Umbraco.Core/Media/OEmbedResult.cs index fd2c5ff421..b370efc1ae 100644 --- a/src/Umbraco.Core/Media/OEmbedResult.cs +++ b/src/Umbraco.Core/Media/OEmbedResult.cs @@ -4,6 +4,6 @@ { public OEmbedStatus OEmbedStatus { get; set; } public bool SupportsDimensions { get; set; } - public string Markup { get; set; } + public string? Markup { get; set; } } } diff --git a/src/Umbraco.Core/Media/UploadAutoFillProperties.cs b/src/Umbraco.Core/Media/UploadAutoFillProperties.cs index 83357f8929..a3c0f1347a 100644 --- a/src/Umbraco.Core/Media/UploadAutoFillProperties.cs +++ b/src/Umbraco.Core/Media/UploadAutoFillProperties.cs @@ -112,7 +112,7 @@ namespace Umbraco.Cms.Core.Media } } - private void SetProperties(IContentBase content, ImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream, string culture, string segment) + private void SetProperties(IContentBase content, ImagingAutoFillUploadField autoFillConfig, string filepath, Stream? filestream, string culture, string segment) { var extension = (Path.GetExtension(filepath) ?? string.Empty).TrimStart(Constants.CharArrays.Period); @@ -120,25 +120,25 @@ namespace Umbraco.Cms.Core.Media ? _imageDimensionExtractor.GetDimensions(filestream) ?? (Size?)new Size(Constants.Conventions.Media.DefaultSize, Constants.Conventions.Media.DefaultSize) : null; - SetProperties(content, autoFillConfig, size, filestream.Length, extension, culture, segment); + SetProperties(content, autoFillConfig, size, filestream?.Length, extension, culture, segment); } - private static void SetProperties(IContentBase content, ImagingAutoFillUploadField autoFillConfig, Size? size, long length, string extension, string culture, string segment) + private static void SetProperties(IContentBase content, ImagingAutoFillUploadField autoFillConfig, Size? size, long? length, string extension, string culture, string segment) { if (content == null) throw new ArgumentNullException(nameof(content)); if (autoFillConfig == null) throw new ArgumentNullException(nameof(autoFillConfig)); if (!string.IsNullOrWhiteSpace(autoFillConfig.WidthFieldAlias) && content.Properties.Contains(autoFillConfig.WidthFieldAlias)) - content.Properties[autoFillConfig.WidthFieldAlias].SetValue(size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty, culture, segment); + content.Properties[autoFillConfig.WidthFieldAlias]!.SetValue(size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty, culture, segment); if (!string.IsNullOrWhiteSpace(autoFillConfig.HeightFieldAlias) && content.Properties.Contains(autoFillConfig.HeightFieldAlias)) - content.Properties[autoFillConfig.HeightFieldAlias].SetValue(size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty, culture, segment); + content.Properties[autoFillConfig.HeightFieldAlias]!.SetValue(size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty, culture, segment); if (!string.IsNullOrWhiteSpace(autoFillConfig.LengthFieldAlias) && content.Properties.Contains(autoFillConfig.LengthFieldAlias)) - content.Properties[autoFillConfig.LengthFieldAlias].SetValue(length, culture, segment); + content.Properties[autoFillConfig.LengthFieldAlias]!.SetValue(length, culture, segment); if (!string.IsNullOrWhiteSpace(autoFillConfig.ExtensionFieldAlias) && content.Properties.Contains(autoFillConfig.ExtensionFieldAlias)) - content.Properties[autoFillConfig.ExtensionFieldAlias].SetValue(extension, culture, segment); + content.Properties[autoFillConfig.ExtensionFieldAlias]!.SetValue(extension, culture, segment); } private static void ResetProperties(IContentBase content, ImagingAutoFillUploadField autoFillConfig, string culture, string segment) @@ -147,16 +147,16 @@ namespace Umbraco.Cms.Core.Media if (autoFillConfig == null) throw new ArgumentNullException(nameof(autoFillConfig)); if (content.Properties.Contains(autoFillConfig.WidthFieldAlias)) - content.Properties[autoFillConfig.WidthFieldAlias].SetValue(string.Empty, culture, segment); + content.Properties[autoFillConfig.WidthFieldAlias]?.SetValue(string.Empty, culture, segment); if (content.Properties.Contains(autoFillConfig.HeightFieldAlias)) - content.Properties[autoFillConfig.HeightFieldAlias].SetValue(string.Empty, culture, segment); + content.Properties[autoFillConfig.HeightFieldAlias]?.SetValue(string.Empty, culture, segment); if (content.Properties.Contains(autoFillConfig.LengthFieldAlias)) - content.Properties[autoFillConfig.LengthFieldAlias].SetValue(string.Empty, culture, segment); + content.Properties[autoFillConfig.LengthFieldAlias]?.SetValue(string.Empty, culture, segment); if (content.Properties.Contains(autoFillConfig.ExtensionFieldAlias)) - content.Properties[autoFillConfig.ExtensionFieldAlias].SetValue(string.Empty, culture, segment); + content.Properties[autoFillConfig.ExtensionFieldAlias]?.SetValue(string.Empty, culture, segment); } } } diff --git a/src/Umbraco.Core/Models/AnchorsModel.cs b/src/Umbraco.Core/Models/AnchorsModel.cs index 6033f092f8..466751c82d 100644 --- a/src/Umbraco.Core/Models/AnchorsModel.cs +++ b/src/Umbraco.Core/Models/AnchorsModel.cs @@ -2,6 +2,6 @@ namespace Umbraco.Cms.Core.Models { public class AnchorsModel { - public string RteContent { get; set; } + public string? RteContent { get; set; } } } diff --git a/src/Umbraco.Core/Models/BackOfficeTourStep.cs b/src/Umbraco.Core/Models/BackOfficeTourStep.cs index 4c56be29fc..aa2aaf7f53 100644 --- a/src/Umbraco.Core/Models/BackOfficeTourStep.cs +++ b/src/Umbraco.Core/Models/BackOfficeTourStep.cs @@ -9,26 +9,26 @@ namespace Umbraco.Cms.Core.Models public class BackOfficeTourStep { [DataMember(Name = "title")] - public string Title { get; set; } + public string? Title { get; set; } [DataMember(Name = "content")] - public string Content { get; set; } + public string? Content { get; set; } [DataMember(Name = "type")] - public string Type { get; set; } + public string? Type { get; set; } [DataMember(Name = "element")] - public string Element { get; set; } + public string? Element { get; set; } [DataMember(Name = "elementPreventClick")] public bool ElementPreventClick { get; set; } [DataMember(Name = "backdropOpacity")] public float? BackdropOpacity { get; set; } [DataMember(Name = "event")] - public string Event { get; set; } + public string? Event { get; set; } [DataMember(Name = "view")] - public string View { get; set; } + public string? View { get; set; } [DataMember(Name = "eventElement")] - public string EventElement { get; set; } + public string? EventElement { get; set; } [DataMember(Name = "customProperties")] - public object CustomProperties { get; set; } + public object? CustomProperties { get; set; } [DataMember(Name = "skipStepIfVisible")] - public string SkipStepIfVisible { get; set; } + public string? SkipStepIfVisible { get; set; } } } diff --git a/src/Umbraco.Core/Models/ChangingPasswordModel.cs b/src/Umbraco.Core/Models/ChangingPasswordModel.cs index 681c7d89ae..be19f13b75 100644 --- a/src/Umbraco.Core/Models/ChangingPasswordModel.cs +++ b/src/Umbraco.Core/Models/ChangingPasswordModel.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Models /// The password value /// [DataMember(Name = "newPassword")] - public string NewPassword { get; set; } + public string? NewPassword { get; set; } /// /// The old password - used to change a password when: EnablePasswordRetrieval = false diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index 31c87853e7..2dc6cb94e4 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -43,7 +43,7 @@ namespace Umbraco.Cms.Core.Models /// /// Initializes a new instance of the class. /// - protected ContentBase(string name, int parentId, IContentTypeComposition contentType, IPropertyCollection properties, string? culture = null) + protected ContentBase(string? name, int parentId, IContentTypeComposition contentType, IPropertyCollection properties, string? culture = null) : this(name, contentType, properties, culture) { if (parentId == 0) throw new ArgumentOutOfRangeException(nameof(parentId)); @@ -53,14 +53,14 @@ namespace Umbraco.Cms.Core.Models /// /// Initializes a new instance of the class. /// - protected ContentBase(string name, IContentBase parent, IContentTypeComposition contentType, IPropertyCollection properties, string? culture = null) + protected ContentBase(string? name, IContentBase? parent, IContentTypeComposition contentType, IPropertyCollection properties, string? culture = null) : this(name, contentType, properties, culture) { if (parent == null) throw new ArgumentNullException(nameof(parent)); SetParent(parent); } - private ContentBase(string name, IContentTypeComposition contentType, IPropertyCollection properties, string? culture = null) + private ContentBase(string? name, IContentTypeComposition contentType, IPropertyCollection properties, string? culture = null) { ContentType = contentType?.ToSimple() ?? throw new ArgumentNullException(nameof(contentType)); diff --git a/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs b/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs index 8b727d65d4..2c73bcd590 100644 --- a/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs +++ b/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs @@ -16,6 +16,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// The assigned permissions to the content item organized by permission group name /// [DataMember(Name = "permissions")] - public IDictionary> AssignedPermissions { get; set; } + public IDictionary>? AssignedPermissions { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs b/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs index afd19af028..03b30b3853 100644 --- a/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs +++ b/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs @@ -17,13 +17,13 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// The assigned permissions for the user group organized by permission group name /// [DataMember(Name = "permissions")] - public IDictionary> AssignedPermissions { get; set; } + public IDictionary>? AssignedPermissions { get; set; } /// /// The default permissions for the user group organized by permission group name /// [DataMember(Name = "defaultPermissions")] - public IDictionary> DefaultPermissions { get; set; } + public IDictionary>? DefaultPermissions { get; set; } public static IDictionary> ClonePermissions(IDictionary> permissions) { diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs b/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs index 2b08a340f0..86af3de89a 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs @@ -7,9 +7,9 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class ContentDomainsAndCulture { [DataMember(Name = "domains")] - public IEnumerable Domains { get; set; } + public IEnumerable? Domains { get; set; } [DataMember(Name = "language")] - public string Language { get; set; } + public string? Language { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs b/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs index bde99ef661..80c24b8cc0 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// [DataMember(Name = "idSortOrder", IsRequired = true)] [Required] - public int[] IdSortOrder { get; set; } + public int[]? IdSortOrder { get; set; } } diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs index dc7b1cdc8c..57b1c98d54 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs @@ -21,6 +21,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// [DataMember(Name = "contentTypeAliases")] [Required] - public string[] ContentTypeAliases { get; set; } + public string[]? ContentTypeAliases { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs index a9651e4f7a..0a2bea7f88 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs @@ -22,6 +22,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// [DataMember(Name = "contentTypeKeys")] [Required] - public Guid[] ContentTypeKeys { get; set; } + public Guid[]? ContentTypeKeys { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs index eb6047103a..153f495a70 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [DataMember(Name = "group")] [ReadOnly(true)] - public string Group { get; set; } + public string? Group { get; set; } [DataMember(Name = "hasPrevalues")] [ReadOnly(true)] diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs index 420b5b5679..c8699472d5 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs @@ -20,16 +20,16 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class ContentTypeReferences : EntityBasic { [DataMember(Name = "properties")] - public object Properties { get; set; } + public object? Properties { get; set; } [DataContract(Name = "property", Namespace = "")] public class PropertyTypeReferences { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "alias")] - public string Alias { get; set; } + public string? Alias { get; set; } } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs index b190786f21..3795e42782 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs @@ -26,13 +26,13 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// [DataMember(Name = "selectedEditor", IsRequired = true)] [Required] - public string EditorAlias { get; set; } + public string? EditorAlias { get; set; } /// /// Gets or sets the datatype configuration fields. /// [DataMember(Name = "preValues")] - public IEnumerable ConfigurationFields { get; set; } + public IEnumerable? ConfigurationFields { get; set; } /// /// Gets or sets the persisted data type. diff --git a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs index 6a70386f07..2e509ea5db 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs @@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// The list of allowed templates to assign (template alias) /// [DataMember(Name = "allowedTemplates")] - public IEnumerable AllowedTemplates { get; set; } + public IEnumerable? AllowedTemplates { get; set; } /// /// The default template to assign (template alias) @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// public override IEnumerable Validate(ValidationContext validationContext) { - if (AllowedTemplates.Any(x => x.IsNullOrWhiteSpace())) + if (AllowedTemplates?.Any(x => x.IsNullOrWhiteSpace()) ?? false) yield return new ValidationResult("Template value cannot be null", new[] { "AllowedTemplates" }); foreach (var v in base.Validate(validationContext)) diff --git a/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs b/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs index 3f8d836aba..a91e740e79 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs @@ -15,6 +15,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public int Language { get; set; } [DataMember(Name = "domains")] - public DomainDisplay[] Domains { get; set; } + public DomainDisplay[]? Domains { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs b/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs index a789012fc7..6c8c1b50e3 100644 --- a/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs +++ b/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs @@ -9,16 +9,16 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class EditorNavigation { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [DataMember(Name = "icon")] - public string Icon { get; set; } + public string? Icon { get; set; } [DataMember(Name = "view")] - public string View { get; set; } + public string? View { get; set; } [DataMember(Name = "active")] public bool Active { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs index 166a70af13..7b665ebd36 100644 --- a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs @@ -14,12 +14,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing { AdditionalData = new Dictionary(); Alias = string.Empty; - Name = string.Empty; + Path = string.Empty; } [DataMember(Name = "name", IsRequired = true)] [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "id", IsRequired = true)] [Required] @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// The path of the entity /// [DataMember(Name = "path")] - public string? Path { get; set; } + public string Path { get; set; } /// /// A collection of extra data that is available for this specific entity/entity type /// diff --git a/src/Umbraco.Core/Models/ContentEditing/GetAvailableCompositionsFilter.cs b/src/Umbraco.Core/Models/ContentEditing/GetAvailableCompositionsFilter.cs index 96ab35d54f..d73687c039 100644 --- a/src/Umbraco.Core/Models/ContentEditing/GetAvailableCompositionsFilter.cs +++ b/src/Umbraco.Core/Models/ContentEditing/GetAvailableCompositionsFilter.cs @@ -9,13 +9,13 @@ /// This is required because in the case of creating/modifying a content type because new property types being added to it are not yet persisted so cannot /// be looked up via the db, they need to be passed in. /// - public string[] FilterPropertyTypes { get; set; } + public string[]? FilterPropertyTypes { get; set; } /// /// This is normally an empty list but if additional content type aliases are passed in, any content types containing those aliases will be filtered out /// along with any content types that have matching property types that are included in the filtered content types /// - public string[] FilterContentTypes { get; set; } + public string[]? FilterContentTypes { get; set; } /// /// Wether the content type is currently marked as an element type diff --git a/src/Umbraco.Core/Models/ContentEditing/LinkDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/LinkDisplay.cs index 69bbd91edc..551065c566 100644 --- a/src/Umbraco.Core/Models/ContentEditing/LinkDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/LinkDisplay.cs @@ -6,27 +6,27 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class LinkDisplay { [DataMember(Name = "icon")] - public string Icon { get; set; } + public string? Icon { get; set; } [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "published")] public bool Published { get; set; } [DataMember(Name = "queryString")] - public string QueryString { get; set; } + public string? QueryString { get; set; } [DataMember(Name = "target")] - public string Target { get; set; } + public string? Target { get; set; } [DataMember(Name = "trashed")] public bool Trashed { get; set; } [DataMember(Name = "udi")] - public GuidUdi Udi { get; set; } + public GuidUdi? Udi { get; set; } [DataMember(Name = "url")] - public string Url { get; set; } + public string? Url { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs b/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs index d3817f9875..729a086864 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs @@ -23,6 +23,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// so the app will need to go fetch the individual tree node in order to be able to load it's action list (menu) /// [DataMember(Name = "treeNodeUrl")] - public string TreeNodeUrl { get; set; } + public string? TreeNodeUrl { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/MacroParameter.cs b/src/Umbraco.Core/Models/ContentEditing/MacroParameter.cs index 5282d09edb..233a58cd08 100644 --- a/src/Umbraco.Core/Models/ContentEditing/MacroParameter.cs +++ b/src/Umbraco.Core/Models/ContentEditing/MacroParameter.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing { [DataMember(Name = "alias", IsRequired = true)] [Required] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [DataMember(Name = "name")] public string? Name { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/MacroParameterDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MacroParameterDisplay.cs index daf793e3c1..134740aa4a 100644 --- a/src/Umbraco.Core/Models/ContentEditing/MacroParameterDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/MacroParameterDisplay.cs @@ -12,19 +12,19 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// Gets or sets the key. /// [DataMember(Name = "key")] - public string Key { get; set; } + public string? Key { get; set; } /// /// Gets or sets the label. /// [DataMember(Name = "label")] - public string Label { get; set; } + public string? Label { get; set; } /// /// Gets or sets the editor. /// [DataMember(Name = "editor")] - public string Editor { get; set; } + public string? Editor { get; set; } /// /// Gets or sets the id. diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs b/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs index 376e758573..d148d88921 100644 --- a/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs @@ -9,10 +9,10 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class MemberBasic : ContentItemBasic { [DataMember(Name = "username")] - public string Username { get; set; } + public string? Username { get; set; } [DataMember(Name = "email")] - public string Email { get; set; } + public string? Email { get; set; } [DataMember(Name = "properties")] public override IEnumerable Properties diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs index cad4fa9af9..c4a5382e84 100644 --- a/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs @@ -10,6 +10,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class MemberListDisplay : ContentItemDisplayBase { [DataMember(Name = "apps")] - public IEnumerable ContentApps { get; set; } + public IEnumerable? ContentApps { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs b/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs index e5c864781d..519266fb15 100644 --- a/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs @@ -13,12 +13,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [DataMember(Name = "username", IsRequired = true)] [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] - public string? Username { get; set; } + public string Username { get; set; } = null!; [DataMember(Name = "email", IsRequired = true)] [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] [EmailAddress] - public string? Email { get; set; } + public string Email { get; set; } = null!; [DataMember(Name = "password")] public ChangingPasswordModel? Password { get; set; } @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing var prop = Properties.FirstOrDefault(x => x.Alias == alias); if (prop == null) return default; var converted = prop.Value.TryConvertTo(); - return converted.ResultOr(default); + return converted.Result ?? default; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs b/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs index 11ddfc0ca0..ee4029cab3 100644 --- a/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs +++ b/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs @@ -6,7 +6,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class NotifySetting { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "checked")] public bool Checked { get; set; } @@ -15,6 +15,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// The letter from the IAction /// [DataMember(Name = "notifyCode")] - public string NotifyCode { get; set; } + public string? NotifyCode { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs b/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs index 6b7192ad68..4682b752b9 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class ObjectType { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "id")] public Guid Id { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/Permission.cs b/src/Umbraco.Core/Models/ContentEditing/Permission.cs index 90bfd86bd2..c6e446fc39 100644 --- a/src/Umbraco.Core/Models/ContentEditing/Permission.cs +++ b/src/Umbraco.Core/Models/ContentEditing/Permission.cs @@ -7,28 +7,28 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class Permission : ICloneable { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "description")] - public string Description { get; set; } + public string? Description { get; set; } [DataMember(Name = "checked")] public bool Checked { get; set; } [DataMember(Name = "icon")] - public string Icon { get; set; } + public string? Icon { get; set; } /// /// We'll use this to map the categories but it wont' be returned in the json /// [IgnoreDataMember] - public string Category { get; set; } + public string Category { get; set; } = null!; /// /// The letter from the IAction /// [DataMember(Name = "permissionCode")] - public string PermissionCode { get; set; } + public string? PermissionCode { get; set; } public object Clone() { diff --git a/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs b/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs index ea5217c1a8..56ca1c1907 100644 --- a/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs +++ b/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs @@ -9,9 +9,9 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class PostedFolder { [DataMember(Name = "parentId")] - public string ParentId { get; set; } + public string? ParentId { get; set; } [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs index 8519cace1e..0431fb270f 100644 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [Required] [DataMember(Name = "alias")] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [DataMember(Name = "sortOrder")] public int SortOrder { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs index 6752507de4..1ddf575a07 100644 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [Required] [RegularExpression(@"^([a-zA-Z]\w.*)$", ErrorMessage = "Invalid alias")] [DataMember(Name = "alias")] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [DataMember(Name = "description")] public string? Description { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs b/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs index c0678ea9d9..199ca34ceb 100644 --- a/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs +++ b/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs @@ -6,15 +6,15 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class PublicAccess { [DataMember(Name = "groups")] - public MemberGroupDisplay[] Groups { get; set; } + public MemberGroupDisplay[]? Groups { get; set; } [DataMember(Name = "loginPage")] - public EntityBasic LoginPage { get; set; } + public EntityBasic? LoginPage { get; set; } [DataMember(Name = "errorPage")] - public EntityBasic ErrorPage { get; set; } + public EntityBasic? ErrorPage { get; set; } [DataMember(Name = "members")] - public MemberDisplay[] Members { get; set; } + public MemberDisplay[]? Members { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs b/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs index ba5616371b..e4b026b6eb 100644 --- a/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs +++ b/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class RedirectUrlSearchResult { [DataMember(Name = "searchResults")] - public IEnumerable SearchResults { get; set; } + public IEnumerable? SearchResults { get; set; } [DataMember(Name = "totalCount")] public long TotalCount { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs index f5c757ad9d..06fcc5d124 100644 --- a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs +++ b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs @@ -6,10 +6,10 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class RichTextEditorCommand { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [DataMember(Name = "mode")] public RichTextEditorCommandMode Mode { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs index c239d5e70c..e80b25f4ae 100644 --- a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs +++ b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs @@ -7,18 +7,18 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class RichTextEditorConfiguration { [DataMember(Name = "plugins")] - public IEnumerable Plugins { get; set; } + public IEnumerable? Plugins { get; set; } [DataMember(Name = "commands")] - public IEnumerable Commands { get; set; } + public IEnumerable? Commands { get; set; } [DataMember(Name = "validElements")] - public string ValidElements { get; set; } + public string? ValidElements { get; set; } [DataMember(Name = "inValidElements")] - public string InvalidElements { get; set; } + public string? InvalidElements { get; set; } [DataMember(Name = "customConfig")] - public IDictionary CustomConfig { get; set; } + public IDictionary? CustomConfig { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs index 4e8fde56df..3740f47fc6 100644 --- a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs +++ b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs @@ -6,6 +6,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class RichTextEditorPlugin { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs b/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs index 3b7342a67b..762c806dc9 100644 --- a/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs +++ b/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs @@ -16,6 +16,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public int VersionAuthorId { get; set; } [DataMember(Name = "versionAuthorName")] - public string VersionAuthorName { get; set; } + public string? VersionAuthorName { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs b/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs index 5ca02d1bc7..53facfe990 100644 --- a/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs +++ b/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class SearchResult { [DataMember(Name = "id")] - public string Id { get; set; } + public string? Id { get; set; } [DataMember(Name = "score")] public float Score { get; set; } @@ -16,6 +16,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public int FieldCount => Values?.Count ?? 0; [DataMember(Name = "values")] - public IReadOnlyDictionary> Values { get; set; } + public IReadOnlyDictionary>? Values { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs b/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs index 4c76fff108..2d550a4457 100644 --- a/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs +++ b/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs @@ -17,6 +17,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public long TotalRecords { get; set; } [DataMember(Name = "results")] - public IEnumerable Results { get; set; } + public IEnumerable? Results { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/Section.cs b/src/Umbraco.Core/Models/ContentEditing/Section.cs index d62125ade8..558d73b49b 100644 --- a/src/Umbraco.Core/Models/ContentEditing/Section.cs +++ b/src/Umbraco.Core/Models/ContentEditing/Section.cs @@ -9,16 +9,16 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class Section { [DataMember(Name = "name")] - public string Name { get; set; } + public string Name { get; set; } = null!; [DataMember(Name = "alias")] - public string Alias { get; set; } + public string Alias { get; set; } = null!; /// /// In some cases a custom route path can be specified so that when clicking on a section it goes to this /// path instead of the normal dashboard path /// [DataMember(Name = "routePath")] - public string RoutePath { get; set; } + public string? RoutePath { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs index db24cef2ad..39e2027b27 100644 --- a/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs @@ -6,9 +6,9 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class SnippetDisplay { [DataMember(Name = "name", IsRequired = true)] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "fileName", IsRequired = true)] - public string FileName { get; set; } + public string? FileName { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs b/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs index c4794e5536..11d3b814c1 100644 --- a/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs +++ b/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs @@ -6,9 +6,9 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class Stylesheet { [DataMember(Name="name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "path")] - public string Path { get; set; } + public string? Path { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs b/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs index 81f7c0fcea..1afabb10e6 100644 --- a/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs +++ b/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs @@ -6,12 +6,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class StylesheetRule { [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "selector")] - public string Selector { get; set; } + public string? Selector { get; set; } [DataMember(Name = "styles")] - public string Styles { get; set; } + public string? Styles { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs b/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs index e5b21ce893..99533facc8 100644 --- a/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs +++ b/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs @@ -10,25 +10,25 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public class TreeSearchResult { [DataMember(Name = "appAlias")] - public string AppAlias { get; set; } + public string? AppAlias { get; set; } [DataMember(Name = "treeAlias")] - public string TreeAlias { get; set; } + public string? TreeAlias { get; set; } /// /// This is optional but if specified should be the name of an angular service to format the search result. /// [DataMember(Name = "jsSvc")] - public string JsFormatterService { get; set; } + public string? JsFormatterService { get; set; } /// /// This is optional but if specified should be the name of a method on the jsSvc angular service to use, if not /// specified than it will expect the method to be called `format(searchResult, appAlias, treeAlias)` /// [DataMember(Name = "jsMethod")] - public string JsFormatterMethod { get; set; } + public string? JsFormatterMethod { get; set; } [DataMember(Name = "results")] - public IEnumerable Results { get; set; } + public IEnumerable? Results { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs b/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs index 0dff38eefd..7a4e6d28d8 100644 --- a/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs +++ b/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs @@ -12,6 +12,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public int Id { get; set; } [DataMember(Name = "cultures")] - public string[] Cultures { get; set; } + public string[]? Cultures { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs b/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs index 4e9556c561..7b3014369a 100644 --- a/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs +++ b/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs @@ -17,18 +17,18 @@ namespace Umbraco.Cms.Core.Models.ContentEditing { [DataMember(Name = "userGroups")] [Required] - public IEnumerable UserGroups { get; set; } + public IEnumerable UserGroups { get; set; } = null!; [DataMember(Name = "email", IsRequired = true)] [Required] [EmailAddress] - public string Email { get; set; } + public string Email { get; set; } = null!; [DataMember(Name = "username")] public string? Username { get; set; } [DataMember(Name = "message")] - public string Message { get; set; } + public string? Message { get; set; } public IEnumerable Validate(ValidationContext validationContext) { diff --git a/src/Umbraco.Core/Models/ContentEditing/UserSave.cs b/src/Umbraco.Core/Models/ContentEditing/UserSave.cs index 7087f0f39c..6e03248a31 100644 --- a/src/Umbraco.Core/Models/ContentEditing/UserSave.cs +++ b/src/Umbraco.Core/Models/ContentEditing/UserSave.cs @@ -25,20 +25,20 @@ namespace Umbraco.Cms.Core.Models.ContentEditing [DataMember(Name = "username", IsRequired = true)] [Required] - public string Username { get; set; } + public string Username { get; set; } = null!; [DataMember(Name = "culture", IsRequired = true)] [Required] - public string Culture { get; set; } + public string Culture { get; set; } = null!; [DataMember(Name = "email", IsRequired = true)] [Required] [EmailAddress] - public string Email { get; set; } + public string Email { get; set; } = null!; [DataMember(Name = "userGroups")] [Required] - public IEnumerable UserGroups { get; set; } + public IEnumerable UserGroups { get; set; } = null!; [DataMember(Name = "startContentIds")] public int[]? StartContentIds { get; set; } diff --git a/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs b/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs index 7dcaee86b4..8001da7db8 100644 --- a/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs +++ b/src/Umbraco.Core/Models/ContentRepositoryExtensions.cs @@ -163,17 +163,20 @@ namespace Umbraco.Extensions var otherProperties = other.Properties; foreach (var otherProperty in otherProperties) { - if (!otherProperty.PropertyType?.SupportsVariation(culture, "*", wildcards: true) ?? true) + if (!otherProperty?.PropertyType?.SupportsVariation(culture, "*", wildcards: true) ?? true) continue; - var alias = otherProperty.PropertyType.Alias; - foreach (var pvalue in otherProperty.Values) + var alias = otherProperty?.PropertyType.Alias; + if (otherProperty is not null && alias is not null) { - if (otherProperty.PropertyType.SupportsVariation(pvalue.Culture, pvalue.Segment, wildcards: true) && - (culture == "*" || (pvalue.Culture?.InvariantEquals(culture) ?? false))) + foreach (var pvalue in otherProperty.Values) { - var value = published ? pvalue.PublishedValue : pvalue.EditedValue; - content.SetValue(alias, value, pvalue.Culture, pvalue.Segment); + if (otherProperty.PropertyType.SupportsVariation(pvalue.Culture, pvalue.Segment, wildcards: true) && + (culture == "*" || (pvalue.Culture?.InvariantEquals(culture) ?? false))) + { + var value = published ? pvalue.PublishedValue : pvalue.EditedValue; + content.SetValue(alias, value, pvalue.Culture, pvalue.Segment); + } } } } diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index d0d072df6a..958caa7235 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -256,7 +256,7 @@ namespace Umbraco.Cms.Core.Models { get { - return _noGroupPropertyTypes.Union(PropertyGroups.SelectMany(x => x.PropertyTypes)); + return _noGroupPropertyTypes.Union(PropertyGroups.SelectMany(x => x.PropertyTypes!)); } } @@ -351,14 +351,14 @@ namespace Umbraco.Cms.Core.Models // get old group var oldPropertyGroup = PropertyGroups.FirstOrDefault(x => - x.PropertyTypes.Any(y => y.Alias == propertyTypeAlias)); + x.PropertyTypes?.Any(y => y.Alias == propertyTypeAlias) ?? false); // set new group propertyType.PropertyGroupId = newPropertyGroup == null ? null : new Lazy(() => newPropertyGroup.Id, false); // remove from old group, if any - add to new group, if any - oldPropertyGroup?.PropertyTypes.RemoveItem(propertyTypeAlias); - newPropertyGroup?.PropertyTypes.Add(propertyType); + oldPropertyGroup?.PropertyTypes?.RemoveItem(propertyTypeAlias); + newPropertyGroup?.PropertyTypes?.Add(propertyType); return true; } @@ -372,7 +372,7 @@ namespace Umbraco.Cms.Core.Models //check through each property group to see if we can remove the property type by alias from it foreach (var propertyGroup in PropertyGroups) { - if (propertyGroup.PropertyTypes.RemoveItem(alias)) + if (propertyGroup.PropertyTypes?.RemoveItem(alias) ?? false) { if (!HasPropertyTypeBeenRemoved) { @@ -409,11 +409,14 @@ namespace Umbraco.Cms.Core.Models // first remove the group PropertyGroups.Remove(group); - // Then re-assign the group's properties to no group - foreach (var property in group.PropertyTypes) + if (group.PropertyTypes is not null) { - property.PropertyGroupId = null; - _noGroupPropertyTypes.Add(property); + // Then re-assign the group's properties to no group + foreach (var property in group.PropertyTypes) + { + property.PropertyGroupId = null; + _noGroupPropertyTypes.Add(property); + } } OnPropertyChanged(nameof(PropertyGroups)); @@ -457,12 +460,16 @@ namespace Umbraco.Cms.Core.Models foreach (var propertyGroup in PropertyGroups) { propertyGroup.ResetDirtyProperties(); - foreach (var propertyType in propertyGroup.PropertyTypes) + if (propertyGroup.PropertyTypes is not null) { - propertyType.ResetDirtyProperties(); - propertiesReset.Add(propertyType.Id); + foreach (var propertyType in propertyGroup.PropertyTypes) + { + propertyType.ResetDirtyProperties(); + propertiesReset.Add(propertyType.Id); + } } } + //then loop through our property type collection since some might not exist on a property group //but don't re-reset ones we've already done. foreach (var propertyType in PropertyTypes.Where(x => propertiesReset.Contains(x.Id) == false)) diff --git a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs index 531a04181c..541dc5f44e 100644 --- a/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeCompositionBase.cs @@ -70,8 +70,11 @@ namespace Umbraco.Cms.Core.Models .Select(group => { group = (PropertyGroup) group.DeepClone(); - foreach (var property in group.PropertyTypes) - AcquireProperty(property); + if (group.PropertyTypes is not null) + { + foreach (var property in group.PropertyTypes) + AcquireProperty(property); + } return group; })); } @@ -273,7 +276,7 @@ namespace Umbraco.Cms.Core.Models // add property to group propertyType.PropertyGroupId = new Lazy(() => group.Id); - group.PropertyTypes.Add(propertyType); + group.PropertyTypes?.Add(propertyType); return true; } diff --git a/src/Umbraco.Core/Models/ContentTypeImportModel.cs b/src/Umbraco.Core/Models/ContentTypeImportModel.cs index 46f091f039..49d09c6821 100644 --- a/src/Umbraco.Core/Models/ContentTypeImportModel.cs +++ b/src/Umbraco.Core/Models/ContentTypeImportModel.cs @@ -8,15 +8,15 @@ namespace Umbraco.Cms.Core.Models public class ContentTypeImportModel : INotificationModel { [DataMember(Name = "alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [DataMember(Name = "name")] - public string Name { get; set; } + public string? Name { get; set; } [DataMember(Name = "notifications")] public List Notifications { get; } = new List(); [DataMember(Name = "tempFileName")] - public string TempFileName { get; set; } + public string? TempFileName { get; set; } } } diff --git a/src/Umbraco.Core/Models/DictionaryItem.cs b/src/Umbraco.Core/Models/DictionaryItem.cs index 759d5b5680..79f922ecb7 100644 --- a/src/Umbraco.Core/Models/DictionaryItem.cs +++ b/src/Umbraco.Core/Models/DictionaryItem.cs @@ -14,7 +14,7 @@ namespace Umbraco.Cms.Core.Models [DataContract(IsReference = true)] public class DictionaryItem : EntityBase, IDictionaryItem { - public Func? GetLanguage { get; set; } + public Func? GetLanguage { get; set; } private Guid? _parentId; private string _itemKey; private IEnumerable? _translations; diff --git a/src/Umbraco.Core/Models/DictionaryTranslation.cs b/src/Umbraco.Core/Models/DictionaryTranslation.cs index 37350ef035..11b1229206 100644 --- a/src/Umbraco.Core/Models/DictionaryTranslation.cs +++ b/src/Umbraco.Core/Models/DictionaryTranslation.cs @@ -11,14 +11,14 @@ namespace Umbraco.Cms.Core.Models [DataContract(IsReference = true)] public class DictionaryTranslation : EntityBase, IDictionaryTranslation { - public Func? GetLanguage { get; set; } + public Func? GetLanguage { get; set; } private ILanguage? _language; private string? _value; //note: this will be memberwise cloned private int _languageId; - public DictionaryTranslation(ILanguage language, string value) + public DictionaryTranslation(ILanguage language, string? value) { if (language == null) throw new ArgumentNullException("language"); _language = language; diff --git a/src/Umbraco.Core/Models/Editors/ContentPropertyFile.cs b/src/Umbraco.Core/Models/Editors/ContentPropertyFile.cs index 9c1806cf08..6d008bc74f 100644 --- a/src/Umbraco.Core/Models/Editors/ContentPropertyFile.cs +++ b/src/Umbraco.Core/Models/Editors/ContentPropertyFile.cs @@ -9,17 +9,17 @@ /// /// Gets or sets the property alias. /// - public string PropertyAlias { get; set; } + public string? PropertyAlias { get; set; } /// /// When dealing with content variants, this is the culture for the variant /// - public string Culture { get; set; } + public string? Culture { get; set; } /// /// When dealing with content variants, this is the segment for the variant /// - public string Segment { get; set; } + public string? Segment { get; set; } /// /// An array of metadata that is parsed out from the file info posted to the server which is set on the client. @@ -28,16 +28,16 @@ /// This can be used for property types like Nested Content that need to have special unique identifiers for each file since there might be multiple files /// per property. /// - public string[] Metadata { get; set; } + public string[]? Metadata { get; set; } /// /// Gets or sets the name of the file. /// - public string FileName { get; set; } + public string? FileName { get; set; } /// /// Gets or sets the temporary path where the file has been uploaded. /// - public string TempFilePath { get; set; } + public string? TempFilePath { get; set; } } } diff --git a/src/Umbraco.Core/Models/Entities/ContentEntitySlim.cs b/src/Umbraco.Core/Models/Entities/ContentEntitySlim.cs index 45d23d26d4..74bd4e4f44 100644 --- a/src/Umbraco.Core/Models/Entities/ContentEntitySlim.cs +++ b/src/Umbraco.Core/Models/Entities/ContentEntitySlim.cs @@ -6,12 +6,12 @@ public class ContentEntitySlim : EntitySlim, IContentEntitySlim { /// - public string ContentTypeAlias { get; set; } + public string ContentTypeAlias { get; set; } = string.Empty; /// - public string ContentTypeIcon { get; set; } + public string? ContentTypeIcon { get; set; } /// - public string ContentTypeThumbnail { get; set; } + public string? ContentTypeThumbnail { get; set; } } } diff --git a/src/Umbraco.Core/Models/Entities/DocumentEntitySlim.cs b/src/Umbraco.Core/Models/Entities/DocumentEntitySlim.cs index b5aca80087..3bc410fc9b 100644 --- a/src/Umbraco.Core/Models/Entities/DocumentEntitySlim.cs +++ b/src/Umbraco.Core/Models/Entities/DocumentEntitySlim.cs @@ -11,9 +11,9 @@ namespace Umbraco.Cms.Core.Models.Entities { private static readonly IReadOnlyDictionary Empty = new Dictionary(); - private IReadOnlyDictionary _cultureNames; - private IEnumerable _publishedCultures; - private IEnumerable _editedCultures; + private IReadOnlyDictionary? _cultureNames; + private IEnumerable? _publishedCultures; + private IEnumerable? _editedCultures; /// public IReadOnlyDictionary CultureNames diff --git a/src/Umbraco.Core/Models/Entities/EntitySlim.cs b/src/Umbraco.Core/Models/Entities/EntitySlim.cs index 5ceaf98772..13ba662cdc 100644 --- a/src/Umbraco.Core/Models/Entities/EntitySlim.cs +++ b/src/Umbraco.Core/Models/Entities/EntitySlim.cs @@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Models.Entities /// [DataMember] - public string Name { get; set; } + public string? Name { get; set; } /// [DataMember] @@ -72,7 +72,7 @@ namespace Umbraco.Cms.Core.Models.Entities /// [DataMember] - public string? Path { get; set; } + public string Path { get; set; } = string.Empty; /// [DataMember] diff --git a/src/Umbraco.Core/Models/Entities/IContentEntitySlim.cs b/src/Umbraco.Core/Models/Entities/IContentEntitySlim.cs index 43de032894..52ea701af3 100644 --- a/src/Umbraco.Core/Models/Entities/IContentEntitySlim.cs +++ b/src/Umbraco.Core/Models/Entities/IContentEntitySlim.cs @@ -13,11 +13,11 @@ /// /// Gets the content type icon. /// - string ContentTypeIcon { get; } + string? ContentTypeIcon { get; } /// /// Gets the content type thumbnail. /// - string ContentTypeThumbnail { get; } + string? ContentTypeThumbnail { get; } } } diff --git a/src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs b/src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs index 15060e3a45..3a2996c6fe 100644 --- a/src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs +++ b/src/Umbraco.Core/Models/Entities/IMediaEntitySlim.cs @@ -9,6 +9,6 @@ /// /// The media file's path/URL /// - string MediaPath { get; } + string? MediaPath { get; } } } diff --git a/src/Umbraco.Core/Models/Entities/ITreeEntity.cs b/src/Umbraco.Core/Models/Entities/ITreeEntity.cs index 79264c3bf0..0024a7cdc4 100644 --- a/src/Umbraco.Core/Models/Entities/ITreeEntity.cs +++ b/src/Umbraco.Core/Models/Entities/ITreeEntity.cs @@ -8,7 +8,7 @@ /// /// Gets or sets the name of the entity. /// - string Name { get; set; } + string? Name { get; set; } /// /// Gets or sets the identifier of the user who created this entity. @@ -37,7 +37,7 @@ /// /// Gets or sets the path to the entity. /// - string? Path { get; set; } + string Path { get; set; } /// /// Gets or sets the sort order of the entity. diff --git a/src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs b/src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs index 41d024de3b..fd3c01e15c 100644 --- a/src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs +++ b/src/Umbraco.Core/Models/Entities/MediaEntitySlim.cs @@ -5,6 +5,6 @@ /// public class MediaEntitySlim : ContentEntitySlim, IMediaEntitySlim { - public string MediaPath { get; set; } + public string? MediaPath { get; set; } } } diff --git a/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs b/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs index 680dbdde0f..54befb1f1f 100644 --- a/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs +++ b/src/Umbraco.Core/Models/Entities/TreeEntityBase.cs @@ -14,7 +14,7 @@ namespace Umbraco.Cms.Core.Models.Entities private bool _hasParentId; private ITreeEntity? _parent; private int _level; - private string? _path; + private string _path = String.Empty; private int _sortOrder; private bool _trashed; @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Core.Models.Entities public string? Name { get => _name; - set => SetPropertyValueAndDetectChanges(value, ref _name, nameof(Name)); + set => SetPropertyValueAndDetectChanges(value, ref _name!, nameof(Name)); } /// @@ -81,10 +81,10 @@ namespace Umbraco.Cms.Core.Models.Entities /// [DataMember] - public string? Path + public string Path { get => _path; - set => SetPropertyValueAndDetectChanges(value, ref _path, nameof(Path)); + set => SetPropertyValueAndDetectChanges(value, ref _path!, nameof(Path)); } /// diff --git a/src/Umbraco.Core/Models/Entities/TreeEntityPath.cs b/src/Umbraco.Core/Models/Entities/TreeEntityPath.cs index a9a1e339df..6fd147ace7 100644 --- a/src/Umbraco.Core/Models/Entities/TreeEntityPath.cs +++ b/src/Umbraco.Core/Models/Entities/TreeEntityPath.cs @@ -13,6 +13,6 @@ /// /// Gets or sets the path of the entity. /// - public string Path { get; set; } + public string Path { get; set; } = null!; } } diff --git a/src/Umbraco.Core/Models/IDataValueEditor.cs b/src/Umbraco.Core/Models/IDataValueEditor.cs index 41fbaa6c25..e3f7100241 100644 --- a/src/Umbraco.Core/Models/IDataValueEditor.cs +++ b/src/Umbraco.Core/Models/IDataValueEditor.cs @@ -40,7 +40,7 @@ namespace Umbraco.Cms.Core.Models /// The property value. /// A value indicating whether the property value is required. /// A specific format (regex) that the property value must respect. - IEnumerable Validate(object value, bool required, string? format); + IEnumerable Validate(object? value, bool required, string? format); /// /// Gets the validators to use to validate the edited value. diff --git a/src/Umbraco.Core/Models/ITwoFactorLogin.cs b/src/Umbraco.Core/Models/ITwoFactorLogin.cs index ca005309b2..92b798fe0d 100644 --- a/src/Umbraco.Core/Models/ITwoFactorLogin.cs +++ b/src/Umbraco.Core/Models/ITwoFactorLogin.cs @@ -5,8 +5,8 @@ namespace Umbraco.Cms.Core.Models { public interface ITwoFactorLogin: IEntity, IRememberBeingDirty { - string ProviderName { get; } - string Secret { get; } + string? ProviderName { get; } + string? Secret { get; } Guid UserOrMemberKey { get; } } } diff --git a/src/Umbraco.Core/Models/IconModel.cs b/src/Umbraco.Core/Models/IconModel.cs index 75e90cf0fb..081b0516ad 100644 --- a/src/Umbraco.Core/Models/IconModel.cs +++ b/src/Umbraco.Core/Models/IconModel.cs @@ -2,7 +2,7 @@ namespace Umbraco.Cms.Core.Models { public class IconModel { - public string Name { get; set; } - public string SvgString { get; set; } + public string? Name { get; set; } + public string? SvgString { get; set; } } } diff --git a/src/Umbraco.Core/Models/Link.cs b/src/Umbraco.Core/Models/Link.cs index f461eb850d..3bfc9c5a0d 100644 --- a/src/Umbraco.Core/Models/Link.cs +++ b/src/Umbraco.Core/Models/Link.cs @@ -2,10 +2,10 @@ { public class Link { - public string Name { get; set; } - public string Target { get; set; } + public string? Name { get; set; } + public string? Target { get; set; } public LinkType Type { get; set; } - public Udi Udi { get; set; } - public string Url { get; set; } + public Udi? Udi { get; set; } + public string? Url { get; set; } } } diff --git a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs index 801aa746c0..f150523e69 100644 --- a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs +++ b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Core.Models.Mapping targetWithHistoryCleanup.HistoryCleanup = source.HistoryCleanup; } - target.AllowedTemplates = source.AllowedTemplates + target.AllowedTemplates = source.AllowedTemplates? .Where(x => x != null) .Select(_fileService.GetTemplate) .Where(x => x != null) @@ -349,7 +349,7 @@ namespace Umbraco.Cms.Core.Models.Mapping //sync templates IEnumerable destAllowedTemplateAliases = target.AllowedTemplates.Select(x => x.Alias); //if the dest is set and it's the same as the source, then don't change - if (destAllowedTemplateAliases.SequenceEqual(source.AllowedTemplates) == false) + if (source.AllowedTemplates is not null && destAllowedTemplateAliases.SequenceEqual(source.AllowedTemplates) == false) { IEnumerable templates = _fileService.GetTemplates(source.AllowedTemplates.ToArray()); target.AllowedTemplates = source.AllowedTemplates diff --git a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs index 2021afa4c2..82631776ba 100644 --- a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs @@ -181,7 +181,7 @@ namespace Umbraco.Cms.Core.Models.Mapping } // else update the dictionary to "true" for the user roles (except internal roles) - foreach (var userRole in userRoles.Where(x => x.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false)) + foreach (var userRole in userRoles.Where(x => x?.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false)) { result[userRole] = true; } diff --git a/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs b/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs index 57142db213..50b53c073e 100644 --- a/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs @@ -205,11 +205,11 @@ namespace Umbraco.Cms.Core.Models.Mapping return groups.OrderBy(x => x.SortOrder); } - private IEnumerable MapProperties(IEnumerable properties, IContentTypeBase contentType, int groupId, bool inherited) + private IEnumerable MapProperties(IEnumerable? properties, IContentTypeBase contentType, int groupId, bool inherited) { var mappedProperties = new List(); - foreach (var p in properties.Where(x => x.DataTypeId != 0).OrderBy(x => x.SortOrder)) + foreach (var p in properties?.Where(x => x.DataTypeId != 0).OrderBy(x => x.SortOrder) ?? Enumerable.Empty()) { var propertyEditorAlias = p.PropertyEditorAlias; var propertyEditor = _propertyEditors[propertyEditorAlias]; diff --git a/src/Umbraco.Core/Models/Media.cs b/src/Umbraco.Core/Models/Media.cs index 7a0264caf3..60542d78cb 100644 --- a/src/Umbraco.Core/Models/Media.cs +++ b/src/Umbraco.Core/Models/Media.cs @@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.Models /// name of the Media object /// Parent object /// MediaType for the current Media object - public Media(string name, IMedia parent, IMediaType mediaType) + public Media(string? name, IMedia? parent, IMediaType mediaType) : this(name, parent, mediaType, new PropertyCollection()) { } @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.Models /// Parent object /// MediaType for the current Media object /// Collection of properties - public Media(string name, IMedia parent, IMediaType mediaType, IPropertyCollection properties) + public Media(string? name, IMedia? parent, IMediaType mediaType, IPropertyCollection properties) : base(name, parent, mediaType, properties) { } @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Models /// name of the Media object /// Id of the Parent IMedia /// MediaType for the current Media object - public Media(string name, int parentId, IMediaType mediaType) + public Media(string? name, int parentId, IMediaType mediaType) : this(name, parentId, mediaType, new PropertyCollection()) { } @@ -48,7 +48,7 @@ namespace Umbraco.Cms.Core.Models /// Id of the Parent IMedia /// MediaType for the current Media object /// Collection of properties - public Media(string name, int parentId, IMediaType mediaType, IPropertyCollection properties) + public Media(string? name, int parentId, IMediaType mediaType, IPropertyCollection properties) : base(name, parentId, mediaType, properties) { } diff --git a/src/Umbraco.Core/Models/MemberPropertyModel.cs b/src/Umbraco.Core/Models/MemberPropertyModel.cs index 0557b226c3..cd23d01a5d 100644 --- a/src/Umbraco.Core/Models/MemberPropertyModel.cs +++ b/src/Umbraco.Core/Models/MemberPropertyModel.cs @@ -9,7 +9,7 @@ namespace Umbraco.Cms.Core.Models public class MemberPropertyModel { [Required] - public string Alias { get; set; } + public string? Alias { get; set; } //NOTE: This has to be a string currently, if it is an object it will bind as an array which we don't want. // If we want to have this as an 'object' with a true type on it, we have to create a custom model binder @@ -19,10 +19,10 @@ namespace Umbraco.Cms.Core.Models // real type anyways. [DataType(System.ComponentModel.DataAnnotations.DataType.Text)] - public string Value { get; set; } + public string? Value { get; set; } [ReadOnly(true)] - public string Name { get; set; } + public string? Name { get; set; } // TODO: Perhaps one day we'll ship with our own EditorTempates but for now developers can just render their own inside the view diff --git a/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs b/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs index 6be3736bce..be84b4bca6 100644 --- a/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Models.Membership /// public interface IReadOnlyUserGroup { - string Name { get; } + string? Name { get; } string? Icon { get; } int Id { get; } int? StartContentId { get; } diff --git a/src/Umbraco.Core/Models/Membership/IUser.cs b/src/Umbraco.Core/Models/Membership/IUser.cs index ca41d892e7..c7c68dabda 100644 --- a/src/Umbraco.Core/Models/Membership/IUser.cs +++ b/src/Umbraco.Core/Models/Membership/IUser.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Models.Membership { UserState UserState { get; } - string Name { get; set; } + string? Name { get; set; } int SessionTimeout { get; set; } int[]? StartContentIds { get; set; } int[]? StartMediaIds { get; set; } diff --git a/src/Umbraco.Core/Models/Membership/IUserGroup.cs b/src/Umbraco.Core/Models/Membership/IUserGroup.cs index 10ed2455e4..96ae3c6dfb 100644 --- a/src/Umbraco.Core/Models/Membership/IUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/IUserGroup.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Models.Membership /// /// The name /// - string Name { get; set; } + string? Name { get; set; } /// /// The set of default permissions diff --git a/src/Umbraco.Core/Models/Membership/MemberExportModel.cs b/src/Umbraco.Core/Models/Membership/MemberExportModel.cs index b4114e154f..e577c86e70 100644 --- a/src/Umbraco.Core/Models/Membership/MemberExportModel.cs +++ b/src/Umbraco.Core/Models/Membership/MemberExportModel.cs @@ -7,13 +7,13 @@ namespace Umbraco.Cms.Core.Models.Membership { public int Id { get; set; } public Guid Key { get; set; } - public string Name { get; set; } - public string Username { get; set; } - public string Email { get; set; } - public List Groups { get; set; } - public string ContentTypeAlias { get; set; } + public string? Name { get; set; } + public string? Username { get; set; } + public string? Email { get; set; } + public List? Groups { get; set; } + public string? ContentTypeAlias { get; set; } public DateTime CreateDate { get; set; } public DateTime UpdateDate { get; set; } - public List Properties { get; set; } + public List? Properties { get; set; } } } diff --git a/src/Umbraco.Core/Models/Membership/MemberExportProperty.cs b/src/Umbraco.Core/Models/Membership/MemberExportProperty.cs index b55ed8a866..fec933190c 100644 --- a/src/Umbraco.Core/Models/Membership/MemberExportProperty.cs +++ b/src/Umbraco.Core/Models/Membership/MemberExportProperty.cs @@ -5,9 +5,9 @@ namespace Umbraco.Cms.Core.Models.Membership public class MemberExportProperty { public int Id { get; set; } - public string Alias { get; set; } - public string Name { get; set; } - public object Value { get; set; } + public string? Alias { get; set; } + public string? Name { get; set; } + public object? Value { get; set; } public DateTime? CreateDate { get; set; } public DateTime? UpdateDate { get; set; } } diff --git a/src/Umbraco.Core/Models/Membership/PersistedPasswordSettings.cs b/src/Umbraco.Core/Models/Membership/PersistedPasswordSettings.cs index d3ae5c5920..3e4831d9c3 100644 --- a/src/Umbraco.Core/Models/Membership/PersistedPasswordSettings.cs +++ b/src/Umbraco.Core/Models/Membership/PersistedPasswordSettings.cs @@ -17,6 +17,6 @@ namespace Umbraco.Cms.Core.Models.Membership /// PBKDF2 with HMAC-SHA256, 128-bit salt, 256-bit subkey, 10000 iterations. /// [DataMember(Name = "hashAlgorithm")] - public string HashAlgorithm { get; set; } + public string? HashAlgorithm { get; set; } } } diff --git a/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs b/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs index 9767ee19b2..261e62e604 100644 --- a/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/ReadOnlyUserGroup.cs @@ -9,7 +9,7 @@ namespace Umbraco.Cms.Core.Models.Membership public ReadOnlyUserGroup(int id, string? name, string? icon, int? startContentId, int? startMediaId, string @alias, IEnumerable allowedSections, IEnumerable? permissions) { - Name = name; + Name = name ?? string.Empty; Icon = icon; Id = id; Alias = alias; @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Models.Membership } public int Id { get; private set; } - public string? Name { get; private set; } + public string Name { get; private set; } public string? Icon { get; private set; } public int? StartContentId { get; private set; } public int? StartMediaId { get; private set; } diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index f8b1da4251..b2100a002e 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -30,6 +30,8 @@ namespace Umbraco.Cms.Core.Models.Membership _startMediaIds = new int[] { }; //cannot be null _rawPasswordValue = ""; + _username = string.Empty; + _email = string.Empty; } /// @@ -105,10 +107,10 @@ namespace Umbraco.Cms.Core.Models.Membership private int[]? _startMediaIds; private int _failedLoginAttempts; - private string? _username; + private string _username; private DateTime? _emailConfirmedDate; private DateTime? _invitedDate; - private string? _email; + private string _email; private string? _rawPasswordValue; private string? _passwordConfig; private IEnumerable? _allowedSections; @@ -142,17 +144,17 @@ namespace Umbraco.Cms.Core.Models.Membership } [DataMember] - public string? Username + public string Username { get => _username; - set => SetPropertyValueAndDetectChanges(value, ref _username, nameof(Username)); + set => SetPropertyValueAndDetectChanges(value, ref _username!, nameof(Username)); } [DataMember] - public string? Email + public string Email { get => _email; - set => SetPropertyValueAndDetectChanges(value, ref _email, nameof(Email)); + set => SetPropertyValueAndDetectChanges(value, ref _email!, nameof(Email)); } [IgnoreDataMember] diff --git a/src/Umbraco.Core/Models/Membership/UserGroup.cs b/src/Umbraco.Core/Models/Membership/UserGroup.cs index aff58b670a..dd91cd6445 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroup.cs @@ -35,6 +35,7 @@ namespace Umbraco.Cms.Core.Models.Membership public UserGroup(IShortStringHelper shortStringHelper) { _alias = string.Empty; + _name = string.Empty; _shortStringHelper = shortStringHelper; _sectionCollection = new List(); } diff --git a/src/Umbraco.Core/Models/NotificationEmailBodyParams.cs b/src/Umbraco.Core/Models/NotificationEmailBodyParams.cs index 89d67763d1..5174ee636b 100644 --- a/src/Umbraco.Core/Models/NotificationEmailBodyParams.cs +++ b/src/Umbraco.Core/Models/NotificationEmailBodyParams.cs @@ -4,7 +4,7 @@ namespace Umbraco.Cms.Core.Models { public class NotificationEmailBodyParams { - public NotificationEmailBodyParams(string recipientName, string action, string itemName, string itemId, string itemUrl, string editedUser, string siteUrl, string summary) + public NotificationEmailBodyParams(string? recipientName, string? action, string? itemName, string itemId, string itemUrl, string? editedUser, string siteUrl, string summary) { RecipientName = recipientName ?? throw new ArgumentNullException(nameof(recipientName)); Action = action ?? throw new ArgumentNullException(nameof(action)); diff --git a/src/Umbraco.Core/Models/NotificationEmailSubjectParams.cs b/src/Umbraco.Core/Models/NotificationEmailSubjectParams.cs index fea247d6bf..c644f7c1a6 100644 --- a/src/Umbraco.Core/Models/NotificationEmailSubjectParams.cs +++ b/src/Umbraco.Core/Models/NotificationEmailSubjectParams.cs @@ -5,7 +5,7 @@ namespace Umbraco.Cms.Core.Models public class NotificationEmailSubjectParams { - public NotificationEmailSubjectParams(string siteUrl, string action, string itemName) + public NotificationEmailSubjectParams(string siteUrl, string? action, string? itemName) { SiteUrl = siteUrl ?? throw new ArgumentNullException(nameof(siteUrl)); Action = action ?? throw new ArgumentNullException(nameof(action)); diff --git a/src/Umbraco.Core/Models/Packaging/InstallWarnings.cs b/src/Umbraco.Core/Models/Packaging/InstallWarnings.cs index 2425465989..7cad9b5b9a 100644 --- a/src/Umbraco.Core/Models/Packaging/InstallWarnings.cs +++ b/src/Umbraco.Core/Models/Packaging/InstallWarnings.cs @@ -7,8 +7,8 @@ namespace Umbraco.Cms.Core.Models.Packaging public class InstallWarnings { // TODO: Shouldn't we detect other conflicting entities too ? - public IEnumerable? ConflictingMacros { get; set; } = Enumerable.Empty(); + public IEnumerable? ConflictingMacros { get; set; } = Enumerable.Empty(); public IEnumerable? ConflictingTemplates { get; set; } = Enumerable.Empty(); - public IEnumerable? ConflictingStylesheets { get; set; } = Enumerable.Empty(); + public IEnumerable? ConflictingStylesheets { get; set; } = Enumerable.Empty(); } } diff --git a/src/Umbraco.Core/Models/PasswordChangedModel.cs b/src/Umbraco.Core/Models/PasswordChangedModel.cs index 11696cfc08..231940f105 100644 --- a/src/Umbraco.Core/Models/PasswordChangedModel.cs +++ b/src/Umbraco.Core/Models/PasswordChangedModel.cs @@ -10,11 +10,11 @@ namespace Umbraco.Cms.Core.Models /// /// The error affiliated with the failing password changes, null if changing was successful /// - public ValidationResult ChangeError { get; set; } + public ValidationResult? ChangeError { get; set; } /// /// If the password was reset, this is the value it has been changed to /// - public string ResetPassword { get; set; } + public string? ResetPassword { get; set; } } } diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index d1d853ecf8..17e6603284 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Core.Models private string? _name; private string _alias; private int _sortOrder; - private PropertyTypeCollection _propertyTypes; + private PropertyTypeCollection? _propertyTypes; public PropertyGroup(bool isPublishing) : this(new PropertyTypeCollection(isPublishing)) @@ -110,7 +110,7 @@ namespace Umbraco.Cms.Core.Models /// [DataMember] [DoNotClone] - public PropertyTypeCollection PropertyTypes + public PropertyTypeCollection? PropertyTypes { get => _propertyTypes; set @@ -122,13 +122,16 @@ namespace Umbraco.Cms.Core.Models _propertyTypes = value; - // since we're adding this collection to this group, - // we need to ensure that all the lazy values are set. - foreach (var propertyType in _propertyTypes) - propertyType.PropertyGroupId = new Lazy(() => Id); + if (_propertyTypes is not null) + { + // since we're adding this collection to this group, + // we need to ensure that all the lazy values are set. + foreach (var propertyType in _propertyTypes) + propertyType.PropertyGroupId = new Lazy(() => Id); - OnPropertyChanged(nameof(PropertyTypes)); - _propertyTypes.CollectionChanged += PropertyTypesChanged; + OnPropertyChanged(nameof(PropertyTypes)); + _propertyTypes.CollectionChanged += PropertyTypesChanged; + } } } diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs index 411c4d55cf..eb52339936 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs @@ -133,17 +133,17 @@ namespace Umbraco.Cms.Core.Models.PublishedContent /// Gets the parent of the content item. /// /// The parent of root content is null. - IPublishedContent Parent { get; } + IPublishedContent? Parent { get; } /// /// Gets the children of the content item that are available for the current culture. /// - IEnumerable Children { get; } + IEnumerable? Children { get; } /// /// Gets all the children of the content item, regardless of whether they are available for the current culture. /// - IEnumerable ChildrenForAllCultures { get; } + IEnumerable? ChildrenForAllCultures { get; } #endregion } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs index c229941586..0ece44a828 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentBase.cs @@ -88,7 +88,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent public abstract IPublishedContent Parent { get; } /// - public virtual IEnumerable Children => this.Children(_variationContextAccessor); + public virtual IEnumerable? Children => this.Children(_variationContextAccessor); /// public abstract IEnumerable ChildrenForAllCultures { get; } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs index 3cf1f3c512..55e4e642dd 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentWrapped.cs @@ -109,13 +109,13 @@ namespace Umbraco.Cms.Core.Models.PublishedContent #region Tree /// - public virtual IPublishedContent Parent => _content.Parent; + public virtual IPublishedContent? Parent => _content.Parent; /// - public virtual IEnumerable Children => _content.Children; + public virtual IEnumerable? Children => _content.Children; /// - public virtual IEnumerable ChildrenForAllCultures => _content.ChildrenForAllCultures; + public virtual IEnumerable? ChildrenForAllCultures => _content.ChildrenForAllCultures; #endregion diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs index 180503341b..9525a9d7ac 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedCultureInfos.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent /// /// Initializes a new instance of the class. /// - public PublishedCultureInfo(string culture, string name, string urlSegment, DateTime date) + public PublishedCultureInfo(string culture, string? name, string? urlSegment, DateTime date) { if (name == null) throw new ArgumentNullException(nameof(name)); if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(name)); @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent /// /// Gets the URL segment of the item. /// - public string UrlSegment { get; } + public string? UrlSegment { get; } /// /// Gets the date associated with the culture. diff --git a/src/Umbraco.Core/Models/RequestPasswordResetModel.cs b/src/Umbraco.Core/Models/RequestPasswordResetModel.cs index 10ade8b589..438e97fb30 100644 --- a/src/Umbraco.Core/Models/RequestPasswordResetModel.cs +++ b/src/Umbraco.Core/Models/RequestPasswordResetModel.cs @@ -9,6 +9,6 @@ namespace Umbraco.Cms.Core.Models { [Required] [DataMember(Name = "email", IsRequired = true)] - public string Email { get; set; } + public string Email { get; set; } = null!; } } diff --git a/src/Umbraco.Core/Models/SendCodeViewModel.cs b/src/Umbraco.Core/Models/SendCodeViewModel.cs index 2e33702932..783bcdeec2 100644 --- a/src/Umbraco.Core/Models/SendCodeViewModel.cs +++ b/src/Umbraco.Core/Models/SendCodeViewModel.cs @@ -11,11 +11,11 @@ namespace Umbraco.Cms.Core.Models { [Required] [DataMember(Name = "code", IsRequired = true)] - public string Code { get; set; } + public string? Code { get; set; } [Required] [DataMember(Name = "provider", IsRequired = true)] - public string Provider { get; set; } + public string? Provider { get; set; } /// /// Flag indicating whether the sign-in cookie should persist after the browser is closed. diff --git a/src/Umbraco.Core/Models/SetPasswordModel.cs b/src/Umbraco.Core/Models/SetPasswordModel.cs index dece266d74..c904f98694 100644 --- a/src/Umbraco.Core/Models/SetPasswordModel.cs +++ b/src/Umbraco.Core/Models/SetPasswordModel.cs @@ -12,10 +12,10 @@ namespace Umbraco.Cms.Core.Models [Required] [DataMember(Name = "password", IsRequired = true)] - public string Password { get; set; } + public string? Password { get; set; } [Required] [DataMember(Name = "resetCode", IsRequired = true)] - public string ResetCode { get; set; } + public string? ResetCode { get; set; } } } diff --git a/src/Umbraco.Core/Models/TemplateQuery/ContentTypeModel.cs b/src/Umbraco.Core/Models/TemplateQuery/ContentTypeModel.cs index e032b4ca11..f4f3e7bc59 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/ContentTypeModel.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/ContentTypeModel.cs @@ -2,8 +2,8 @@ { public class ContentTypeModel { - public string Alias { get; set; } + public string? Alias { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } diff --git a/src/Umbraco.Core/Models/TemplateQuery/PropertyModel.cs b/src/Umbraco.Core/Models/TemplateQuery/PropertyModel.cs index 4270f9d48f..3ea4059b7e 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/PropertyModel.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/PropertyModel.cs @@ -2,10 +2,10 @@ { public class PropertyModel { - public string Name { get; set; } + public string? Name { get; set; } - public string Alias { get; set; } + public string Alias { get; set; } = string.Empty; - public string Type { get; set; } + public string? Type { get; set; } } } diff --git a/src/Umbraco.Core/Models/TemplateQuery/QueryConditionExtensions.cs b/src/Umbraco.Core/Models/TemplateQuery/QueryConditionExtensions.cs index 4edda6ad5d..962cf92558 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/QueryConditionExtensions.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/QueryConditionExtensions.cs @@ -13,7 +13,7 @@ namespace Umbraco.Extensions public static Expression> BuildCondition(this QueryCondition condition, string parameterAlias) { object constraintValue; - switch (condition.Property.Type.ToLowerInvariant()) + switch (condition.Property.Type?.ToLowerInvariant()) { case "string": constraintValue = condition.ConstraintValue; diff --git a/src/Umbraco.Core/Models/TemplateQuery/QueryModel.cs b/src/Umbraco.Core/Models/TemplateQuery/QueryModel.cs index a18d1e4021..48d6506143 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/QueryModel.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/QueryModel.cs @@ -4,10 +4,10 @@ namespace Umbraco.Cms.Core.Models.TemplateQuery { public class QueryModel { - public ContentTypeModel ContentType { get; set; } - public SourceModel Source { get; set; } - public IEnumerable Filters { get; set; } - public SortExpression Sort { get; set; } + public ContentTypeModel? ContentType { get; set; } + public SourceModel? Source { get; set; } + public IEnumerable? Filters { get; set; } + public SortExpression? Sort { get; set; } public int Take { get; set; } } } diff --git a/src/Umbraco.Core/Models/TemplateQuery/QueryResultModel.cs b/src/Umbraco.Core/Models/TemplateQuery/QueryResultModel.cs index b4cd15fce4..8605f92423 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/QueryResultModel.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/QueryResultModel.cs @@ -6,8 +6,8 @@ namespace Umbraco.Cms.Core.Models.TemplateQuery public class QueryResultModel { - public string QueryExpression { get; set; } - public IEnumerable SampleResults { get; set; } + public string? QueryExpression { get; set; } + public IEnumerable? SampleResults { get; set; } public int ResultCount { get; set; } public long ExecutionTime { get; set; } public int Take { get; set; } diff --git a/src/Umbraco.Core/Models/TemplateQuery/SortExpression.cs b/src/Umbraco.Core/Models/TemplateQuery/SortExpression.cs index 8a66819b72..c68b366ba5 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/SortExpression.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/SortExpression.cs @@ -2,8 +2,8 @@ { public class SortExpression { - public PropertyModel Property { get; set; } + public PropertyModel? Property { get; set; } - public string Direction { get; set; } + public string? Direction { get; set; } } } diff --git a/src/Umbraco.Core/Models/TemplateQuery/SourceModel.cs b/src/Umbraco.Core/Models/TemplateQuery/SourceModel.cs index 95e7fbc3e7..4b67f7e73c 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/SourceModel.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/SourceModel.cs @@ -3,6 +3,6 @@ public class SourceModel { public int Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } diff --git a/src/Umbraco.Core/Models/TemplateQuery/TemplateQueryResult.cs b/src/Umbraco.Core/Models/TemplateQuery/TemplateQueryResult.cs index 8519862de8..95615b4d0d 100644 --- a/src/Umbraco.Core/Models/TemplateQuery/TemplateQueryResult.cs +++ b/src/Umbraco.Core/Models/TemplateQuery/TemplateQueryResult.cs @@ -2,8 +2,8 @@ { public class TemplateQueryResult { - public string Icon { get; set; } + public string? Icon { get; set; } - public string Name { get; set; } + public string? Name { get; set; } } } diff --git a/src/Umbraco.Core/Models/TwoFactorLogin.cs b/src/Umbraco.Core/Models/TwoFactorLogin.cs index 6ede9606e8..350a5f2f1a 100644 --- a/src/Umbraco.Core/Models/TwoFactorLogin.cs +++ b/src/Umbraco.Core/Models/TwoFactorLogin.cs @@ -5,8 +5,8 @@ namespace Umbraco.Cms.Core.Models { public class TwoFactorLogin : EntityBase, ITwoFactorLogin { - public string ProviderName { get; set; } - public string Secret { get; set; } + public string? ProviderName { get; set; } + public string? Secret { get; set; } public Guid UserOrMemberKey { get; set; } public bool Confirmed { get; set; } } diff --git a/src/Umbraco.Core/Models/UnLinkLoginModel.cs b/src/Umbraco.Core/Models/UnLinkLoginModel.cs index 38d1901c12..d8c9920c5e 100644 --- a/src/Umbraco.Core/Models/UnLinkLoginModel.cs +++ b/src/Umbraco.Core/Models/UnLinkLoginModel.cs @@ -7,10 +7,10 @@ namespace Umbraco.Cms.Core.Models { [Required] [DataMember(Name = "loginProvider", IsRequired = true)] - public string LoginProvider { get; set; } + public string? LoginProvider { get; set; } [Required] [DataMember(Name = "providerKey", IsRequired = true)] - public string ProviderKey { get; set; } + public string? ProviderKey { get; set; } } } diff --git a/src/Umbraco.Core/Models/UserTourStatus.cs b/src/Umbraco.Core/Models/UserTourStatus.cs index cc3b43dd0f..1b83721f02 100644 --- a/src/Umbraco.Core/Models/UserTourStatus.cs +++ b/src/Umbraco.Core/Models/UserTourStatus.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Models /// The tour alias /// [DataMember(Name = "alias")] - public string Alias { get; set; } + public string Alias { get; set; } = string.Empty; /// /// If the tour is completed diff --git a/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs b/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs index 8f1ff2f49c..d104383b38 100644 --- a/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs +++ b/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs @@ -14,6 +14,6 @@ namespace Umbraco.Cms.Core.Models [Required] [DataMember(Name = "resetCode", IsRequired = true)] - public string ResetCode { get; set; } + public string? ResetCode { get; set; } } } diff --git a/src/Umbraco.Core/Notifications/IStatefulNotification.cs b/src/Umbraco.Core/Notifications/IStatefulNotification.cs index 7fa2382038..87d2b58cde 100644 --- a/src/Umbraco.Core/Notifications/IStatefulNotification.cs +++ b/src/Umbraco.Core/Notifications/IStatefulNotification.cs @@ -4,6 +4,6 @@ namespace Umbraco.Cms.Core.Notifications { public interface IStatefulNotification : INotification { - IDictionary State { get; set; } + IDictionary? State { get; set; } } } diff --git a/src/Umbraco.Core/Notifications/NotificationExtensions.cs b/src/Umbraco.Core/Notifications/NotificationExtensions.cs index 53677c05a1..c00606a219 100644 --- a/src/Umbraco.Core/Notifications/NotificationExtensions.cs +++ b/src/Umbraco.Core/Notifications/NotificationExtensions.cs @@ -4,7 +4,7 @@ namespace Umbraco.Cms.Core.Notifications { public static class NotificationExtensions { - public static T WithState(this T notification, IDictionary state) where T : IStatefulNotification + public static T WithState(this T notification, IDictionary? state) where T : IStatefulNotification { notification.State = state; return notification; diff --git a/src/Umbraco.Core/Notifications/StatefulNotification.cs b/src/Umbraco.Core/Notifications/StatefulNotification.cs index 940e8ac45f..2ff89578f2 100644 --- a/src/Umbraco.Core/Notifications/StatefulNotification.cs +++ b/src/Umbraco.Core/Notifications/StatefulNotification.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Notifications /// This can be used by event subscribers to store state in the notification so they easily deal with custom state data between /// a starting ("ing") and an ending ("ed") notification /// - public IDictionary State + public IDictionary? State { get => _state ??= new Dictionary(); set => _state = value; diff --git a/src/Umbraco.Core/Notifications/TemplateSavedNotification.cs b/src/Umbraco.Core/Notifications/TemplateSavedNotification.cs index ae07680f34..ad75a32c02 100644 --- a/src/Umbraco.Core/Notifications/TemplateSavedNotification.cs +++ b/src/Umbraco.Core/Notifications/TemplateSavedNotification.cs @@ -24,29 +24,42 @@ namespace Umbraco.Cms.Core.Notifications { get { - State.TryGetValue(s_templateForContentTypeKey, out var result); - - if (result is not bool createTemplate) + if (State?.TryGetValue(s_templateForContentTypeKey, out var result) ?? false) { - return false; + if (result is not bool createTemplate) + { + return false; + } + + return createTemplate; } - return createTemplate; + return false; + } + set + { + if (!value is bool && State is not null) + { + State[s_templateForContentTypeKey] = value; + } } - set => State[s_templateForContentTypeKey] = value; } public string? ContentTypeAlias { get { - State.TryGetValue(s_contentTypeAliasKey, out var result); - return result as string; + if (State?.TryGetValue(s_contentTypeAliasKey, out var result) ?? false) + { + return result as string; + } + + return null; } set { - if (value is not null) + if (value is not null && State is not null) { State[s_contentTypeAliasKey] = value; } diff --git a/src/Umbraco.Core/Notifications/TemplateSavingNotification.cs b/src/Umbraco.Core/Notifications/TemplateSavingNotification.cs index b06a3f581a..95a681d2f8 100644 --- a/src/Umbraco.Core/Notifications/TemplateSavingNotification.cs +++ b/src/Umbraco.Core/Notifications/TemplateSavingNotification.cs @@ -39,29 +39,42 @@ namespace Umbraco.Cms.Core.Notifications { get { - State.TryGetValue(s_templateForContentTypeKey, out var result); - - if (result is not bool createTemplate) + if (State?.TryGetValue(s_templateForContentTypeKey, out var result) ?? false) { - return false; + if (result is not bool createTemplate) + { + return false; + } + + return createTemplate; } - return createTemplate; + return false; + } + set + { + if (!value is bool && State is not null) + { + State[s_templateForContentTypeKey] = value; + } } - set => State[s_templateForContentTypeKey] = value; } public string? ContentTypeAlias { get { - State.TryGetValue(s_contentTypeAliasKey, out var result); - return result as string; + if (State?.TryGetValue(s_contentTypeAliasKey, out var result) ?? false) + { + return result as string; + } + + return null; } set { - if (value is not null) + if (value is not null && State is not null) { State[s_contentTypeAliasKey] = value; } diff --git a/src/Umbraco.Core/Packaging/ConflictingPackageData.cs b/src/Umbraco.Core/Packaging/ConflictingPackageData.cs index 4824917d7c..3ad4287879 100644 --- a/src/Umbraco.Core/Packaging/ConflictingPackageData.cs +++ b/src/Umbraco.Core/Packaging/ConflictingPackageData.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Packaging _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); } - public IEnumerable? FindConflictingStylesheets(IEnumerable? stylesheetNodes) + public IEnumerable? FindConflictingStylesheets(IEnumerable? stylesheetNodes) { return stylesheetNodes? .Select(n => @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Packaging .Where(v => v != null); } - public IEnumerable? FindConflictingMacros(IEnumerable? macroNodes) + public IEnumerable? FindConflictingMacros(IEnumerable? macroNodes) { return macroNodes? .Select(n => diff --git a/src/Umbraco.Core/Packaging/InstallationSummary.cs b/src/Umbraco.Core/Packaging/InstallationSummary.cs index 618853731d..d5d7ad343b 100644 --- a/src/Umbraco.Core/Packaging/InstallationSummary.cs +++ b/src/Umbraco.Core/Packaging/InstallationSummary.cs @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Packaging { var sb = new StringBuilder(); - void WriteConflicts(IEnumerable? source, Func selector, string message, bool appendLine = true) + void WriteConflicts(IEnumerable? source, Func selector, string message, bool appendLine = true) { var result = source?.Select(selector).ToList(); if (result?.Count > 0) @@ -64,9 +64,9 @@ namespace Umbraco.Cms.Core.Packaging } } - WriteConflicts(Warnings?.ConflictingMacros, x => x.Alias, "Conflicting macros found, they will be overwritten: "); + WriteConflicts(Warnings?.ConflictingMacros, x => x?.Alias, "Conflicting macros found, they will be overwritten: "); WriteConflicts(Warnings?.ConflictingTemplates, x => x.Alias, "Conflicting templates found, they will be overwritten: "); - WriteConflicts(Warnings?.ConflictingStylesheets, x => x.Alias, "Conflicting stylesheets found, they will be overwritten: "); + WriteConflicts(Warnings?.ConflictingStylesheets, x => x?.Alias, "Conflicting stylesheets found, they will be overwritten: "); WriteCount("Data types installed: ", DataTypesInstalled); WriteCount("Languages installed: ", LanguagesInstalled); WriteCount("Dictionary items installed: ", DictionaryItemsInstalled); diff --git a/src/Umbraco.Core/Packaging/InstalledPackage.cs b/src/Umbraco.Core/Packaging/InstalledPackage.cs index 50c1444127..ded901512b 100644 --- a/src/Umbraco.Core/Packaging/InstalledPackage.cs +++ b/src/Umbraco.Core/Packaging/InstalledPackage.cs @@ -10,12 +10,12 @@ namespace Umbraco.Cms.Core.Packaging { [DataMember(Name = "name", IsRequired = true)] [Required] - public string PackageName { get; set; } + public string? PackageName { get; set; } // TODO: Version? Icon? Other metadata? This would need to come from querying the package on Our [DataMember(Name = "packageView")] - public string PackageView { get; set; } + public string? PackageView { get; set; } [DataMember(Name = "plans")] public IEnumerable PackageMigrationPlans { get; set; } = Enumerable.Empty(); diff --git a/src/Umbraco.Core/Packaging/InstalledPackageMigrationPlans.cs b/src/Umbraco.Core/Packaging/InstalledPackageMigrationPlans.cs index 6bb060b429..5aaca2e9f2 100644 --- a/src/Umbraco.Core/Packaging/InstalledPackageMigrationPlans.cs +++ b/src/Umbraco.Core/Packaging/InstalledPackageMigrationPlans.cs @@ -15,13 +15,13 @@ namespace Umbraco.Cms.Core.Packaging /// This can be used to determine if the package advertises any migrations /// [DataMember(Name = "finalMigrationId")] - public string FinalMigrationId { get; set; } + public string? FinalMigrationId { get; set; } /// /// If the package has migrations, this will be it's current migration Id /// [DataMember(Name = "currentMigrationId")] - public string CurrentMigrationId { get; set; } + public string? CurrentMigrationId { get; set; } } } diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index f022ecc396..4183575070 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -333,7 +333,7 @@ namespace Umbraco.Cms.Core.Packaging continue; } - IDictionaryItem di = _languageService.GetDictionaryItemById(outInt); + IDictionaryItem? di = _languageService.GetDictionaryItemById(outInt); if (di == null) { @@ -404,14 +404,17 @@ namespace Umbraco.Cms.Core.Packaging continue; } - XElement? macroXml = GetMacroXml(outInt, out IMacro macro); + XElement? macroXml = GetMacroXml(outInt, out IMacro? macro); if (macroXml == null) { continue; } macros.Add(macroXml); - packagedMacros.Add(macro); + if (macro is not null) + { + packagedMacros.Add(macro); + } } root.Add(macros); @@ -659,7 +662,7 @@ namespace Umbraco.Cms.Core.Packaging // TODO: Delete this /// - private XElement? GetMacroXml(int macroId, out IMacro macro) + private XElement? GetMacroXml(int macroId, out IMacro? macro) { macro = _macroService.GetById(macroId); if (macro == null) diff --git a/src/Umbraco.Core/Persistence/Repositories/IMemberGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IMemberGroupRepository.cs index 61c0b0c0a1..2c80106aab 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IMemberGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IMemberGroupRepository.cs @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories /// /// /// - IEnumerable GetMemberGroupsForMember(string username); + IEnumerable GetMemberGroupsForMember(string? username); void ReplaceRoles(int[] memberIds, string[] roleNames); @@ -46,6 +46,6 @@ namespace Umbraco.Cms.Core.Persistence.Repositories void DissociateRoles(int[] memberIds, string[] roleNames); - + } } diff --git a/src/Umbraco.Core/Persistence/Repositories/INotificationsRepository.cs b/src/Umbraco.Core/Persistence/Repositories/INotificationsRepository.cs index 069c31ef50..18585b06a0 100644 --- a/src/Umbraco.Core/Persistence/Repositories/INotificationsRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/INotificationsRepository.cs @@ -14,7 +14,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories int DeleteNotifications(IUser user, IEntity entity); IEnumerable GetEntityNotifications(IEntity entity); IEnumerable GetUserNotifications(IUser user); - IEnumerable GetUsersNotifications(IEnumerable userIds, string action, IEnumerable nodeIds, Guid objectType); + IEnumerable GetUsersNotifications(IEnumerable userIds, string? action, IEnumerable nodeIds, Guid objectType); IEnumerable SetNotifications(IUser user, IEntity entity, string[] actions); } } diff --git a/src/Umbraco.Core/Persistence/Repositories/InstallationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/InstallationRepository.cs index 58ebf8f5c4..cd3e31559b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/InstallationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/InstallationRepository.cs @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories public class InstallationRepository : IInstallationRepository { private readonly IJsonSerializer _jsonSerializer; - private static HttpClient _httpClient; + private static HttpClient? _httpClient; private const string RestApiInstallUrl = "https://our.umbraco.com/umbraco/api/Installation/Install"; public InstallationRepository(IJsonSerializer jsonSerializer) diff --git a/src/Umbraco.Core/Persistence/Repositories/UpgradeCheckRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UpgradeCheckRepository.cs index 2f55293a13..c36156e54b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UpgradeCheckRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UpgradeCheckRepository.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories public class UpgradeCheckRepository : IUpgradeCheckRepository { private readonly IJsonSerializer _jsonSerializer; - private static HttpClient _httpClient; + private static HttpClient? _httpClient; private const string RestApiUpgradeChecklUrl = "https://our.umbraco.com/umbraco/api/UpgradeCheck/CheckUpgrade"; public UpgradeCheckRepository(IJsonSerializer jsonSerializer) diff --git a/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs index f29511150c..a8620641c7 100644 --- a/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs @@ -9,20 +9,20 @@ namespace Umbraco.Cms.Core.PropertyEditors public class BlockListConfiguration { [ConfigurationField("blocks", "Available Blocks", "views/propertyeditors/blocklist/prevalue/blocklist.blockconfiguration.html", Description = "Define the available blocks.")] - public BlockConfiguration[] Blocks { get; set; } + public BlockConfiguration[]? Blocks { get; set; } [DataContract] public class BlockConfiguration { [DataMember(Name ="backgroundColor")] - public string BackgroundColor { get; set; } + public string? BackgroundColor { get; set; } [DataMember(Name ="iconColor")] - public string IconColor { get; set; } + public string? IconColor { get; set; } [DataMember(Name ="thumbnail")] - public string Thumbnail { get; set; } + public string? Thumbnail { get; set; } [DataMember(Name ="contentElementTypeKey")] public Guid ContentElementTypeKey { get; set; } @@ -31,16 +31,16 @@ namespace Umbraco.Cms.Core.PropertyEditors public Guid? SettingsElementTypeKey { get; set; } [DataMember(Name ="view")] - public string View { get; set; } + public string? View { get; set; } [DataMember(Name ="stylesheet")] - public string Stylesheet { get; set; } + public string? Stylesheet { get; set; } [DataMember(Name ="label")] - public string Label { get; set; } + public string? Label { get; set; } [DataMember(Name ="editorSize")] - public string EditorSize { get; set; } + public string? EditorSize { get; set; } [DataMember(Name ="forceHideContentEditorInOverlay")] public bool ForceHideContentEditorInOverlay { get; set; } @@ -66,6 +66,6 @@ namespace Umbraco.Cms.Core.PropertyEditors public bool UseInlineEditingAsDefault { get; set; } [ConfigurationField("maxPropertyWidth", "Property editor width", "textstring", Description = "optional css overwrite, example: 800px or 100%")] - public string MaxPropertyWidth { get; set; } + public string? MaxPropertyWidth { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs index 1f25b6abac..555d6f8418 100644 --- a/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs @@ -6,7 +6,7 @@ public bool ShowOpenButton { get; set; } [ConfigurationField("startNodeId", "Start node", "treepicker")] // + config in configuration editor ctor - public Udi StartNodeId { get; set; } + public Udi? StartNodeId { get; set; } [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, "Ignore User Start Nodes", "boolean", diff --git a/src/Umbraco.Core/PropertyEditors/DataEditor.cs b/src/Umbraco.Core/PropertyEditors/DataEditor.cs index d235ce7ca7..5619a1bb87 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditor.cs @@ -39,6 +39,7 @@ namespace Umbraco.Cms.Core.PropertyEditors if (Attribute == null) { Alias = string.Empty; + Name = string.Empty; return; } @@ -67,7 +68,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// [DataMember(Name = "name", IsRequired = true)] - public string? Name { get; internal set; } + public string Name { get; internal set; } /// [DataMember(Name = "icon")] diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index 18c8256400..14af54ee4a 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -95,7 +95,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public string ValueType { get; set; } /// - public IEnumerable Validate(object value, bool required, string format) + public IEnumerable Validate(object? value, bool required, string? format) { List? results = null; var r = Validators.SelectMany(v => v.Validate(value, ValueType, Configuration)).ToList(); @@ -156,7 +156,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// The result of the conversion attempt. /// /// ValueType was out of range. - internal Attempt TryConvertValueToCrlType(object value) + internal Attempt TryConvertValueToCrlType(object? value) { // Ensure empty string values are converted to null if (value is string s && string.IsNullOrWhiteSpace(s)) @@ -270,11 +270,11 @@ namespace Umbraco.Cms.Core.PropertyEditors // If it is a string type, we will attempt to see if it is JSON stored data, if it is we'll try to convert // to a real JSON object so we can pass the true JSON object directly to Angular! var stringValue = value as string ?? value.ToString(); - if (stringValue.DetectIsJson()) + if (stringValue!.DetectIsJson()) { try { - var json = _jsonSerializer.Deserialize(stringValue); + var json = _jsonSerializer.Deserialize(stringValue!); return json; } catch diff --git a/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs b/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs index d653a831cb..2b1997459c 100644 --- a/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs +++ b/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs @@ -9,6 +9,6 @@ namespace Umbraco.Cms.Core.PropertyEditors public int Id { get; set; } [DataMember(Name = "value")] - public string Value { get; set; } + public string? Value { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/IFileExtensionConfigItem.cs b/src/Umbraco.Core/PropertyEditors/IFileExtensionConfigItem.cs index 6394007fad..d32005fb7f 100644 --- a/src/Umbraco.Core/PropertyEditors/IFileExtensionConfigItem.cs +++ b/src/Umbraco.Core/PropertyEditors/IFileExtensionConfigItem.cs @@ -4,6 +4,6 @@ { int Id { get; set; } - string Value { get; set; } + string? Value { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/IValueRequiredValidator.cs b/src/Umbraco.Core/PropertyEditors/IValueRequiredValidator.cs index 2334a543ba..439bfcdc81 100644 --- a/src/Umbraco.Core/PropertyEditors/IValueRequiredValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/IValueRequiredValidator.cs @@ -17,6 +17,6 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// This is used to validate values when the property type specifies that a value is required. /// - IEnumerable ValidateRequired(object value, string valueType); + IEnumerable ValidateRequired(object? value, string valueType); } } diff --git a/src/Umbraco.Core/PropertyEditors/IValueValidator.cs b/src/Umbraco.Core/PropertyEditors/IValueValidator.cs index f4c45fdd3d..45f094de56 100644 --- a/src/Umbraco.Core/PropertyEditors/IValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/IValueValidator.cs @@ -18,6 +18,6 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// The value can be a string, a Json structure (JObject, JArray...)... corresponding to what was posted by an editor. /// - IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration); + IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration); } } diff --git a/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs index d9eb13a50d..62ddd4c053 100644 --- a/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs @@ -9,10 +9,10 @@ public bool DisplayLivePreview { get; set; } [ConfigurationField("defaultValue", "Default value", "textarea", Description = "If value is blank, the editor will show this")] - public string DefaultValue { get; set; } + public string? DefaultValue { get; set; } [ConfigurationField("overlaySize", "Overlay Size", "overlaysize", Description = "Select the width of the overlay (link picker).")] - public string OverlaySize { get; set; } + public string? OverlaySize { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs b/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs index 87e097883f..8b843fdf85 100644 --- a/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs +++ b/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.PropertyEditors { [ConfigurationField("filter", "Accepted types", "treesourcetypepicker", Description = "Limit to specific types")] - public string Filter { get; set; } + public string? Filter { get; set; } [ConfigurationField("multiple", "Pick multiple items", "boolean", Description = "Outputs a IEnumerable")] public bool Multiple { get; set; } @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.PropertyEditors } [ConfigurationField("startNodeId", "Start node", "mediapicker")] - public Udi StartNodeId { get; set; } + public Udi? StartNodeId { get; set; } [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, "Ignore User Start Nodes", "boolean", @@ -40,16 +40,16 @@ namespace Umbraco.Cms.Core.PropertyEditors public bool EnableLocalFocalPoint { get; set; } [ConfigurationField("crops", "Image Crops", "views/propertyeditors/mediapicker3/prevalue/mediapicker3.crops.html", Description = "Local crops, stored on document")] - public CropConfiguration[] Crops { get; set; } + public CropConfiguration[]? Crops { get; set; } [DataContract] public class CropConfiguration { [DataMember(Name = "alias")] - public string Alias { get; set; } + public string? Alias { get; set; } [DataMember(Name = "label")] - public string Label { get; set; } + public string? Label { get; set; } [DataMember(Name = "width")] public int Width { get; set; } diff --git a/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs index 06faedea0d..d18eeac644 100644 --- a/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs @@ -15,7 +15,7 @@ public bool DisableFolderSelect { get; set; } [ConfigurationField("startNodeId", "Start node", "mediapicker")] - public Udi StartNodeId { get; set; } + public Udi? StartNodeId { get; set; } [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, "Ignore User Start Nodes", "boolean", diff --git a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs index 54ae68550d..2825b5b8af 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs @@ -6,10 +6,10 @@ public class MultiNodePickerConfiguration : IIgnoreUserStartNodesConfig { [ConfigurationField("startNode", "Node type", "treesource")] - public MultiNodePickerConfigurationTreeSource TreeSource { get; set; } + public MultiNodePickerConfigurationTreeSource? TreeSource { get; set; } [ConfigurationField("filter", "Allow items of type", "treesourcetypepicker", Description = "Select the applicable types")] - public string Filter { get; set; } + public string? Filter { get; set; } [ConfigurationField("minNumber", "Minimum number of items", "number")] public int MinNumber { get; set; } diff --git a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationTreeSource.cs b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationTreeSource.cs index 1277ed9bc0..bc48bbdd54 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationTreeSource.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationTreeSource.cs @@ -9,12 +9,12 @@ namespace Umbraco.Cms.Core.PropertyEditors public class MultiNodePickerConfigurationTreeSource { [DataMember(Name = "type")] - public string ObjectType { get; set; } + public string? ObjectType { get; set; } [DataMember(Name = "query")] - public string StartNodeQuery { get; set; } + public string? StartNodeQuery { get; set; } [DataMember(Name = "id")] - public Udi StartNodeId { get; set; } + public Udi? StartNodeId { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs index e8e4dc57f6..caf933e6ad 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public int MaxNumber { get; set; } [ConfigurationField("overlaySize", "Overlay Size", "overlaysize", Description = "Select the width of the overlay.")] - public string OverlaySize { get; set; } + public string? OverlaySize { get; set; } [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, "Ignore user start nodes", "boolean", diff --git a/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs b/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs index 4fd1e1e104..aed6b5cd00 100644 --- a/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs @@ -9,7 +9,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public class NestedContentConfiguration { [ConfigurationField("contentTypes", "Element Types", "views/propertyeditors/nestedcontent/nestedcontent.doctypepicker.html", Description = "Select the Element Types to use as models for the items.")] - public ContentType[] ContentTypes { get; set; } + public ContentType[]? ContentTypes { get; set; } [ConfigurationField("minItems", "Min Items", "number", Description = "Minimum number of items allowed.")] public int? MinItems { get; set; } @@ -31,13 +31,13 @@ namespace Umbraco.Cms.Core.PropertyEditors public class ContentType { [DataMember(Name = "ncAlias")] - public string Alias { get; set; } + public string? Alias { get; set; } [DataMember(Name = "ncTabAlias")] - public string TabAlias { get; set; } + public string? TabAlias { get; set; } [DataMember(Name = "nameTemplate")] - public string Template { get; set; } + public string? Template { get; set; } } } } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs index 1ce7742eb6..6286287e1c 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public virtual IDataEditor? this[string? alias] => this.SingleOrDefault(x => x.Alias == alias); - public virtual bool TryGet(string alias, out IDataEditor? editor) + public virtual bool TryGet(string? alias, out IDataEditor? editor) { editor = this.FirstOrDefault(x => x.Alias == alias); return editor != null; diff --git a/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs b/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs index 29db502c9e..e0bbae88b5 100644 --- a/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs @@ -7,10 +7,10 @@ { // TODO: Make these strongly typed, for now this works though [ConfigurationField("editor", "Editor", "views/propertyeditors/rte/rte.prevalues.html", HideLabel = true)] - public object Editor { get; set; } + public object? Editor { get; set; } [ConfigurationField("overlaySize", "Overlay Size", "overlaysize", Description = "Select the width of the overlay (link picker).")] - public string OverlaySize { get; set; } + public string? OverlaySize { get; set; } [ConfigurationField("hideLabel", "Hide Label", "boolean")] public bool HideLabel { get; set; } @@ -22,6 +22,6 @@ [ConfigurationField("mediaParentId", "Image Upload Folder", "mediafolderpicker", Description = "Choose the upload location of pasted images")] - public GuidUdi MediaParentId { get; set; } + public GuidUdi? MediaParentId { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs b/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs index ab5b1ae964..945e10fd17 100644 --- a/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs @@ -12,9 +12,9 @@ public bool ShowLabels { get; set; } [ConfigurationField("labelOn", "Label On", "textstring", Description = "Label text when enabled.")] - public string LabelOn { get; set; } + public string? LabelOn { get; set; } [ConfigurationField("labelOff", "Label Off", "textstring", Description = "Label text when disabled.")] - public string LabelOff { get; set; } + public string? LabelOff { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs index e390c3f493..6404e54dfa 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators /// public class DateTimeValidator : IValueValidator { - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { //don't validate if empty if (value == null || value.ToString().IsNullOrWhiteSpace()) diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs index b68f4848aa..cfcec9a050 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Decimal"; /// - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { if (value == null || value.ToString() == string.Empty) yield break; diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs index a03251e978..4e6799c443 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators /// - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { // TODO: localize these! if (value != null) diff --git a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs index 90c37d54b4..cfba0fab72 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Email"; /// - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { var asString = value == null ? "" : value.ToString(); diff --git a/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs index 6c8e06ef3d..a79088b65b 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Integer"; /// - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { if (value != null && value.ToString() != string.Empty) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs index c655c02754..380efb9238 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs @@ -60,7 +60,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators } /// - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { if (_regex == null) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs index c1ebf62390..ae12a3641e 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs @@ -22,13 +22,13 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators public string ValidationName => "Required"; /// - public IEnumerable Validate(object value, string valueType, object? dataTypeConfiguration) + public IEnumerable Validate(object? value, string valueType, object? dataTypeConfiguration) { return ValidateRequired(value, valueType); } /// - public IEnumerable ValidateRequired(object value, string valueType) + public IEnumerable ValidateRequired(object? value, string valueType) { if (value == null) { diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs index 5d431296f9..241b968df9 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs @@ -59,12 +59,12 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot(); if (source is int id) { - IMember m = _memberService.GetById(id); + IMember? m = _memberService.GetById(id); if (m == null) { return null; } - member = publishedSnapshot?.Members.Get(m); + member = publishedSnapshot?.Members?.Get(m); if (member != null) { return member; @@ -76,13 +76,13 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters if (sourceUdi is null) return null; - IMember m = _memberService.GetByKey(sourceUdi.Guid); + IMember? m = _memberService.GetByKey(sourceUdi.Guid); if (m == null) { return null; } - member = publishedSnapshot?.Members.Get(m); + member = publishedSnapshot?.Members?.Get(m); if (member != null) { diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs index 4bfb4db713..8211be362f 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs @@ -104,12 +104,12 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters case Constants.UdiEntityType.Member: multiNodeTreePickerItem = GetPublishedContent(udi, ref objectType, UmbracoObjectTypes.Member, id => { - IMember m = _memberService.GetByKey(guidUdi.Guid); + IMember? m = _memberService.GetByKey(guidUdi.Guid); if (m == null) { return null; } - IPublishedContent? member = publishedSnapshot?.Members.Get(m); + IPublishedContent? member = publishedSnapshot?.Members?.Get(m); return member; }); break; diff --git a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs index d26b46a510..61b8a02f0e 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.PropertyEditors public int Id { get; set; } [DataMember(Name = "value")] - public string Value { get; set; } + public string? Value { get; set; } } } } diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs index 7d5c0fdedd..098d7e0cb4 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContent.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal WriterId = CreatorId = 0; CreateDate = UpdateDate = DateTime.Now; Version = Guid.Empty; - + Path = string.Empty; ContentType = contentType; } @@ -34,11 +34,11 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal public int SortOrder { get; set; } - public string Name { get; set; } + public string? Name { get; set; } public IReadOnlyDictionary Cultures => _cultures ??= GetCultures(); - public string UrlSegment { get; set; } + public string? UrlSegment { get; set; } public int WriterId { get; set; } @@ -62,19 +62,19 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal public int ParentId { get; set; } - public IEnumerable ChildIds { get; set; } + public IEnumerable? ChildIds { get; set; } - public IPublishedContent Parent { get; set; } + public IPublishedContent? Parent { get; set; } - public IEnumerable Children { get; set; } + public IEnumerable? Children { get; set; } - public IEnumerable ChildrenForAllCultures => Children; + public IEnumerable? ChildrenForAllCultures => Children; public IPublishedContentType ContentType { get; set; } - public IEnumerable Properties { get; set; } + public IEnumerable? Properties { get; set; } - public IPublishedProperty? GetProperty(string alias) => Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); + public IPublishedProperty? GetProperty(string alias) => Properties?.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); public IPublishedProperty? GetProperty(string alias, bool recurse) { @@ -84,7 +84,7 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal return property; } - IPublishedContent content = this; + IPublishedContent? content = this; while (content != null && (property == null || property.HasValue() == false)) { content = content.Parent; diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs index 07d25d7f9a..0e7280d443 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal [EditorBrowsable(EditorBrowsableState.Never)] public class InternalPublishedProperty : IPublishedProperty { - public IPublishedPropertyType? PropertyType { get; set; } + public IPublishedPropertyType PropertyType { get; set; } = null!; public string Alias { get; set; } = string.Empty; diff --git a/src/Umbraco.Core/ReflectionUtilities.cs b/src/Umbraco.Core/ReflectionUtilities.cs index 7a43ed04a6..982e0835fb 100644 --- a/src/Umbraco.Core/ReflectionUtilities.cs +++ b/src/Umbraco.Core/ReflectionUtilities.cs @@ -598,7 +598,7 @@ namespace Umbraco.Cms.Core if (!method.IsStatic) { parameters = new Type[lambdaParameters.Length + 1]; - parameters[0] = lambdaDeclaring ?? method.DeclaringType; + parameters[0] = lambdaDeclaring ?? method.DeclaringType!; Array.Copy(lambdaParameters, 0, parameters, 1, lambdaParameters.Length); } @@ -718,7 +718,7 @@ namespace Umbraco.Cms.Core var types = new Type[parameters.Length + (withDeclaring ? 1 : 0)]; var i = 0; if (withDeclaring) - types[i++] = method.DeclaringType; + types[i++] = method.DeclaringType!; foreach (var parameter in parameters) types[i++] = parameter.ParameterType; return types; diff --git a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs index c6de78fe42..1b75eb1aeb 100644 --- a/src/Umbraco.Core/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Core/Routing/DefaultUrlProvider.cs @@ -70,14 +70,14 @@ namespace Umbraco.Cms.Core.Routing public virtual IEnumerable GetOtherUrls(int id, Uri current) { IUmbracoContext umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); - IPublishedContent node = umbracoContext.Content.GetById(id); + IPublishedContent? node = umbracoContext.Content.GetById(id); if (node == null) { yield break; } // look for domains, walking up the tree - IPublishedContent n = node; + IPublishedContent? n = node; IEnumerable? domainUris = DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainMapper, n.Id, current, false); diff --git a/src/Umbraco.Core/Routing/DomainUtilities.cs b/src/Umbraco.Core/Routing/DomainUtilities.cs index 2b8e84d703..c754fd6bb4 100644 --- a/src/Umbraco.Core/Routing/DomainUtilities.cs +++ b/src/Umbraco.Core/Routing/DomainUtilities.cs @@ -77,22 +77,22 @@ namespace Umbraco.Cms.Core.Routing /// If culture is null, uses the default culture for the installation instead. Otherwise, /// will try with the specified culture, else return null. /// - internal static DomainAndUri? DomainForNode(IDomainCache domainCache, ISiteDomainMapper siteDomainMapper, int nodeId, Uri current, string? culture = null) + internal static DomainAndUri? DomainForNode(IDomainCache? domainCache, ISiteDomainMapper siteDomainMapper, int nodeId, Uri current, string? culture = null) { // be safe if (nodeId <= 0) return null; // get the domains on that node - var domains = domainCache.GetAssigned(nodeId).ToArray(); + var domains = domainCache?.GetAssigned(nodeId).ToArray(); // none? - if (domains.Length == 0) + if (domains is null || domains.Length == 0) return null; // else filter // it could be that none apply (due to culture) - return SelectDomain(domains, current, culture, domainCache.DefaultCulture, siteDomainMapper.MapDomain); + return SelectDomain(domains, current, culture, domainCache?.DefaultCulture, siteDomainMapper.MapDomain); } /// @@ -106,24 +106,24 @@ namespace Umbraco.Cms.Core.Routing /// The domains and their uris, that match the specified uri, else null. /// If at least a domain is set on the node then the method returns the domains that /// best match the specified uri, else it returns null. - internal static IEnumerable? DomainsForNode(IDomainCache domainCache, ISiteDomainMapper siteDomainMapper, int nodeId, Uri current, bool excludeDefault = true) + internal static IEnumerable? DomainsForNode(IDomainCache? domainCache, ISiteDomainMapper siteDomainMapper, int nodeId, Uri current, bool excludeDefault = true) { // be safe if (nodeId <= 0) return null; // get the domains on that node - var domains = domainCache.GetAssigned(nodeId).ToArray(); + var domains = domainCache?.GetAssigned(nodeId).ToArray(); // none? - if (domains.Length == 0) + if (domains is null || domains.Length == 0) return null; // get the domains and their uris var domainAndUris = SelectDomains(domains, current).ToArray(); // filter - return siteDomainMapper.MapDomains(domainAndUris, current, excludeDefault, null, domainCache.DefaultCulture).ToArray(); + return siteDomainMapper.MapDomains(domainAndUris, current, excludeDefault, null, domainCache?.DefaultCulture).ToArray(); } #endregion @@ -148,19 +148,19 @@ namespace Umbraco.Cms.Core.Routing /// the right one, unless it is null, in which case the method returns null. /// The filter, if any, will be called only with a non-empty argument, and _must_ return something. /// - public static DomainAndUri? SelectDomain(IEnumerable domains, Uri uri, string? culture = null, string? defaultCulture = null, Func, Uri, string?, string?, DomainAndUri?>? filter = null) + public static DomainAndUri? SelectDomain(IEnumerable? domains, Uri uri, string? culture = null, string? defaultCulture = null, Func, Uri, string?, string?, DomainAndUri?>? filter = null) { // sanitize the list to have proper uris for comparison (scheme, path end with /) // we need to end with / because example.com/foo cannot match example.com/foobar // we need to order so example.com/foo matches before example.com/ - var domainsAndUris = domains + var domainsAndUris = domains? .Where(d => d.IsWildcard == false) .Select(d => new DomainAndUri(d, uri)) .OrderByDescending(d => d.Uri.ToString()) .ToList(); // nothing = no magic, return null - if (domainsAndUris.Count == 0) + if (domainsAndUris is null || domainsAndUris.Count == 0) return null; // sanitize cultures @@ -345,7 +345,7 @@ namespace Umbraco.Cms.Core.Routing /// The current domain root node identifier, or null. /// The deepest wildcard Domain in the path, or null. /// Looks _under_ rootNodeId but not _at_ rootNodeId. - public static Domain? FindWildcardDomainInPath(IEnumerable domains, string path, int? rootNodeId) + public static Domain? FindWildcardDomainInPath(IEnumerable? domains, string path, int? rootNodeId) { var stopNodeId = rootNodeId ?? -1; @@ -353,7 +353,7 @@ namespace Umbraco.Cms.Core.Routing .Reverse() .Select(s => int.Parse(s, CultureInfo.InvariantCulture)) .TakeWhile(id => id != stopNodeId) - .Select(id => domains.FirstOrDefault(d => d.ContentId == id && d.IsWildcard)) + .Select(id => domains?.FirstOrDefault(d => d.ContentId == id && d.IsWildcard)) .FirstOrDefault(domain => domain != null); } diff --git a/src/Umbraco.Core/Routing/ISiteDomainMapper.cs b/src/Umbraco.Core/Routing/ISiteDomainMapper.cs index 56fdfaef6d..e9ca34477c 100644 --- a/src/Umbraco.Core/Routing/ISiteDomainMapper.cs +++ b/src/Umbraco.Core/Routing/ISiteDomainMapper.cs @@ -40,6 +40,6 @@ namespace Umbraco.Cms.Core.Routing /// The may be null, but when non-null, it can be used /// to help pick the best matches. /// - IEnumerable MapDomains(IReadOnlyCollection domainAndUris, Uri current, bool excludeDefault, string? culture, string defaultCulture); + IEnumerable MapDomains(IReadOnlyCollection domainAndUris, Uri current, bool excludeDefault, string? culture, string? defaultCulture); } } diff --git a/src/Umbraco.Core/Routing/PublishedRouter.cs b/src/Umbraco.Core/Routing/PublishedRouter.cs index b058798d94..c76fc5a066 100644 --- a/src/Umbraco.Core/Routing/PublishedRouter.cs +++ b/src/Umbraco.Core/Routing/PublishedRouter.cs @@ -272,8 +272,8 @@ namespace Umbraco.Cms.Core.Routing // note - we are not handling schemes nor ports here. _logger.LogDebug("{TracePrefix}Uri={RequestUri}", tracePrefix, request.Uri); var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); - IDomainCache domainsCache = umbracoContext.PublishedSnapshot.Domains; - var domains = domainsCache.GetAll(includeWildcards: false).ToList(); + IDomainCache? domainsCache = umbracoContext.PublishedSnapshot.Domains; + var domains = domainsCache?.GetAll(includeWildcards: false).ToList(); // determines whether a domain corresponds to a published document, since some // domains may exist but on a document that has been unpublished - as a whole - or @@ -282,7 +282,7 @@ namespace Umbraco.Cms.Core.Routing bool IsPublishedContentDomain(Domain domain) { // just get it from content cache - optimize there, not here - IPublishedContent domainDocument = umbracoContext.PublishedSnapshot.Content.GetById(domain.ContentId); + IPublishedContent? domainDocument = umbracoContext.PublishedSnapshot.Content.GetById(domain.ContentId); // not published - at all if (domainDocument == null) @@ -300,9 +300,9 @@ namespace Umbraco.Cms.Core.Routing return domainDocument.Cultures.ContainsKey(domain.Culture); } - domains = domains.Where(IsPublishedContentDomain).ToList(); + domains = domains?.Where(IsPublishedContentDomain).ToList(); - var defaultCulture = domainsCache.DefaultCulture; + var defaultCulture = domainsCache?.DefaultCulture; // try to find a domain matching the current request DomainAndUri? domainAndUri = DomainUtilities.SelectDomain(domains, request.Uri, defaultCulture: defaultCulture); @@ -351,7 +351,7 @@ namespace Umbraco.Cms.Core.Routing _logger.LogDebug("{TracePrefix}Path={NodePath}", tracePrefix, nodePath); var rootNodeId = request.Domain != null ? request.Domain.ContentId : (int?)null; var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); - Domain? domain = DomainUtilities.FindWildcardDomainInPath(umbracoContext.PublishedSnapshot.Domains.GetAll(true), nodePath, rootNodeId); + Domain? domain = DomainUtilities.FindWildcardDomainInPath(umbracoContext.PublishedSnapshot.Domains?.GetAll(true), nodePath, rootNodeId); // always has a contentId and a culture if (domain != null) @@ -693,7 +693,7 @@ namespace Umbraco.Cms.Core.Routing throw new InvalidOperationException("The template is not set, the page cannot render."); } - ITemplate template = _fileService.GetTemplate(templateId.Value); + ITemplate? template = _fileService.GetTemplate(templateId.Value); if (template == null) { throw new InvalidOperationException("The template with Id " + templateId + " does not exist, the page cannot render."); diff --git a/src/Umbraco.Core/Routing/SiteDomainMapper.cs b/src/Umbraco.Core/Routing/SiteDomainMapper.cs index 57c0dff3cf..a74d4532e1 100644 --- a/src/Umbraco.Core/Routing/SiteDomainMapper.cs +++ b/src/Umbraco.Core/Routing/SiteDomainMapper.cs @@ -246,7 +246,7 @@ namespace Umbraco.Cms.Core.Routing /// public virtual IEnumerable MapDomains(IReadOnlyCollection domainAndUris, - Uri current, bool excludeDefault, string? culture, string defaultCulture) + Uri current, bool excludeDefault, string? culture, string? defaultCulture) { // TODO: ignoring cultures entirely? diff --git a/src/Umbraco.Core/Routing/UriUtility.cs b/src/Umbraco.Core/Routing/UriUtility.cs index 07adfc1587..b973bdd068 100644 --- a/src/Umbraco.Core/Routing/UriUtility.cs +++ b/src/Umbraco.Core/Routing/UriUtility.cs @@ -8,8 +8,8 @@ namespace Umbraco.Cms.Core.Routing { public sealed class UriUtility { - static string _appPath; - static string _appPathPrefix; + static string? _appPath; + static string? _appPathPrefix; public UriUtility(IHostingEnvironment hostingEnvironment) { @@ -32,10 +32,10 @@ namespace Umbraco.Cms.Core.Routing } // will be "/" or "/foo" - public string AppPath => _appPath; + public string? AppPath => _appPath; // will be "" or "/foo" - public string AppPathPrefix => _appPathPrefix; + public string? AppPathPrefix => _appPathPrefix; // adds the virtual directory if any // see also VirtualPathUtility.ToAbsolute @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Routing // see also VirtualPathUtility.ToAppRelative public string ToAppRelative(string virtualPath) { - if (virtualPath.InvariantStartsWith(_appPathPrefix) + if (_appPathPrefix is not null && virtualPath.InvariantStartsWith(_appPathPrefix) && (virtualPath.Length == _appPathPrefix.Length || virtualPath[_appPathPrefix.Length] == '/')) { virtualPath = virtualPath.Substring(_appPathPrefix.Length); diff --git a/src/Umbraco.Core/Routing/UrlProvider.cs b/src/Umbraco.Core/Routing/UrlProvider.cs index adb92d5fe7..c53d75fc31 100644 --- a/src/Umbraco.Core/Routing/UrlProvider.cs +++ b/src/Umbraco.Core/Routing/UrlProvider.cs @@ -49,7 +49,7 @@ namespace Umbraco.Cms.Core.Routing #region GetUrl - private IPublishedContent GetDocument(int id) + private IPublishedContent? GetDocument(int id) { var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext(); return umbracoContext.Content.GetById(id); @@ -101,7 +101,7 @@ namespace Umbraco.Cms.Core.Routing /// when no culture is specified, the current culture. /// If the provider is unable to provide a URL, it returns "#". /// - public string GetUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string? culture = null, Uri? current = null) + public string GetUrl(IPublishedContent? content, UrlMode mode = UrlMode.Default, string? culture = null, Uri? current = null) { if (content == null || content.ContentType.ItemType == PublishedItemType.Element) return "#"; diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 65ac5689c7..b8b4b9ed25 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -1367,7 +1367,7 @@ namespace Umbraco.Cms.Core.Services /// private PublishResult CommitDocumentChangesInternal(IScope scope, IContent content, EventMessages eventMessages, IReadOnlyCollection allLangs, - IDictionary notificationState, + IDictionary? notificationState, int userId = Constants.Security.SuperUserId, bool branchOne = false, bool branchRoot = false) { @@ -3015,7 +3015,7 @@ namespace Umbraco.Cms.Core.Services private PublishResult StrategyCanPublish(IScope scope, IContent content, bool checkPath, IReadOnlyList? culturesPublishing, IReadOnlyCollection? culturesUnpublishing, EventMessages evtMsgs, - IReadOnlyCollection allLangs, IDictionary notificationState) + IReadOnlyCollection allLangs, IDictionary? notificationState) { // raise Publishing notification if (scope.Notifications.PublishCancelable( diff --git a/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index d402eb5e6b..877f462124 100644 --- a/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -20,12 +20,12 @@ namespace Umbraco.Cms.Core.Services where TItem : class, IContentTypeComposition { private readonly IAuditRepository _auditRepository; - private readonly IEntityContainerRepository _containerRepository; + private readonly IEntityContainerRepository? _containerRepository; private readonly IEntityRepository _entityRepository; private readonly IEventAggregator _eventAggregator; protected ContentTypeServiceBase(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, - TRepository repository, IAuditRepository auditRepository, IEntityContainerRepository containerRepository, IEntityRepository entityRepository, + TRepository repository, IAuditRepository auditRepository, IEntityContainerRepository? containerRepository, IEntityRepository entityRepository, IEventAggregator eventAggregator) : base(provider, loggerFactory, eventMessagesFactory) { @@ -608,7 +608,7 @@ namespace Umbraco.Cms.Core.Services scope.Notifications.Publish(GetContentTypeChangedNotification(changes, eventMessages)); - DeletedNotification deletedNotification = GetDeletedNotification(deleted.LegacyDistinctBy(x => x.Id), eventMessages); + DeletedNotification deletedNotification = GetDeletedNotification(deleted.LegacyDistinctBy(x => x!.Id), eventMessages); deletedNotification.WithStateFrom(deletingNotification); scope.Notifications.Publish(deletedNotification); @@ -635,7 +635,7 @@ namespace Umbraco.Cms.Core.Services // all descendants are going to be deleted TItem[] allDescendantsAndSelf = itemsA.SelectMany(xx => GetDescendants(xx.Id, true)) - .LegacyDistinctBy(x => x.Id) + .LegacyDistinctBy(x => x!.Id) .ToArray(); TItem[] deleted = allDescendantsAndSelf; @@ -666,7 +666,7 @@ namespace Umbraco.Cms.Core.Services scope.Notifications.Publish(GetContentTypeChangedNotification(changes, eventMessages)); - DeletedNotification deletedNotification = GetDeletedNotification(deleted.LegacyDistinctBy(x => x.Id), eventMessages); + DeletedNotification deletedNotification = GetDeletedNotification(deleted.LegacyDistinctBy(x => x!.Id), eventMessages); deletedNotification.WithStateFrom(deletingNotification); scope.Notifications.Publish(deletedNotification); @@ -747,7 +747,7 @@ namespace Umbraco.Cms.Core.Services { if (containerId > 0) { - var container = _containerRepository.Get(containerId); + var container = _containerRepository?.Get(containerId); if (container == null) throw new DataOperationException(MoveOperationStatusType.FailedParentNotFound); // causes rollback } @@ -809,7 +809,7 @@ namespace Umbraco.Cms.Core.Services EntityContainer? container = null; if (containerId > 0) { - container = _containerRepository.Get(containerId); + container = _containerRepository?.Get(containerId); if (container == null) throw new DataOperationException(MoveOperationStatusType.FailedParentNotFound); // causes rollback } @@ -865,7 +865,7 @@ namespace Umbraco.Cms.Core.Services return OperationResult.Attempt.Cancel(eventMessages, container); } - _containerRepository.Save(container); + _containerRepository?.Save(container); scope.Complete(); var savedNotification = new EntityContainerSavedNotification(container, eventMessages); @@ -911,7 +911,7 @@ namespace Umbraco.Cms.Core.Services scope.WriteLock(WriteLockIds); // also for containers - _containerRepository.Save(container); + _containerRepository?.Save(container); scope.Complete(); var savedNotification = new EntityContainerSavedNotification(container, eventMessages); @@ -930,31 +930,31 @@ namespace Umbraco.Cms.Core.Services { scope.ReadLock(ReadLockIds); // also for containers - return _containerRepository.Get(containerId); + return _containerRepository?.Get(containerId); } } - public EntityContainer GetContainer(Guid containerId) + public EntityContainer? GetContainer(Guid containerId) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers - return _containerRepository.Get(containerId); + return _containerRepository?.Get(containerId); } } - public IEnumerable GetContainers(int[] containerIds) + public IEnumerable? GetContainers(int[] containerIds) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers - return _containerRepository.GetMany(containerIds); + return _containerRepository?.GetMany(containerIds); } } - public IEnumerable GetContainers(TItem item) + public IEnumerable? GetContainers(TItem item) { var ancestorIds = item.Path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asInt) ? asInt : int.MinValue) @@ -964,13 +964,13 @@ namespace Umbraco.Cms.Core.Services return GetContainers(ancestorIds); } - public IEnumerable GetContainers(string name, int level) + public IEnumerable? GetContainers(string name, int level) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers - return _containerRepository.Get(name, level); + return _containerRepository?.Get(name, level); } } @@ -981,7 +981,7 @@ namespace Umbraco.Cms.Core.Services { scope.WriteLock(WriteLockIds); // also for containers - EntityContainer? container = _containerRepository.Get(containerId); + EntityContainer? container = _containerRepository?.Get(containerId); if (container == null) { return OperationResult.Attempt.NoOperation(eventMessages); @@ -1003,7 +1003,7 @@ namespace Umbraco.Cms.Core.Services return Attempt.Fail(new OperationResult(OperationResultType.FailedCancelledByEvent, eventMessages)); } - _containerRepository.Delete(container); + _containerRepository?.Delete(container); scope.Complete(); var deletedNotification = new EntityContainerDeletedNotification(container, eventMessages); @@ -1024,7 +1024,7 @@ namespace Umbraco.Cms.Core.Services try { - EntityContainer? container = _containerRepository.Get(id); + EntityContainer? container = _containerRepository?.Get(id); //throw if null, this will be caught by the catch and a failed returned if (container == null) @@ -1041,7 +1041,7 @@ namespace Umbraco.Cms.Core.Services return OperationResult.Attempt.Cancel(eventMessages); } - _containerRepository.Save(container); + _containerRepository?.Save(container); scope.Complete(); var renamedNotification = new EntityContainerRenamedNotification(container, eventMessages); diff --git a/src/Umbraco.Core/Services/DashboardService.cs b/src/Umbraco.Core/Services/DashboardService.cs index a495c87454..c3e01a974f 100644 --- a/src/Umbraco.Core/Services/DashboardService.cs +++ b/src/Umbraco.Core/Services/DashboardService.cs @@ -82,7 +82,7 @@ namespace Umbraco.Cms.Core.Services if (grantBySectionRules.Length > 0) { var allowedSections = sectionService.GetAllowedSections(user.Id).Select(x => x.Alias).ToArray(); - var wantedSections = grantBySectionRules.SelectMany(g => g.Value.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)).ToArray(); + var wantedSections = grantBySectionRules.SelectMany(g => g.Value?.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty()).ToArray(); if (wantedSections.Intersect(allowedSections).Any()) hasAccess = true; @@ -93,7 +93,7 @@ namespace Umbraco.Cms.Core.Services if (hasAccess == false && grantRules.Any()) { assignedUserGroups = user.Groups.Select(x => x.Alias).ToArray(); - var wantedUserGroups = grantRules.SelectMany(g => g.Value.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)).ToArray(); + var wantedUserGroups = grantRules.SelectMany(g => g.Value?.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty()).ToArray(); if (wantedUserGroups.Intersect(assignedUserGroups).Any()) hasAccess = true; @@ -107,7 +107,7 @@ namespace Umbraco.Cms.Core.Services // check if this item has any deny arguments, if so check if the user is in one of the denied user groups, if so they will // be denied to see it no matter what assignedUserGroups = assignedUserGroups ?? user.Groups.Select(x => x.Alias).ToArray(); - var deniedUserGroups = denyRules.SelectMany(g => g.Value.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)).ToArray(); + var deniedUserGroups = denyRules.SelectMany(g => g.Value?.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty()).ToArray(); if (deniedUserGroups.Intersect(assignedUserGroups).Any()) hasAccess = false; diff --git a/src/Umbraco.Core/Services/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/EntityXmlSerializer.cs index e0f458db7b..6a070e38fb 100644 --- a/src/Umbraco.Core/Services/EntityXmlSerializer.cs +++ b/src/Umbraco.Core/Services/EntityXmlSerializer.cs @@ -159,9 +159,9 @@ namespace Umbraco.Cms.Core.Services // what about writer/creator/version? - xml.Add(new XAttribute("loginName", member.Username)); - xml.Add(new XAttribute("email", member.Email)); - xml.Add(new XAttribute("icon", member.ContentType.Icon)); + xml.Add(new XAttribute("loginName", member.Username!)); + xml.Add(new XAttribute("email", member.Email!)); + xml.Add(new XAttribute("icon", member.ContentType.Icon!)); return xml; } @@ -184,7 +184,7 @@ namespace Umbraco.Cms.Core.Services public XElement Serialize(IDataType dataType) { var xml = new XElement("DataType"); - xml.Add(new XAttribute("Name", dataType.Name)); + xml.Add(new XAttribute("Name", dataType.Name!)); //The 'ID' when exporting is actually the property editor alias (in pre v7 it was the IDataType GUID id) xml.Add(new XAttribute("Id", dataType.EditorAlias)); xml.Add(new XAttribute("Definition", dataType.Key)); @@ -257,12 +257,12 @@ namespace Umbraco.Cms.Core.Services new XAttribute("Key", dictionaryItem.Key), new XAttribute("Name", dictionaryItem.ItemKey)); - foreach (IDictionaryTranslation translation in dictionaryItem.Translations) + foreach (IDictionaryTranslation translation in dictionaryItem.Translations!) { xml.Add(new XElement("Value", - new XAttribute("LanguageId", translation.Language.Id), + new XAttribute("LanguageId", translation.Language!.Id), new XAttribute("LanguageCultureAlias", translation.Language.IsoCode), - new XCData(translation.Value))); + new XCData(translation.Value!))); } return xml; @@ -273,7 +273,7 @@ namespace Umbraco.Cms.Core.Services var xml = new XElement("Stylesheet", new XElement("Name", stylesheet.Alias), new XElement("FileName", stylesheet.Path), - new XElement("Content", new XCData(stylesheet.Content))); + new XElement("Content", new XCData(stylesheet.Content!))); if (!includeProperties) { @@ -283,12 +283,15 @@ namespace Umbraco.Cms.Core.Services var props = new XElement("Properties"); xml.Add(props); - foreach (var prop in stylesheet.Properties) + if (stylesheet.Properties is not null) { - props.Add(new XElement("Property", - new XElement("Name", prop.Name), - new XElement("Alias", prop.Alias), - new XElement("Value", prop.Value))); + foreach (var prop in stylesheet.Properties) + { + props.Add(new XElement("Property", + new XElement("Name", prop.Name), + new XElement("Alias", prop.Alias), + new XElement("Value", prop.Value))); + } } return xml; @@ -325,7 +328,7 @@ namespace Umbraco.Cms.Core.Services xml.Add(new XElement("Name", template.Name)); xml.Add(new XElement("Key", template.Key)); xml.Add(new XElement("Alias", template.Alias)); - xml.Add(new XElement("Design", new XCData(template.Content))); + xml.Add(new XElement("Design", new XCData(template.Content!))); if (template is Template concreteTemplate && concreteTemplate.MasterTemplateId != null) { @@ -374,9 +377,12 @@ namespace Umbraco.Cms.Core.Services } var structure = new XElement("Structure"); - foreach (var allowedType in mediaType.AllowedContentTypes) + if (mediaType.AllowedContentTypes is not null) { - structure.Add(new XElement("MediaType", allowedType.Alias)); + foreach (var allowedType in mediaType.AllowedContentTypes) + { + structure.Add(new XElement("MediaType", allowedType.Alias)); + } } var genericProperties = new XElement("GenericProperties", SerializePropertyTypes(mediaType.PropertyTypes, mediaType.PropertyGroups)); // actually, all of them @@ -425,7 +431,7 @@ namespace Umbraco.Cms.Core.Services { properties.Add(new XElement("property", new XAttribute("key", property.Key), - new XAttribute("name", property.Name), + new XAttribute("name", property.Name!), new XAttribute("alias", property.Alias), new XAttribute("sortOrder", property.SortOrder), new XAttribute("propertyType", property.EditorAlias))); @@ -464,10 +470,14 @@ namespace Umbraco.Cms.Core.Services info.Add(compositionsElement); var allowedTemplates = new XElement("AllowedTemplates"); - foreach (var template in contentType.AllowedTemplates) + if (contentType.AllowedTemplates is not null) { - allowedTemplates.Add(new XElement("Template", template.Alias)); + foreach (var template in contentType.AllowedTemplates) + { + allowedTemplates.Add(new XElement("Template", template.Alias)); + } } + info.Add(allowedTemplates); if (contentType.DefaultTemplate != null && contentType.DefaultTemplate.Id != 0) @@ -480,9 +490,12 @@ namespace Umbraco.Cms.Core.Services } var structure = new XElement("Structure"); - foreach (var allowedType in contentType.AllowedContentTypes) + if (contentType.AllowedContentTypes is not null) { - structure.Add(new XElement("DocumentType", allowedType.Alias)); + foreach (var allowedType in contentType.AllowedContentTypes) + { + structure.Add(new XElement("DocumentType", allowedType.Alias)); + } } var genericProperties = new XElement("GenericProperties", SerializePropertyTypes(contentType.PropertyTypes, contentType.PropertyGroups)); // actually, all of them @@ -506,11 +519,14 @@ namespace Umbraco.Cms.Core.Services if (contentType.Level != 1 && masterContentType == null) { //get URL encoded folder names - var folders = _contentTypeService.GetContainers(contentType) + var folders = _contentTypeService.GetContainers(contentType)? .OrderBy(x => x.Level); - folderNames = string.Join("/", folders.Select(x => WebUtility.UrlEncode(x.Name)).ToArray()); - folderKeys = string.Join("/", folders.Select(x => x.Key).ToArray()); + if (folders is not null) + { + folderNames = string.Join("/", folders.Select(x => WebUtility.UrlEncode(x.Name)).ToArray()); + folderKeys = string.Join("/", folders.Select(x => x.Key).ToArray()); + } } if (string.IsNullOrWhiteSpace(folderNames) == false) @@ -554,7 +570,7 @@ namespace Umbraco.Cms.Core.Services } } - private XElement SerializePropertyType(IPropertyType propertyType, IDataType definition, PropertyGroup propertyGroup) + private XElement SerializePropertyType(IPropertyType propertyType, IDataType definition, PropertyGroup? propertyGroup) => new XElement("GenericProperty", new XElement("Name", propertyType.Name), new XElement("Alias", propertyType.Alias), @@ -605,8 +621,8 @@ namespace Umbraco.Cms.Core.Services new XAttribute("sortOrder", contentBase.SortOrder), new XAttribute("createDate", contentBase.CreateDate.ToString("s")), new XAttribute("updateDate", contentBase.UpdateDate.ToString("s")), - new XAttribute("nodeName", contentBase.Name), - new XAttribute("urlName", urlValue), + new XAttribute("nodeName", contentBase.Name!), + new XAttribute("urlName", urlValue!), new XAttribute("path", contentBase.Path), new XAttribute("isDoc", "")); @@ -614,7 +630,7 @@ namespace Umbraco.Cms.Core.Services // Add culture specific node names foreach (var culture in contentBase.AvailableCultures) { - xml.Add(new XAttribute("nodeName-" + culture, contentBase.GetCultureName(culture))); + xml.Add(new XAttribute("nodeName-" + culture, contentBase.GetCultureName(culture)!)); } foreach (var property in contentBase.Properties) diff --git a/src/Umbraco.Core/Services/IContentTypeServiceBase.cs b/src/Umbraco.Core/Services/IContentTypeServiceBase.cs index d6f24ba4e0..ee176d45d0 100644 --- a/src/Umbraco.Core/Services/IContentTypeServiceBase.cs +++ b/src/Umbraco.Core/Services/IContentTypeServiceBase.cs @@ -81,10 +81,10 @@ namespace Umbraco.Cms.Core.Services Attempt?> CreateContainer(int parentContainerId, Guid key, string name, int userId = Constants.Security.SuperUserId); Attempt SaveContainer(EntityContainer container, int userId = Constants.Security.SuperUserId); EntityContainer? GetContainer(int containerId); - EntityContainer GetContainer(Guid containerId); - IEnumerable GetContainers(int[] containerIds); - IEnumerable GetContainers(TItem contentType); - IEnumerable GetContainers(string folderName, int level); + EntityContainer? GetContainer(Guid containerId); + IEnumerable? GetContainers(int[] containerIds); + IEnumerable? GetContainers(TItem contentType); + IEnumerable? GetContainers(string folderName, int level); Attempt DeleteContainer(int containerId, int userId = Constants.Security.SuperUserId); Attempt?> RenameContainer(int id, string name, int userId = Constants.Security.SuperUserId); diff --git a/src/Umbraco.Core/Services/IKeyValueService.cs b/src/Umbraco.Core/Services/IKeyValueService.cs index 82fddedad3..179bbe5580 100644 --- a/src/Umbraco.Core/Services/IKeyValueService.cs +++ b/src/Umbraco.Core/Services/IKeyValueService.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Services /// Gets a value. /// /// Returns null if no value was found for the key. - string GetValue(string key); + string? GetValue(string key); /// /// Returns key/value pairs for all keys with the specified prefix. diff --git a/src/Umbraco.Core/Services/ILocalizationService.cs b/src/Umbraco.Core/Services/ILocalizationService.cs index e880602c3b..33caa957eb 100644 --- a/src/Umbraco.Core/Services/ILocalizationService.cs +++ b/src/Umbraco.Core/Services/ILocalizationService.cs @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the /// - IDictionaryItem GetDictionaryItemById(int id); + IDictionaryItem? GetDictionaryItemById(int id); /// /// Gets a by its id @@ -101,7 +101,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the /// - ILanguage GetLanguageById(int id); + ILanguage? GetLanguageById(int id); /// /// Gets a by its iso code diff --git a/src/Umbraco.Core/Services/IMacroService.cs b/src/Umbraco.Core/Services/IMacroService.cs index c4bc34997f..f1984db5f3 100644 --- a/src/Umbraco.Core/Services/IMacroService.cs +++ b/src/Umbraco.Core/Services/IMacroService.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Services /// /// Alias to retrieve an for /// An object - IMacro GetByAlias(string alias); + IMacro? GetByAlias(string alias); ///// ///// Gets a list all available objects @@ -30,9 +30,9 @@ namespace Umbraco.Cms.Core.Services IEnumerable GetAll(params Guid[] ids); - IMacro GetById(int id); + IMacro? GetById(int id); - IMacro GetById(Guid id); + IMacro? GetById(Guid id); /// /// Deletes an diff --git a/src/Umbraco.Core/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs index 8f40866eb3..8609b74a1d 100644 --- a/src/Umbraco.Core/Services/IMediaService.cs +++ b/src/Umbraco.Core/Services/IMediaService.cs @@ -65,14 +65,14 @@ namespace Umbraco.Cms.Core.Services /// Alias of the /// Optional id of the user creating the media item /// - IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = Constants.Security.SuperUserId); + IMedia CreateMedia(string name, IMedia? parent, string mediaTypeAlias, int userId = Constants.Security.SuperUserId); /// /// Gets an object by Id /// /// Id of the Content to retrieve /// - IMedia GetById(int id); + IMedia? GetById(int id); /// /// Gets a collection of objects by Parent Id @@ -146,14 +146,14 @@ namespace Umbraco.Cms.Core.Services /// Id of the Media's new Parent /// Id of the User moving the Media /// True if moving succeeded, otherwise False - Attempt Move(IMedia media, int parentId, int userId = Constants.Security.SuperUserId); + Attempt Move(IMedia media, int parentId, int userId = Constants.Security.SuperUserId); /// /// Deletes an object by moving it to the Recycle Bin /// /// The to delete /// Id of the User deleting the Media - Attempt MoveToRecycleBin(IMedia media, int userId = Constants.Security.SuperUserId); + Attempt MoveToRecycleBin(IMedia media, int userId = Constants.Security.SuperUserId); /// /// Empties the Recycle Bin by deleting all that resides in the bin @@ -191,28 +191,28 @@ namespace Umbraco.Cms.Core.Services /// /// The to delete /// Id of the User deleting the Media - Attempt Delete(IMedia media, int userId = Constants.Security.SuperUserId); + Attempt Delete(IMedia media, int userId = Constants.Security.SuperUserId); /// /// Saves a single object /// /// The to save /// Id of the User saving the Media - Attempt Save(IMedia media, int userId = Constants.Security.SuperUserId); + Attempt Save(IMedia media, int userId = Constants.Security.SuperUserId); /// /// Saves a collection of objects /// /// Collection of to save /// Id of the User saving the Media - Attempt Save(IEnumerable medias, int userId = Constants.Security.SuperUserId); + Attempt Save(IEnumerable medias, int userId = Constants.Security.SuperUserId); /// /// Gets an object by its 'UniqueId' /// /// Guid key of the Media to retrieve /// - IMedia GetById(Guid key); + IMedia? GetById(Guid key); /// /// Gets a collection of objects by Level @@ -285,14 +285,14 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the to retrieve the parent from /// Parent object - IMedia GetParent(int id); + IMedia? GetParent(int id); /// /// Gets the parent of the current media as an item. /// /// to retrieve the parent from /// Parent object - IMedia GetParent(IMedia media); + IMedia? GetParent(IMedia media); /// /// Sorts a collection of objects by updating the SortOrder according @@ -338,7 +338,7 @@ namespace Umbraco.Cms.Core.Services /// /// The filesystem path to the media. /// The content of the media. - Stream GetMediaFileContentStream(string filepath); + Stream? GetMediaFileContentStream(string filepath); /// /// Sets the content of a media. diff --git a/src/Umbraco.Core/Services/IMemberGroupService.cs b/src/Umbraco.Core/Services/IMemberGroupService.cs index 0b72906c2f..7ca20ebd89 100644 --- a/src/Umbraco.Core/Services/IMemberGroupService.cs +++ b/src/Umbraco.Core/Services/IMemberGroupService.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Services public interface IMemberGroupService : IService { IEnumerable GetAll(); - IMemberGroup GetById(int id); + IMemberGroup? GetById(int id); IMemberGroup GetById(Guid id); IEnumerable GetByIds(IEnumerable ids); IMemberGroup GetByName(string name); diff --git a/src/Umbraco.Core/Services/IMemberService.cs b/src/Umbraco.Core/Services/IMemberService.cs index 6619462779..25bbf7b516 100644 --- a/src/Umbraco.Core/Services/IMemberService.cs +++ b/src/Umbraco.Core/Services/IMemberService.cs @@ -113,14 +113,14 @@ namespace Umbraco.Cms.Core.Services /// and the user id in the membership provider. /// Id /// - IMember GetByKey(Guid id); + IMember? GetByKey(Guid id); /// /// Gets a Member by its integer id /// /// Id /// - IMember GetById(int id); + IMember? GetById(int id); /// /// Gets all Members for the specified MemberType alias diff --git a/src/Umbraco.Core/Services/IMembershipRoleService.cs b/src/Umbraco.Core/Services/IMembershipRoleService.cs index 682b02727b..70e1d53491 100644 --- a/src/Umbraco.Core/Services/IMembershipRoleService.cs +++ b/src/Umbraco.Core/Services/IMembershipRoleService.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Services IEnumerable GetAllRoles(); - IEnumerable GetAllRoles(int memberId); + IEnumerable? GetAllRoles(int memberId); IEnumerable GetAllRoles(string? username); diff --git a/src/Umbraco.Core/Services/IPublicAccessService.cs b/src/Umbraco.Core/Services/IPublicAccessService.cs index 327dcfab89..96d8ca5d1b 100644 --- a/src/Umbraco.Core/Services/IPublicAccessService.cs +++ b/src/Umbraco.Core/Services/IPublicAccessService.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// Returns null if no entry is found - PublicAccessEntry GetEntryForContent(IContent content); + PublicAccessEntry? GetEntryForContent(IContent content); /// /// Gets the entry defined for the content item based on a content path diff --git a/src/Umbraco.Core/Services/KeyValueService.cs b/src/Umbraco.Core/Services/KeyValueService.cs index e54a803659..f7fe99909c 100644 --- a/src/Umbraco.Core/Services/KeyValueService.cs +++ b/src/Umbraco.Core/Services/KeyValueService.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Services } /// - public string GetValue(string key) + public string? GetValue(string key) { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) { diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index 347872fe0b..c249dd0e0b 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -49,17 +49,27 @@ namespace Umbraco.Cms.Core.Services if (item == null) throw new ArgumentNullException(nameof(item)); if (language == null) throw new ArgumentNullException(nameof(language)); - var existing = item.Translations.FirstOrDefault(x => x.Language.Id == language.Id); + var existing = item.Translations?.FirstOrDefault(x => x.Language?.Id == language.Id); if (existing != null) { existing.Value = value; } else { - item.Translations = new List(item.Translations) + if (item.Translations is not null) { - new DictionaryTranslation(language, value) - }; + item.Translations = new List(item.Translations) + { + new DictionaryTranslation(language, value) + }; + } + else + { + item.Translations = new List + { + new DictionaryTranslation(language, value) + }; + } } } @@ -70,7 +80,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// - public IDictionaryItem CreateDictionaryItemWithIdentity(string key, Guid? parentId, string defaultValue = null) + public IDictionaryItem CreateDictionaryItemWithIdentity(string key, Guid? parentId, string? defaultValue = null) { using (var scope = ScopeProvider.CreateScope()) { @@ -121,7 +131,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the /// - public IDictionaryItem GetDictionaryItemById(int id) + public IDictionaryItem? GetDictionaryItemById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -292,7 +302,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the /// - public ILanguage GetLanguageById(int id) + public ILanguage? GetLanguageById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -444,7 +454,7 @@ namespace Umbraco.Cms.Core.Services } } - private void Audit(AuditType type, string message, int userId, int objectId, string entityType) + private void Audit(AuditType type, string message, int userId, int objectId, string? entityType) { _auditRepository.Save(new AuditItem(objectId, type, userId, entityType, message)); } @@ -455,14 +465,18 @@ namespace Umbraco.Cms.Core.Services /// if developers have a lot of dictionary items and translations, the caching and cloning size gets much larger because of /// the large object graphs. So now we don't cache or clone the attached ILanguage /// - private void EnsureDictionaryItemLanguageCallback(IDictionaryItem d) + private void EnsureDictionaryItemLanguageCallback(IDictionaryItem? d) { var item = d as DictionaryItem; if (item == null) return; item.GetLanguage = GetLanguageById; - foreach (var trans in item.Translations.OfType()) - trans.GetLanguage = GetLanguageById; + var translations = item.Translations?.OfType(); + if (translations is not null) + { + foreach (var trans in translations) + trans.GetLanguage = GetLanguageById; + } } public Dictionary GetDictionaryItemKeyMap() diff --git a/src/Umbraco.Core/Services/LocalizedTextService.cs b/src/Umbraco.Core/Services/LocalizedTextService.cs index c79d57f389..1f81995a63 100644 --- a/src/Umbraco.Core/Services/LocalizedTextService.cs +++ b/src/Umbraco.Core/Services/LocalizedTextService.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Services public class LocalizedTextService : ILocalizedTextService { private readonly ILogger _logger; - private readonly Lazy _fileSources; + private readonly Lazy? _fileSources; private IDictionary>>> _dictionarySource => _dictionarySourceLazy.Value; @@ -160,7 +160,7 @@ namespace Umbraco.Cms.Core.Services return aliasValue; } - public string Localize(string key, CultureInfo culture, IDictionary tokens = null) + public string Localize(string key, CultureInfo culture, IDictionary? tokens = null) { if (culture == null) throw new ArgumentNullException(nameof(culture)); @@ -174,8 +174,8 @@ namespace Umbraco.Cms.Core.Services return Localize(area, alias, culture, tokens); } - public string Localize(string area, string alias, CultureInfo culture, - IDictionary tokens = null) + public string Localize(string? area, string? alias, CultureInfo culture, + IDictionary? tokens = null) { if (culture == null) throw new ArgumentNullException(nameof(culture)); @@ -237,13 +237,13 @@ namespace Umbraco.Cms.Core.Services foreach (var key in keys) { var dictionaryKey = - (string)key.Attribute("alias"); + (string)key.Attribute("alias")!; //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files if (result.ContainsKey(dictionaryKey) == false) result.Add(dictionaryKey, key.Value); } - overallResult.Add(area.Attribute("alias").Value, result); + overallResult.Add(area.Attribute("alias")!.Value, result); } //Merge English Dictionary @@ -255,24 +255,24 @@ namespace Umbraco.Cms.Core.Services { IDictionary result = new Dictionary(StringComparer.InvariantCulture); - if (overallResult.ContainsKey(area.Attribute("alias").Value)) + if (overallResult.ContainsKey(area.Attribute("alias")!.Value)) { - result = overallResult[area.Attribute("alias").Value]; + result = overallResult[area.Attribute("alias")!.Value]; } var keys = area.XPathSelectElements("./key"); foreach (var key in keys) { var dictionaryKey = - (string)key.Attribute("alias"); + (string)key.Attribute("alias")!; //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files if (result.ContainsKey(dictionaryKey) == false) result.Add(dictionaryKey, key.Value); } - if (!overallResult.ContainsKey(area.Attribute("alias").Value)) + if (!overallResult.ContainsKey(area.Attribute("alias")!.Value)) { - overallResult.Add(area.Attribute("alias").Value, result); + overallResult.Add(area.Attribute("alias")!.Value, result); } } } @@ -289,7 +289,7 @@ namespace Umbraco.Cms.Core.Services foreach (var key in keys) { var dictionaryKey = - (string)key.Attribute("alias"); + (string)key.Attribute("alias")!; //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files if (result.ContainsKey(dictionaryKey) == false) result.Add(dictionaryKey, key.Value); @@ -304,7 +304,7 @@ namespace Umbraco.Cms.Core.Services foreach (var key in keys) { var dictionaryKey = - (string)key.Attribute("alias"); + (string)key.Attribute("alias")!; //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files if (result.ContainsKey(dictionaryKey) == false) result.Add(dictionaryKey, key.Value); @@ -369,11 +369,11 @@ namespace Umbraco.Cms.Core.Services if (currentCulture.Name.Length > 2) return currentCulture; var attempt = _fileSources.Value.TryConvert2LetterCultureTo4Letter(currentCulture.TwoLetterISOLanguageName); - return attempt.Success ? attempt.Result : currentCulture; + return attempt.Success ? attempt.Result! : currentCulture; } - private string GetFromDictionarySource(CultureInfo culture, string area, string key, - IDictionary tokens) + private string GetFromDictionarySource(CultureInfo culture, string? area, string key, + IDictionary? tokens) { if (_dictionarySource.ContainsKey(culture) == false) { @@ -384,7 +384,7 @@ namespace Umbraco.Cms.Core.Services } - string found = null; + string? found = null; if (string.IsNullOrWhiteSpace(area)) { _noAreaDictionarySource[culture].Value.TryGetValue(key, out found); @@ -426,7 +426,7 @@ namespace Umbraco.Cms.Core.Services /// we support a dictionary which means in the future we can really have any sort of token system. /// Currently though, the token key's will need to be an integer and sequential - though we aren't going to throw exceptions if that is not the case. /// - internal static string ParseTokens(string value, IDictionary tokens) + internal static string ParseTokens(string value, IDictionary? tokens) { if (tokens == null || tokens.Any() == false) { diff --git a/src/Umbraco.Core/Services/LocalizedTextServiceFileSources.cs b/src/Umbraco.Core/Services/LocalizedTextServiceFileSources.cs index a24d47fe4b..9c9132d9bb 100644 --- a/src/Umbraco.Core/Services/LocalizedTextServiceFileSources.cs +++ b/src/Umbraco.Core/Services/LocalizedTextServiceFileSources.cs @@ -18,8 +18,8 @@ namespace Umbraco.Cms.Core.Services { private readonly ILogger _logger; private readonly IAppPolicyCache _cache; - private readonly IEnumerable _supplementFileSources; - private readonly DirectoryInfo _fileSourceFolder; + private readonly IEnumerable? _supplementFileSources; + private readonly DirectoryInfo? _fileSourceFolder; // TODO: See other notes in this class, this is purely a hack because we store 2 letter culture file names that contain 4 letter cultures :( private readonly Dictionary _twoLetterCultureConverter = new Dictionary(); @@ -75,7 +75,7 @@ namespace Umbraco.Cms.Core.Services // need to check if the file is 2 letters, then open it to try to find it's 4 letter culture, then use that // if it's successful. We're going to assume (though it seems assuming in the legacy logic is never a great idea) // that any 4 letter file is named with the actual culture that it is! - CultureInfo culture = null; + CultureInfo? culture = null; if (filename.Length == 2) { //we need to open the file to see if we can read it's 'real' culture, we'll use XmlReader since we don't @@ -128,7 +128,7 @@ namespace Umbraco.Cms.Core.Services MergeSupplementaryFiles(culture, xdoc); return xdoc; - }, isSliding: true, timeout: TimeSpan.FromMinutes(10), dependentFiles: new[] { localCopy.FullName })); + }, isSliding: true, timeout: TimeSpan.FromMinutes(10), dependentFiles: new[] { localCopy.FullName })!); } return result; }); @@ -153,20 +153,20 @@ namespace Umbraco.Cms.Core.Services } // TODO: See other notes in this class, this is purely a hack because we store 2 letter culture file names that contain 4 letter cultures :( - public Attempt TryConvert2LetterCultureTo4Letter(string twoLetterCulture) + public Attempt TryConvert2LetterCultureTo4Letter(string twoLetterCulture) { - if (twoLetterCulture.Length != 2) return Attempt.Fail(); + if (twoLetterCulture.Length != 2) return Attempt.Fail(); //This needs to be resolved before continuing so that the _twoLetterCultureConverter cache is initialized var resolved = _xmlSources.Value; return _twoLetterCultureConverter.ContainsKey(twoLetterCulture) ? Attempt.Succeed(_twoLetterCultureConverter[twoLetterCulture]) - : Attempt.Fail(); + : Attempt.Fail(); } // TODO: See other notes in this class, this is purely a hack because we store 2 letter culture file names that contain 4 letter cultures :( - public Attempt TryConvert4LetterCultureTo2Letter(CultureInfo culture) + public Attempt TryConvert4LetterCultureTo2Letter(CultureInfo culture) { if (culture == null) throw new ArgumentNullException("culture"); @@ -175,7 +175,7 @@ namespace Umbraco.Cms.Core.Services return _twoLetterCultureConverter.Values.Contains(culture) ? Attempt.Succeed(culture.Name.Substring(0, 2)) - : Attempt.Fail(); + : Attempt.Fail(); } private void MergeSupplementaryFiles(CultureInfo culture, XDocument xMasterDoc) @@ -211,11 +211,11 @@ namespace Umbraco.Cms.Core.Services if (xChildDoc.Root == null || xChildDoc.Root.Name != "language") continue; foreach (var xArea in xChildDoc.Root.Elements("area") - .Where(x => ((string)x.Attribute("alias")).IsNullOrWhiteSpace() == false)) + .Where(x => ((string)x.Attribute("alias")!).IsNullOrWhiteSpace() == false)) { - var areaAlias = (string)xArea.Attribute("alias"); + var areaAlias = (string)xArea.Attribute("alias")!; - var areaFound = xMasterDoc.Root.Elements("area").FirstOrDefault(x => ((string)x.Attribute("alias")) == areaAlias); + var areaFound = xMasterDoc.Root.Elements("area").FirstOrDefault(x => ((string)x.Attribute("alias")!) == areaAlias); if (areaFound == null) { //add the whole thing @@ -238,10 +238,10 @@ namespace Umbraco.Cms.Core.Services //merge in the child elements foreach (var key in source.Elements("key") - .Where(x => ((string)x.Attribute("alias")).IsNullOrWhiteSpace() == false)) + .Where(x => ((string)x.Attribute("alias")!).IsNullOrWhiteSpace() == false)) { - var keyAlias = (string)key.Attribute("alias"); - var keyFound = destination.Elements("key").FirstOrDefault(x => ((string)x.Attribute("alias")) == keyAlias); + var keyAlias = (string)key.Attribute("alias")!; + var keyFound = destination.Elements("key").FirstOrDefault(x => ((string)x.Attribute("alias")!) == keyAlias); if (keyFound == null) { //append, it doesn't exist diff --git a/src/Umbraco.Core/Services/MacroService.cs b/src/Umbraco.Core/Services/MacroService.cs index dd3c2d9af1..602a7ef22e 100644 --- a/src/Umbraco.Core/Services/MacroService.cs +++ b/src/Umbraco.Core/Services/MacroService.cs @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.Services /// /// Alias to retrieve an for /// An object - public IMacro GetByAlias(string alias) + public IMacro? GetByAlias(string alias) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Services } } - public IMacro GetById(int id) + public IMacro? GetById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -69,7 +69,7 @@ namespace Umbraco.Cms.Core.Services } } - public IMacro GetById(Guid id) + public IMacro? GetById(Guid id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index def72653bd..56c508fa22 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Services #region Count - public int Count(string mediaTypeAlias = null) + public int Count(string? mediaTypeAlias = null) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Services } } - public int CountNotTrashed(string mediaTypeAlias = null) + public int CountNotTrashed(string? mediaTypeAlias = null) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -80,7 +80,7 @@ namespace Umbraco.Cms.Core.Services } } - public int CountChildren(int parentId, string mediaTypeAlias = null) + public int CountChildren(int parentId, string? mediaTypeAlias = null) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -89,7 +89,7 @@ namespace Umbraco.Cms.Core.Services } } - public int CountDescendants(int parentId, string mediaTypeAlias = null) + public int CountDescendants(int parentId, string? mediaTypeAlias = null) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -150,7 +150,7 @@ namespace Umbraco.Cms.Core.Services var media = new Core.Models.Media(name, parentId, mediaType); using (var scope = ScopeProvider.CreateScope()) { - CreateMedia(scope, media, parent, userId, false); + CreateMedia(scope, media, parent!, userId, false); scope.Complete(); } @@ -202,7 +202,7 @@ namespace Umbraco.Cms.Core.Services /// The alias of the media type. /// The optional id of the user creating the media. /// The media object. - public IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = Cms.Core.Constants.Security.SuperUserId) + public IMedia CreateMedia(string name, IMedia? parent, string mediaTypeAlias, int userId = Cms.Core.Constants.Security.SuperUserId) { if (parent == null) throw new ArgumentNullException(nameof(parent)); @@ -288,7 +288,7 @@ namespace Umbraco.Cms.Core.Services } } - private void CreateMedia(IScope scope, Core.Models.Media media, IMedia parent, int userId, bool withIdentity) + private void CreateMedia(IScope scope, Core.Models.Media media, IMedia? parent, int userId, bool withIdentity) { EventMessages eventMessages = EventMessagesFactory.Get(); @@ -323,7 +323,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the Media to retrieve /// - public IMedia GetById(int id) + public IMedia? GetById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -354,7 +354,7 @@ namespace Umbraco.Cms.Core.Services /// /// Guid key of the Media to retrieve /// - public IMedia GetById(Guid key) + public IMedia? GetById(Guid key) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -381,7 +381,7 @@ namespace Umbraco.Cms.Core.Services } /// - public IEnumerable GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery filter = null, Ordering ordering = null) + public IEnumerable GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null) { if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex)); if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize)); @@ -399,7 +399,7 @@ namespace Umbraco.Cms.Core.Services } /// - public IEnumerable GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery filter = null, Ordering ordering = null) + public IEnumerable GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null) { if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex)); if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize)); @@ -477,10 +477,10 @@ namespace Umbraco.Cms.Core.Services /// /// to retrieve ancestors for /// An Enumerable list of objects - public IEnumerable GetAncestors(IMedia media) + public IEnumerable GetAncestors(IMedia? media) { //null check otherwise we get exceptions - if (media.Path.IsNullOrWhiteSpace()) return Enumerable.Empty(); + if (media is null || media.Path.IsNullOrWhiteSpace()) return Enumerable.Empty(); var rootId = Cms.Core.Constants.System.RootString; var ids = media.Path.Split(Constants.CharArrays.Comma) @@ -499,7 +499,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetPagedChildren(int id, long pageIndex, int pageSize, out long totalChildren, - IQuery filter = null, Ordering ordering = null) + IQuery? filter = null, Ordering? ordering = null) { if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex)); if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize)); @@ -518,7 +518,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalChildren, - IQuery filter = null, Ordering ordering = null) + IQuery? filter = null, Ordering? ordering = null) { if (ordering == null) ordering = Ordering.By("Path"); @@ -542,7 +542,7 @@ namespace Umbraco.Cms.Core.Services } } - private IQuery GetPagedDescendantQuery(string mediaPath) + private IQuery GetPagedDescendantQuery(string? mediaPath) { var query = Query(); if (!mediaPath.IsNullOrWhiteSpace()) @@ -551,7 +551,7 @@ namespace Umbraco.Cms.Core.Services } private IEnumerable GetPagedLocked(IQuery query, long pageIndex, int pageSize, out long totalChildren, - IQuery filter, Ordering ordering) + IQuery? filter, Ordering ordering) { if (pageIndex < 0) throw new ArgumentOutOfRangeException(nameof(pageIndex)); if (pageSize <= 0) throw new ArgumentOutOfRangeException(nameof(pageSize)); @@ -565,7 +565,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id of the to retrieve the parent from /// Parent object - public IMedia GetParent(int id) + public IMedia? GetParent(int id) { // intentionally not locking var media = GetById(id); @@ -577,12 +577,13 @@ namespace Umbraco.Cms.Core.Services /// /// to retrieve the parent from /// Parent object - public IMedia GetParent(IMedia media) + public IMedia? GetParent(IMedia? media) { - if (media.ParentId == Cms.Core.Constants.System.Root || media.ParentId == Cms.Core.Constants.System.RecycleBinMedia) + var parentId = media?.ParentId; + if (parentId is null || media?.ParentId == Cms.Core.Constants.System.Root || media?.ParentId == Cms.Core.Constants.System.RecycleBinMedia) return null; - return GetById(media.ParentId); + return GetById(parentId.Value); } /// @@ -601,7 +602,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetPagedMediaInRecycleBin(long pageIndex, int pageSize, out long totalRecords, - IQuery filter = null, Ordering ordering = null) + IQuery? filter = null, Ordering? ordering = null) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -653,7 +654,7 @@ namespace Umbraco.Cms.Core.Services /// /// The to save /// Id of the User saving the Media - public Attempt Save(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId) + public Attempt Save(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages eventMessages = EventMessagesFactory.Get(); @@ -700,7 +701,7 @@ namespace Umbraco.Cms.Core.Services /// /// Collection of to save /// Id of the User saving the Media - public Attempt Save(IEnumerable medias, int userId = Cms.Core.Constants.Security.SuperUserId) + public Attempt Save(IEnumerable medias, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages messages = EventMessagesFactory.Get(); IMedia[] mediasA = medias.ToArray(); @@ -747,7 +748,7 @@ namespace Umbraco.Cms.Core.Services /// /// The to delete /// Id of the User deleting the Media - public Attempt Delete(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId) + public Attempt Delete(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages messages = EventMessagesFactory.Get(); @@ -883,7 +884,7 @@ namespace Umbraco.Cms.Core.Services /// /// The to delete /// Id of the User deleting the Media - public Attempt MoveToRecycleBin(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId) + public Attempt MoveToRecycleBin(IMedia media, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages messages = EventMessagesFactory.Get(); var moves = new List<(IMedia, string)>(); @@ -925,7 +926,7 @@ namespace Umbraco.Cms.Core.Services /// The to move /// Id of the Media's new Parent /// Id of the User moving the Media - public Attempt Move(IMedia media, int parentId, int userId = Cms.Core.Constants.Security.SuperUserId) + public Attempt Move(IMedia media, int parentId, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages messages = EventMessagesFactory.Get(); @@ -942,7 +943,7 @@ namespace Umbraco.Cms.Core.Services { scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); - IMedia parent = parentId == Cms.Core.Constants.System.Root ? null : GetById(parentId); + IMedia? parent = parentId == Cms.Core.Constants.System.Root ? null : GetById(parentId); if (parentId != Cms.Core.Constants.System.Root && (parent == null || parent.Trashed)) { throw new InvalidOperationException("Parent does not exist or is trashed."); // causes rollback @@ -976,7 +977,7 @@ namespace Umbraco.Cms.Core.Services // MUST be called from within WriteLock // trash indicates whether we are trashing, un-trashing, or not changing anything - private void PerformMoveLocked(IMedia media, int parentId, IMedia parent, int userId, ICollection<(IMedia, string)> moves, bool? trash) + private void PerformMoveLocked(IMedia media, int parentId, IMedia? parent, int userId, ICollection<(IMedia, string)> moves, bool? trash) { media.ParentId = parentId; @@ -1163,7 +1164,7 @@ namespace Umbraco.Cms.Core.Services #region Private Methods - private void Audit(AuditType type, int userId, int objectId, string message = null) + private void Audit(AuditType type, int userId, int objectId, string? message = null) { _auditRepository.Save(new AuditItem(objectId, type, userId, ObjectTypes.GetName(UmbracoObjectTypes.Media), message)); } @@ -1172,7 +1173,7 @@ namespace Umbraco.Cms.Core.Services #region File Management - public Stream GetMediaFileContentStream(string filepath) + public Stream? GetMediaFileContentStream(string filepath) { if (_mediaFileManager.FileSystem.FileExists(filepath) == false) return null; diff --git a/src/Umbraco.Core/Services/MemberGroupService.cs b/src/Umbraco.Core/Services/MemberGroupService.cs index 253f2b433a..faf64f445e 100644 --- a/src/Umbraco.Core/Services/MemberGroupService.cs +++ b/src/Umbraco.Core/Services/MemberGroupService.cs @@ -40,7 +40,7 @@ namespace Umbraco.Cms.Core.Services } } - public IMemberGroup GetById(int id) + public IMemberGroup? GetById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs index bf0d326a32..6da6c277f4 100644 --- a/src/Umbraco.Core/Services/MemberService.cs +++ b/src/Umbraco.Core/Services/MemberService.cs @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Services /// If no alias is supplied then the count for all Member will be returned /// Optional alias for the MemberType when counting number of Members /// with number of Members - public int Count(string memberTypeAlias = null) + public int Count(string? memberTypeAlias = null) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -294,7 +294,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id /// - public IMember GetById(int id) + public IMember? GetById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -310,7 +310,7 @@ namespace Umbraco.Cms.Core.Services /// and the user id in the membership provider. /// Id /// - public IMember GetByKey(Guid id) + public IMember? GetByKey(Guid id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -337,19 +337,19 @@ namespace Umbraco.Cms.Core.Services } public IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords, - string orderBy, Direction orderDirection, string memberTypeAlias = null, string filter = "") + string orderBy, Direction orderDirection, string? memberTypeAlias = null, string filter = "") { return GetAll(pageIndex, pageSize, out totalRecords, orderBy, orderDirection, true, memberTypeAlias, filter); } public IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords, - string orderBy, Direction orderDirection, bool orderBySystemField, string memberTypeAlias, string filter) + string orderBy, Direction orderDirection, bool orderBySystemField, string? memberTypeAlias, string filter) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query1 = memberTypeAlias == null ? null : Query().Where(x => x.ContentTypeAlias == memberTypeAlias); - var query2 = filter == null ? null : Query().Where(x => x.Name.Contains(filter) || x.Username.Contains(filter) || x.Email.Contains(filter)); + var query2 = filter == null ? null : Query().Where(x => (x.Name != null && x.Name.Contains(filter)) || x.Username.Contains(filter) || x.Email.Contains(filter)); return _memberRepository.GetPage(query1, pageIndex, pageSize, out totalRecords, query2, Ordering.By(orderBy, orderDirection, isCustomField: !orderBySystemField)); } } @@ -377,7 +377,7 @@ namespace Umbraco.Cms.Core.Services /// /// Email to use for retrieval /// - public IMember GetByEmail(string email) + public IMember? GetByEmail(string email) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -479,19 +479,19 @@ namespace Umbraco.Cms.Core.Services switch (matchType) { case StringPropertyMatchType.Exact: - query.Where(member => member.Name.Equals(displayNameToMatch)); + query.Where(member => string.Equals(member.Name, displayNameToMatch)); break; case StringPropertyMatchType.Contains: - query.Where(member => member.Name.Contains(displayNameToMatch)); + query.Where(member => member.Name != null && member.Name.Contains(displayNameToMatch)); break; case StringPropertyMatchType.StartsWith: - query.Where(member => member.Name.StartsWith(displayNameToMatch)); + query.Where(member => member.Name != null && member.Name.StartsWith(displayNameToMatch)); break; case StringPropertyMatchType.EndsWith: - query.Where(member => member.Name.EndsWith(displayNameToMatch)); + query.Where(member => member.Name != null && member.Name.EndsWith(displayNameToMatch)); break; case StringPropertyMatchType.Wildcard: - query.Where(member => member.Name.SqlWildcard(displayNameToMatch, TextColumnType.NVarchar)); + query.Where(member => member.Name != null && member.Name.SqlWildcard(displayNameToMatch, TextColumnType.NVarchar)); break; default: throw new ArgumentOutOfRangeException(nameof(matchType)); // causes rollback // causes rollback @@ -600,16 +600,16 @@ namespace Umbraco.Cms.Core.Services switch (matchType) { case StringPropertyMatchType.Exact: - query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue.SqlEquals(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue.SqlEquals(value, TextColumnType.NVarchar))); + query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue!.SqlEquals(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue!.SqlEquals(value, TextColumnType.NVarchar))); break; case StringPropertyMatchType.Contains: - query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue.SqlContains(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue.SqlContains(value, TextColumnType.NVarchar))); + query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue!.SqlContains(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue!.SqlContains(value, TextColumnType.NVarchar))); break; case StringPropertyMatchType.StartsWith: query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue.SqlStartsWith(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue.SqlStartsWith(value, TextColumnType.NVarchar))); break; case StringPropertyMatchType.EndsWith: - query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue.SqlEndsWith(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue.SqlEndsWith(value, TextColumnType.NVarchar))); + query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && (((Member) x).LongStringPropertyValue!.SqlEndsWith(value, TextColumnType.NText) || ((Member) x).ShortStringPropertyValue!.SqlEndsWith(value, TextColumnType.NVarchar))); break; default: throw new ArgumentOutOfRangeException(nameof(matchType)); @@ -856,7 +856,7 @@ namespace Umbraco.Cms.Core.Services } } - private void DeleteLocked(IScope scope, IMember member, EventMessages evtMsgs, IDictionary notificationState = null) + private void DeleteLocked(IScope scope, IMember member, EventMessages evtMsgs, IDictionary? notificationState = null) { // a member has no descendants _memberRepository.Delete(member); @@ -898,7 +898,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// A list of member roles - public IEnumerable GetAllRoles(int memberId) + public IEnumerable? GetAllRoles(int memberId) { using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) { @@ -908,13 +908,13 @@ namespace Umbraco.Cms.Core.Services } } - public IEnumerable GetAllRoles(string username) + public IEnumerable GetAllRoles(string? username) { using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IEnumerable result = _memberGroupRepository.GetMemberGroupsForMember(username); - return result.Select(x => x.Name).Distinct(); + return result.Where(x => x.Name != null).Select(x => x.Name).Distinct()!; } } @@ -1075,7 +1075,7 @@ namespace Umbraco.Cms.Core.Services #region Private Methods - private void Audit(AuditType type, int userId, int objectId, string message = null) => _auditRepository.Save(new AuditItem(objectId, type, userId, ObjectTypes.GetName(UmbracoObjectTypes.Member), message)); + private void Audit(AuditType type, int userId, int objectId, string? message = null) => _auditRepository.Save(new AuditItem(objectId, type, userId, ObjectTypes.GetName(UmbracoObjectTypes.Member), message)); #endregion @@ -1089,12 +1089,12 @@ namespace Umbraco.Cms.Core.Services /// This is internal for now and is used to export a member in the member editor, /// it will raise an event so that auditing logs can be created. /// - public MemberExportModel ExportMember(Guid key) + public MemberExportModel? ExportMember(Guid key) { using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) { IQuery query = Query().Where(x => x.Key == key); - IMember member = _memberRepository.Get(query).FirstOrDefault(); + IMember? member = _memberRepository.Get(query).FirstOrDefault(); if (member == null) { @@ -1108,7 +1108,7 @@ namespace Umbraco.Cms.Core.Services Name = member.Name, Username = member.Username, Email = member.Email, - Groups = GetAllRoles(member.Id).ToList(), + Groups = GetAllRoles(member.Id)?.ToList(), ContentTypeAlias = member.ContentTypeAlias, CreateDate = member.CreateDate, UpdateDate = member.UpdateDate, diff --git a/src/Umbraco.Core/Services/NotificationService.cs b/src/Umbraco.Core/Services/NotificationService.cs index 28e309bef5..9cd34675d7 100644 --- a/src/Umbraco.Core/Services/NotificationService.cs +++ b/src/Umbraco.Core/Services/NotificationService.cs @@ -73,7 +73,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// - public void SendNotifications(IUser operatingUser, IEnumerable entities, string action, string actionName, Uri siteUri, + public void SendNotifications(IUser operatingUser, IEnumerable entities, string? action, string? actionName, Uri siteUri, Func<(IUser user, NotificationEmailSubjectParams subject), string> createSubject, Func<(IUser user, NotificationEmailBodyParams body, bool isHtml), string> createBody) { @@ -138,7 +138,7 @@ namespace Umbraco.Cms.Core.Services } while (id > 0); } - private IEnumerable GetUsersNotifications(IEnumerable userIds, string action, IEnumerable nodeIds, Guid objectType) + private IEnumerable GetUsersNotifications(IEnumerable userIds, string? action, IEnumerable nodeIds, Guid objectType) { using (var scope = _uowProvider.CreateScope(autoComplete: true)) { @@ -287,7 +287,7 @@ namespace Umbraco.Cms.Core.Services /// Callback to create the mail subject /// Callback to create the mail body private NotificationRequest CreateNotificationRequest(IUser performingUser, IUser mailingUser, IContent content, IContentBase oldDoc, - string actionName, + string? actionName, Uri siteUri, Func<(IUser user, NotificationEmailSubjectParams subject), string> createSubject, Func<(IUser user, NotificationEmailBodyParams body, bool isHtml), string> createBody) @@ -314,14 +314,14 @@ namespace Umbraco.Cms.Core.Services { // TODO: doesn't take into account variants - var newText = p.GetValue() != null ? p.GetValue().ToString() : ""; + var newText = p.GetValue() != null ? p.GetValue()?.ToString() : ""; var oldText = newText; // check if something was changed and display the changes otherwise display the fields if (oldDoc.Properties.Contains(p.PropertyType.Alias)) { var oldProperty = oldDoc.Properties[p.PropertyType.Alias]; - oldText = oldProperty.GetValue() != null ? oldProperty.GetValue().ToString() : ""; + oldText = oldProperty?.GetValue() != null ? oldProperty.GetValue()?.ToString() : ""; // replace HTML with char equivalent ReplaceHtmlSymbols(ref oldText); @@ -350,25 +350,29 @@ namespace Umbraco.Cms.Core.Services { //Create the HTML based summary (ul of culture names) - var culturesChanged = content.CultureInfos.Values.Where(x => x.WasDirty()) + var culturesChanged = content.CultureInfos?.Values.Where(x => x.WasDirty()) .Select(x => x.Culture) .Select(_localizationService.GetLanguageByIsoCode) .WhereNotNull() .Select(x => x.CultureName); summary.Append("
    "); - foreach (var culture in culturesChanged) + if (culturesChanged is not null) { - summary.Append("
  • "); - summary.Append(culture); - summary.Append("
  • "); + foreach (var culture in culturesChanged) + { + summary.Append("
  • "); + summary.Append(culture); + summary.Append("
  • "); + } } + summary.Append("
"); } else { //Create the text based summary (csv of culture names) - var culturesChanged = string.Join(", ", content.CultureInfos.Values.Where(x => x.WasDirty()) + var culturesChanged = string.Join(", ", content.CultureInfos!.Values.Where(x => x.WasDirty()) .Select(x => x.Culture) .Select(_localizationService.GetLanguageByIsoCode) .WhereNotNull() @@ -407,7 +411,7 @@ namespace Umbraco.Cms.Core.Services string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), summary.ToString()); - var fromMail = _contentSettings.Notifications.Email ?? _globalSettings.Smtp.From; + var fromMail = _contentSettings.Notifications.Email ?? _globalSettings.Smtp?.From; var subject = createSubject((mailingUser, subjectVars)); var body = ""; @@ -458,10 +462,10 @@ namespace Umbraco.Cms.Core.Services /// Replaces the HTML symbols with the character equivalent. /// /// The old string. - private static void ReplaceHtmlSymbols(ref string oldString) + private static void ReplaceHtmlSymbols(ref string? oldString) { if (oldString.IsNullOrWhiteSpace()) return; - oldString = oldString.Replace(" ", " "); + oldString = oldString!.Replace(" ", " "); oldString = oldString.Replace("’", "'"); oldString = oldString.Replace("&", "&"); oldString = oldString.Replace("“", "“"); @@ -490,7 +494,7 @@ namespace Umbraco.Cms.Core.Services private class NotificationRequest { - public NotificationRequest(EmailMessage mail, string action, string userName, string email) + public NotificationRequest(EmailMessage mail, string? action, string? userName, string? email) { Mail = mail; Action = action; @@ -500,11 +504,11 @@ namespace Umbraco.Cms.Core.Services public EmailMessage Mail { get; } - public string Action { get; } + public string? Action { get; } - public string UserName { get; } + public string? UserName { get; } - public string Email { get; } + public string? Email { get; } } private void Process(BlockingCollection notificationRequests) @@ -514,7 +518,7 @@ namespace Umbraco.Cms.Core.Services _logger.LogDebug("Begin processing notifications."); while (true) { - NotificationRequest request; + NotificationRequest? request; while (notificationRequests.TryTake(out request, 8 * 1000)) // stay on for 8s { try diff --git a/src/Umbraco.Core/Services/PropertyValidationService.cs b/src/Umbraco.Core/Services/PropertyValidationService.cs index 30aff6dc9a..093e765948 100644 --- a/src/Umbraco.Core/Services/PropertyValidationService.cs +++ b/src/Umbraco.Core/Services/PropertyValidationService.cs @@ -119,15 +119,15 @@ namespace Umbraco.Cms.Core.Services } /// - public bool IsPropertyValid(IProperty property, string? culture = "*", string segment = "*") + public bool IsPropertyValid(IProperty property, string? culture = "*", string? segment = "*") { //NOTE - the pvalue and vvalues logic in here is borrowed directly from the Property.Values setter so if you are wondering what that's all about, look there. // The underlying Property._pvalue and Property._vvalues are not exposed but we can re-create these values ourselves which is what it's doing. - culture = culture.NullOrWhiteSpaceAsNull(); - segment = segment.NullOrWhiteSpaceAsNull(); + culture = culture?.NullOrWhiteSpaceAsNull(); + segment = segment?.NullOrWhiteSpaceAsNull(); - IPropertyValue pvalue = null; + IPropertyValue? pvalue = null; // if validating invariant/neutral, and it is supported, validate // (including ensuring that the value exists, if mandatory) @@ -160,8 +160,8 @@ namespace Umbraco.Cms.Core.Services var pvalues = property.Values.Where(x => x != pvalue && // don't revalidate pvalue property.PropertyType.SupportsVariation(x.Culture, x.Segment, true) && // the value variation is ok - (culture == "*" || x.Culture.InvariantEquals(culture)) && // the culture matches - (segment == "*" || x.Segment.InvariantEquals(segment))) // the segment matches + (culture == "*" || (x.Culture?.InvariantEquals(culture) ?? false)) && // the culture matches + (segment == "*" || (x.Segment?.InvariantEquals(segment) ?? false))) // the segment matches .ToList(); return pvalues.Count == 0 || pvalues.All(x => IsValidPropertyValue(property, x.EditedValue)); @@ -173,7 +173,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// True is property value is valid, otherwise false - private bool IsValidPropertyValue(IProperty property, object value) + private bool IsValidPropertyValue(IProperty property, object? value) { return IsPropertyValueValid(property.PropertyType, value); } @@ -181,7 +181,7 @@ namespace Umbraco.Cms.Core.Services /// /// Determines whether a value is valid for this property type. /// - private bool IsPropertyValueValid(IPropertyType propertyType, object value) + private bool IsPropertyValueValid(IPropertyType propertyType, object? value) { var editor = _propertyEditors[propertyType.PropertyEditorAlias]; if (editor == null) diff --git a/src/Umbraco.Core/Services/PublicAccessService.cs b/src/Umbraco.Core/Services/PublicAccessService.cs index 0b4709873d..47431a97a3 100644 --- a/src/Umbraco.Core/Services/PublicAccessService.cs +++ b/src/Umbraco.Core/Services/PublicAccessService.cs @@ -40,7 +40,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// Returns null if no entry is found - public PublicAccessEntry GetEntryForContent(IContent content) + public PublicAccessEntry? GetEntryForContent(IContent content) { return GetEntryForContent(content.Path.EnsureEndsWith("," + content.Id)); } diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 64aef06761..65adc8892c 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -522,7 +522,7 @@ namespace Umbraco.Cms.Core.Services IQuery? filterQuery = null; if (filter.IsNullOrWhiteSpace() == false) { - filterQuery = Query().Where(x => x.Name.Contains(filter!) || x.Username.Contains(filter!)); + filterQuery = Query().Where(x => (x.Name != null && x.Name.Contains(filter!)) || x.Username.Contains(filter!)); } return GetAll(pageIndex, pageSize, out totalRecords, orderBy, orderDirection, userState, userGroups, null, filterQuery); @@ -1005,7 +1005,7 @@ namespace Umbraco.Cms.Core.Services .GroupBy(x => x.UserGroupId); return new EntityPermissionCollection( - permissions.Select(x => GetPermissionsForPathForGroup(x, pathIds, fallbackToDefaultPermissions))); + permissions.Select(x => GetPermissionsForPathForGroup(x, pathIds, fallbackToDefaultPermissions)).Where(x => x is not null)!); } /// diff --git a/src/Umbraco.Core/StaticApplicationLogging.cs b/src/Umbraco.Core/StaticApplicationLogging.cs index e216011014..83ce4e89f1 100644 --- a/src/Umbraco.Core/StaticApplicationLogging.cs +++ b/src/Umbraco.Core/StaticApplicationLogging.cs @@ -5,7 +5,7 @@ namespace Umbraco.Cms.Core { public static class StaticApplicationLogging { - private static ILoggerFactory _loggerFactory; + private static ILoggerFactory? _loggerFactory; public static void Initialize(ILoggerFactory loggerFactory) { diff --git a/src/Umbraco.Core/Strings/Css/StylesheetRule.cs b/src/Umbraco.Core/Strings/Css/StylesheetRule.cs index b6ffeaa57e..06a888c812 100644 --- a/src/Umbraco.Core/Strings/Css/StylesheetRule.cs +++ b/src/Umbraco.Core/Strings/Css/StylesheetRule.cs @@ -6,11 +6,11 @@ namespace Umbraco.Cms.Core.Strings.Css { public class StylesheetRule { - public string Name { get; set; } + public string Name { get; set; } = null!; - public string Selector { get; set; } + public string Selector { get; set; } = null!; - public string Styles { get; set; } + public string Styles { get; set; } = null!; public override string ToString() { @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Strings.Css { // since we already have a string builder in play here, we'll append to it the "hard" way // instead of using string interpolation (for increased performance) - foreach (var style in Styles.Split(Constants.CharArrays.Semicolon, StringSplitOptions.RemoveEmptyEntries)) + foreach (var style in Styles?.Split(Constants.CharArrays.Semicolon, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty()) { sb.Append("\t").Append(style.StripNewLines().Trim()).Append(";").Append(Environment.NewLine); } diff --git a/src/Umbraco.Core/Telemetry/Models/PackageTelemetry.cs b/src/Umbraco.Core/Telemetry/Models/PackageTelemetry.cs index c23a30648b..53dc6d1a6e 100644 --- a/src/Umbraco.Core/Telemetry/Models/PackageTelemetry.cs +++ b/src/Umbraco.Core/Telemetry/Models/PackageTelemetry.cs @@ -21,6 +21,6 @@ namespace Umbraco.Cms.Core.Telemetry.Models /// This may be an empty string if no version is specified, or if package telemetry has been restricted. /// [DataMember(Name = "version")] - public string Version { get; set; } + public string? Version { get; set; } } } diff --git a/src/Umbraco.Core/Telemetry/Models/TelemetryReportData.cs b/src/Umbraco.Core/Telemetry/Models/TelemetryReportData.cs index d19e24695b..71fee55e4a 100644 --- a/src/Umbraco.Core/Telemetry/Models/TelemetryReportData.cs +++ b/src/Umbraco.Core/Telemetry/Models/TelemetryReportData.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.Telemetry.Models /// Gets or sets the Umbraco CMS version. /// [DataMember(Name = "version")] - public string Version { get; set; } + public string? Version { get; set; } /// /// Gets or sets an enumerable containing information about packages. @@ -29,6 +29,6 @@ namespace Umbraco.Cms.Core.Telemetry.Models /// Contains only the name and version of the packages, unless no version is specified. /// [DataMember(Name = "packages")] - public IEnumerable Packages { get; set; } + public IEnumerable? Packages { get; set; } } } diff --git a/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs b/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs index 98e8baf4e8..16f7a609c3 100644 --- a/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs +++ b/src/Umbraco.Core/Templates/UmbracoComponentRenderer.cs @@ -106,7 +106,7 @@ namespace Umbraco.Cms.Core.Templates var html = (await _macroRenderer.RenderAsync(alias, content, macroProps)).Text; - return new HtmlEncodedString(html); + return new HtmlEncodedString(html!); } } } diff --git a/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs b/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs index a8b6401cea..44bf0e3c3c 100644 --- a/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs +++ b/src/Umbraco.Core/Web/Mvc/PluginControllerMetadata.cs @@ -7,10 +7,10 @@ namespace Umbraco.Cms.Core.Web.Mvc /// public class PluginControllerMetadata { - public Type ControllerType { get; set; } - public string ControllerName { get; set; } - public string ControllerNamespace { get; set; } - public string AreaName { get; set; } + public Type? ControllerType { get; set; } + public string? ControllerName { get; set; } + public string? ControllerNamespace { get; set; } + public string? AreaName { get; set; } /// /// This is determined by another attribute [IsBackOffice] which slightly modifies the route path diff --git a/src/Umbraco.Infrastructure/Manifest/DashboardAccessRuleConverter.cs b/src/Umbraco.Infrastructure/Manifest/DashboardAccessRuleConverter.cs index 80f944950c..1a34fe373c 100644 --- a/src/Umbraco.Infrastructure/Manifest/DashboardAccessRuleConverter.cs +++ b/src/Umbraco.Infrastructure/Manifest/DashboardAccessRuleConverter.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Cms.Core.Dashboards; +using Umbraco.Cms.Core.Exceptions; using Umbraco.Cms.Infrastructure.Serialization; namespace Umbraco.Cms.Core.Manifest @@ -23,7 +24,7 @@ namespace Umbraco.Cms.Core.Manifest // see Create above, target is either DataEditor (parameter) or ConfiguredDataEditor (property) if (!(target is AccessRule accessRule)) - throw new Exception("panic."); + throw new PanicException("panic."); GetRule(accessRule, jobject, "grant", AccessRuleType.Grant); GetRule(accessRule, jobject, "deny", AccessRuleType.Deny);