From 093d336cc7b1ef655abd3761b9b34e5352b989f9 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Tue, 15 Feb 2022 15:48:41 +0100 Subject: [PATCH] Fix more nullability errors --- .../CharacterReplacementEqualityComparer.cs | 2 +- .../Extensions/ContentExtensions.cs | 10 +++++----- .../Handlers/AuditNotificationsHandler.cs | 2 +- src/Umbraco.Core/IO/FileSystemExtensions.cs | 2 +- src/Umbraco.Core/IO/IFileProviderFactory.cs | 2 +- src/Umbraco.Core/IO/ShadowWrapper.cs | 2 +- .../Media/Exif/ExifPropertyCollection.cs | 9 ++++++--- src/Umbraco.Core/Media/Exif/ImageFile.cs | 10 +++++----- src/Umbraco.Core/Media/Exif/JPEGFile.cs | 6 +++--- .../TypeDetector/RasterizedTypeDetector.cs | 2 +- .../Media/TypeDetector/TIFFDetector.cs | 2 +- .../Models/ContentEditing/EntityBasic.cs | 3 ++- src/Umbraco.Core/Models/Entities/EntitySlim.cs | 2 +- .../Models/Entities/ITreeEntity.cs | 2 +- src/Umbraco.Core/Models/Member.cs | 12 ++++++------ .../Models/Membership/IReadOnlyUserGroup.cs | 2 +- .../Models/Membership/IUserGroup.cs | 2 +- .../Packaging/PackagesRepository.cs | 2 +- .../PropertyEditors/IDataEditor.cs | 2 +- .../PublishedCache/IPublishedCache.cs | 4 ++-- .../PublishedCache/IPublishedSnapshot.cs | 8 ++++---- .../Internal/InternalPublishedContentCache.cs | 2 +- .../Internal/InternalPublishedProperty.cs | 18 +++++++++--------- .../Internal/InternalPublishedSnapshot.cs | 10 +++++----- .../InternalPublishedSnapshotService.cs | 6 +++--- .../PublishedCache/PublishedCacheBase.cs | 4 ++-- .../Routing/ContentFinderByUrlAlias.cs | 6 +++--- .../Services/IContentServiceBase.cs | 2 +- .../Services/IMembershipMemberService.cs | 4 ++-- src/Umbraco.Core/Services/MemberService.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 1 + 31 files changed, 74 insertions(+), 69 deletions(-) diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/CharacterReplacementEqualityComparer.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/CharacterReplacementEqualityComparer.cs index a916febb93..b8049fe650 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/CharacterReplacementEqualityComparer.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/CharacterReplacementEqualityComparer.cs @@ -5,7 +5,7 @@ namespace Umbraco.Cms.Core.Configuration.UmbracoSettings { public class CharacterReplacementEqualityComparer : IEqualityComparer { - public bool Equals(IChar x, IChar y) + public bool Equals(IChar? x, IChar? y) { if (ReferenceEquals(x, y)) { diff --git a/src/Umbraco.Core/Extensions/ContentExtensions.cs b/src/Umbraco.Core/Extensions/ContentExtensions.cs index 4c574ca3c4..184957fdf4 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) @@ -181,14 +181,14 @@ namespace Umbraco.Extensions /// /// Gets the for the Creator of this content item. /// - public static IProfile GetCreatorProfile(this IContentBase content, IUserService userService) + public static IProfile? GetCreatorProfile(this IContentBase content, IUserService userService) { return userService.GetProfileById(content.CreatorId); } /// /// Gets the for the Writer of this content. /// - public static IProfile GetWriterProfile(this IContent content, IUserService userService) + public static IProfile? GetWriterProfile(this IContent content, IUserService userService) { return userService.GetProfileById(content.WriterId); } @@ -196,7 +196,7 @@ namespace Umbraco.Extensions /// /// Gets the for the Writer of this content. /// - public static IProfile GetWriterProfile(this IMedia content, IUserService userService) + public static IProfile? GetWriterProfile(this IMedia content, IUserService userService) { return userService.GetProfileById(content.WriterId); } @@ -207,7 +207,7 @@ namespace Umbraco.Extensions /// /// Gets the for the Creator of this media item. /// - public static IProfile GetCreatorProfile(this IMedia media, IUserService userService) + public static IProfile? GetCreatorProfile(this IMedia media, IUserService userService) { return userService.GetProfileById(media.CreatorId); } diff --git a/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs b/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs index 594f8aa620..0a47b0c696 100644 --- a/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs +++ b/src/Umbraco.Core/Handlers/AuditNotificationsHandler.cs @@ -231,7 +231,7 @@ namespace Umbraco.Cms.Core.Handlers _auditService.Write(performingUser.Id, $"User \"{performingUser.Name}\" {FormatEmail(performingUser)}", PerformingIp, DateTime.UtcNow, - -1, $"User Group {group.Id} \"{group.Name}\" ({group.Alias})", + -1, $"User Group {group?.Id} \"{group?.Name}\" ({group?.Alias})", "umbraco/user-group/permissions-change", $"assigning {(string.IsNullOrWhiteSpace(assigned) ? "(nothing)" : assigned)} on id:{perm.EntityId} \"{entity.Name}\""); } } diff --git a/src/Umbraco.Core/IO/FileSystemExtensions.cs b/src/Umbraco.Core/IO/FileSystemExtensions.cs index 523d8ba096..eb5edf127d 100644 --- a/src/Umbraco.Core/IO/FileSystemExtensions.cs +++ b/src/Umbraco.Core/IO/FileSystemExtensions.cs @@ -101,7 +101,7 @@ namespace Umbraco.Extensions /// /// true if the was successfully created; otherwise, false. /// - public static bool TryCreateFileProvider(this IFileSystem fileSystem, out IFileProvider fileProvider) + public static bool TryCreateFileProvider(this IFileSystem fileSystem, out IFileProvider? fileProvider) { fileProvider = fileSystem switch { diff --git a/src/Umbraco.Core/IO/IFileProviderFactory.cs b/src/Umbraco.Core/IO/IFileProviderFactory.cs index 742467ccc8..981d5558fc 100644 --- a/src/Umbraco.Core/IO/IFileProviderFactory.cs +++ b/src/Umbraco.Core/IO/IFileProviderFactory.cs @@ -13,6 +13,6 @@ namespace Umbraco.Cms.Core.IO /// /// The newly created instance (or null if not supported). /// - IFileProvider Create(); + IFileProvider? Create(); } } diff --git a/src/Umbraco.Core/IO/ShadowWrapper.cs b/src/Umbraco.Core/IO/ShadowWrapper.cs index 1b8a0a285d..829ea22bc8 100644 --- a/src/Umbraco.Core/IO/ShadowWrapper.cs +++ b/src/Umbraco.Core/IO/ShadowWrapper.cs @@ -228,6 +228,6 @@ namespace Umbraco.Cms.Core.IO } /// - public IFileProvider Create() => _innerFileSystem.TryCreateFileProvider(out IFileProvider fileProvider) ? fileProvider : null; + public IFileProvider? Create() => _innerFileSystem.TryCreateFileProvider(out IFileProvider? fileProvider) ? fileProvider : null; } } diff --git a/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs b/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs index f26a409695..cb5ffe450e 100644 --- a/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs +++ b/src/Umbraco.Core/Media/Exif/ExifPropertyCollection.cs @@ -146,10 +146,13 @@ namespace Umbraco.Cms.Core.Media.Exif Type type = value.GetType (); if (type.IsEnum) { Type etype = typeof(ExifEnumProperty<>).MakeGenericType (new Type[] { type }); - object prop = Activator.CreateInstance (etype, new object[] { key, value }); + object? prop = Activator.CreateInstance (etype, new object[] { key, value }); if (items.ContainsKey (key)) items.Remove (key); - items.Add (key, (ExifProperty)prop); + if (prop is ExifProperty exifProperty) + { + items.Add (key, exifProperty); + } } else throw new ArgumentException ("No exif property exists for this tag.", "value"); } @@ -198,7 +201,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// The to add to the collection. public void Add (ExifProperty item) { - ExifProperty oldItem = null; + ExifProperty? oldItem = null; if (items.TryGetValue (item.Tag, out oldItem)) items[item.Tag] = item; else diff --git a/src/Umbraco.Core/Media/Exif/ImageFile.cs b/src/Umbraco.Core/Media/Exif/ImageFile.cs index f2190b3e1c..cb783d3ee9 100644 --- a/src/Umbraco.Core/Media/Exif/ImageFile.cs +++ b/src/Umbraco.Core/Media/Exif/ImageFile.cs @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// /// Gets or sets the embedded thumbnail image. /// - public ImageFile Thumbnail { get; set; } + public ImageFile? Thumbnail { get; set; } /// /// Gets or sets the Exif property with the given key. /// @@ -76,7 +76,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// /// A string that contains the name of the file. /// The created from the file. - public static ImageFile FromFile (string filename) + public static ImageFile? FromFile (string filename) { return FromFile(filename, Encoding.Default); } @@ -87,7 +87,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// A string that contains the name of the file. /// The encoding to be used for text metadata when the source encoding is unknown. /// The created from the file. - public static ImageFile FromFile(string filename, Encoding encoding) + public static ImageFile? FromFile(string filename, Encoding encoding) { using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// /// A that contains image data. /// The created from the file. - public static ImageFile FromStream(Stream stream) + public static ImageFile? FromStream(Stream stream) { return FromStream(stream, Encoding.Default); } @@ -111,7 +111,7 @@ namespace Umbraco.Cms.Core.Media.Exif /// A that contains image data. /// The encoding to be used for text metadata when the source encoding is unknown. /// The created from the file. - public static ImageFile FromStream(Stream stream, Encoding encoding) + public static ImageFile? FromStream(Stream stream, Encoding encoding) { // JPEG if (JpegDetector.IsOfType(stream)) diff --git a/src/Umbraco.Core/Media/Exif/JPEGFile.cs b/src/Umbraco.Core/Media/Exif/JPEGFile.cs index 373dfbc377..61cc166184 100644 --- a/src/Umbraco.Core/Media/Exif/JPEGFile.cs +++ b/src/Umbraco.Core/Media/Exif/JPEGFile.cs @@ -11,9 +11,9 @@ namespace Umbraco.Cms.Core.Media.Exif internal class JPEGFile : ImageFile { #region Member Variables - private JPEGSection jfifApp0; - private JPEGSection jfxxApp0; - private JPEGSection exifApp1; + private JPEGSection? jfifApp0; + private JPEGSection? jfxxApp0; + private JPEGSection? exifApp1; private uint makerNoteOffset; private long exifIFDFieldOffset, gpsIFDFieldOffset, interopIFDFieldOffset, firstIFDFieldOffset; private long thumbOffsetLocation, thumbSizeLocation; diff --git a/src/Umbraco.Core/Media/TypeDetector/RasterizedTypeDetector.cs b/src/Umbraco.Core/Media/TypeDetector/RasterizedTypeDetector.cs index 4089842a00..167fbe5e0e 100644 --- a/src/Umbraco.Core/Media/TypeDetector/RasterizedTypeDetector.cs +++ b/src/Umbraco.Core/Media/TypeDetector/RasterizedTypeDetector.cs @@ -4,7 +4,7 @@ namespace Umbraco.Cms.Core.Media.TypeDetector { public abstract class RasterizedTypeDetector { - public static byte[] GetFileHeader(Stream fileStream) + public static byte[]? GetFileHeader(Stream fileStream) { fileStream.Seek(0, SeekOrigin.Begin); var header = new byte[8]; diff --git a/src/Umbraco.Core/Media/TypeDetector/TIFFDetector.cs b/src/Umbraco.Core/Media/TypeDetector/TIFFDetector.cs index 61a1a46c9c..1eda8efe7a 100644 --- a/src/Umbraco.Core/Media/TypeDetector/TIFFDetector.cs +++ b/src/Umbraco.Core/Media/TypeDetector/TIFFDetector.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Media.TypeDetector return tiffHeader != null && tiffHeader == "MM\x00\x2a" || tiffHeader == "II\x2a\x00"; } - public static string GetFileHeader(Stream fileStream) + public static string? GetFileHeader(Stream fileStream) { var header = RasterizedTypeDetector.GetFileHeader(fileStream); if (header == null) diff --git a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs index 32477f2443..166a70af13 100644 --- a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs @@ -14,11 +14,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing { AdditionalData = new Dictionary(); Alias = string.Empty; + Name = 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] diff --git a/src/Umbraco.Core/Models/Entities/EntitySlim.cs b/src/Umbraco.Core/Models/Entities/EntitySlim.cs index cdbd8d4ade..5ceaf98772 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] diff --git a/src/Umbraco.Core/Models/Entities/ITreeEntity.cs b/src/Umbraco.Core/Models/Entities/ITreeEntity.cs index f52b17512e..79264c3bf0 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. diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index 8b59980974..84dacb4a0a 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -15,8 +15,8 @@ namespace Umbraco.Cms.Core.Models public class Member : ContentBase, IMember { private IDictionary? _additionalData; - private string? _username; - private string? _email; + private string _username; + private string _email; private string? _rawPasswordValue; private string? _passwordConfig; private DateTime? _emailConfirmedDate; @@ -187,20 +187,20 @@ namespace Umbraco.Cms.Core.Models /// Gets or sets the Username /// [DataMember] - public string? Username + public string Username { get => _username; - set => SetPropertyValueAndDetectChanges(value, ref _username, nameof(Username)); + set => SetPropertyValueAndDetectChanges(value, ref _username!, nameof(Username)); } /// /// Gets or sets the Email /// [DataMember] - public string? Email + public string Email { get => _email; - set => SetPropertyValueAndDetectChanges(value, ref _email, nameof(Email)); + set => SetPropertyValueAndDetectChanges(value, ref _email!, nameof(Email)); } [DataMember] diff --git a/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs b/src/Umbraco.Core/Models/Membership/IReadOnlyUserGroup.cs index be84b4bca6..6be3736bce 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/IUserGroup.cs b/src/Umbraco.Core/Models/Membership/IUserGroup.cs index 96ae3c6dfb..10ed2455e4 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/Packaging/PackagesRepository.cs b/src/Umbraco.Core/Packaging/PackagesRepository.cs index 7223d8a30a..f022ecc396 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Core/Packaging/PackagesRepository.cs @@ -681,7 +681,7 @@ namespace Umbraco.Cms.Core.Packaging throw new ArgumentException("Value cannot be null or whitespace.", nameof(path)); } - IStylesheet stylesheet = _fileService.GetStylesheet(path); + IStylesheet? stylesheet = _fileService.GetStylesheet(path); if (stylesheet == null) { return null; diff --git a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs b/src/Umbraco.Core/PropertyEditors/IDataEditor.cs index 038aced3f3..dba30aaf60 100644 --- a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/IDataEditor.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// Gets the name of the editor. /// - string? Name { get; } + string Name { get; } /// /// Gets the icon of the editor. diff --git a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs index bdc95c9563..5cf7f58411 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// The content unique identifier. /// The content, or null. /// The value of overrides defaults. - IPublishedContent GetById(bool preview, int contentId); + IPublishedContent? GetById(bool preview, int contentId); /// /// Gets a content identified by its unique identifier. @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// The content unique identifier. /// The content, or null. /// Considers published or unpublished content depending on defaults. - IPublishedContent GetById(int contentId); + IPublishedContent? GetById(int contentId); /// /// Gets a content identified by its unique identifier. diff --git a/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs b/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs index 714de258e0..3c55b9d699 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedSnapshot.cs @@ -23,12 +23,12 @@ namespace Umbraco.Cms.Core.PublishedCache /// /// Gets the . /// - IPublishedMemberCache Members { get; } + IPublishedMemberCache? Members { get; } /// /// Gets the . /// - IDomainCache Domains { get; } + IDomainCache? Domains { get; } /// /// Gets the snapshot-level cache. @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// /// The snapshot-level cache belongs to this snapshot only. /// - IAppCache SnapshotCache { get; } + IAppCache? SnapshotCache { get; } /// /// Gets the elements-level cache. @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// The elements-level cache is shared by all snapshots relying on the same elements, /// ie all snapshots built on top of unchanging content / media / etc. /// - IAppCache ElementsCache { get; } + IAppCache? ElementsCache { get; } /// /// Forces the preview mode. diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs index dcf05641f1..abeb19e4ec 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs @@ -30,7 +30,7 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal public string GetRouteById(int contentId, string? culture = null) => throw new NotImplementedException(); - public override IPublishedContent GetById(bool preview, int contentId) => _content.ContainsKey(contentId) ? _content[contentId] : null; + public override IPublishedContent? GetById(bool preview, int contentId) => _content.ContainsKey(contentId) ? _content[contentId] : null; public override IPublishedContent GetById(bool preview, Guid contentId) => throw new NotImplementedException(); diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs index 21b426aa29..07d25d7f9a 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs @@ -7,24 +7,24 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal [EditorBrowsable(EditorBrowsableState.Never)] public class InternalPublishedProperty : IPublishedProperty { - public IPublishedPropertyType PropertyType { get; set; } + public IPublishedPropertyType? PropertyType { get; set; } - public string Alias { get; set; } + public string Alias { get; set; } = string.Empty; - public object SolidSourceValue { get; set; } + public object? SolidSourceValue { get; set; } - public object SolidValue { get; set; } + public object? SolidValue { get; set; } public bool SolidHasValue { get; set; } - public object SolidXPathValue { get; set; } + public object? SolidXPathValue { get; set; } - public virtual object GetSourceValue(string culture = null, string? segment = null) => SolidSourceValue; + public virtual object? GetSourceValue(string? culture = null, string? segment = null) => SolidSourceValue; - public virtual object GetValue(string culture = null, string? segment = null) => SolidValue; + public virtual object? GetValue(string? culture = null, string? segment = null) => SolidValue; - public virtual object GetXPathValue(string culture = null, string? segment = null) => SolidXPathValue; + public virtual object? GetXPathValue(string? culture = null, string? segment = null) => SolidXPathValue; - public virtual bool HasValue(string culture = null, string? segment = null) => SolidHasValue; + public virtual bool HasValue(string? culture = null, string? segment = null) => SolidHasValue; } } diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs index 1ff8d99139..0516edc47b 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshot.cs @@ -16,19 +16,19 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal public IPublishedMediaCache Media => InnerMediaCache; - public IPublishedMemberCache Members => null; + public IPublishedMemberCache? Members => null; - public IDomainCache Domains => null; + public IDomainCache? Domains => null; - public IDisposable ForcedPreview(bool forcedPreview, Action callback = null) => throw new NotImplementedException(); + public IDisposable ForcedPreview(bool forcedPreview, Action? callback = null) => throw new NotImplementedException(); public void Resync() { } - public IAppCache SnapshotCache => null; + public IAppCache? SnapshotCache => null; - public IAppCache ElementsCache => null; + public IAppCache? ElementsCache => null; public void Dispose() { diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs index 61e2a9c2a9..cc080a0f44 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedSnapshotService.cs @@ -10,8 +10,8 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal [EditorBrowsable(EditorBrowsableState.Never)] public class InternalPublishedSnapshotService : IPublishedSnapshotService { - private InternalPublishedSnapshot _snapshot; - private InternalPublishedSnapshot _previewSnapshot; + private InternalPublishedSnapshot? _snapshot; + private InternalPublishedSnapshot? _previewSnapshot; public Task CollectAsync() => Task.CompletedTask; @@ -56,7 +56,7 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal { } - public void Rebuild(IReadOnlyCollection contentTypeIds = null, IReadOnlyCollection mediaTypeIds = null, IReadOnlyCollection memberTypeIds = null) + public void Rebuild(IReadOnlyCollection? contentTypeIds = null, IReadOnlyCollection? mediaTypeIds = null, IReadOnlyCollection? memberTypeIds = null) { } } diff --git a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs index 9ffa3bb447..379668a832 100644 --- a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs +++ b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs @@ -24,9 +24,9 @@ namespace Umbraco.Cms.Core.PublishedCache PreviewDefault = previewDefault; } - public abstract IPublishedContent GetById(bool preview, int contentId); + public abstract IPublishedContent? GetById(bool preview, int contentId); - public IPublishedContent GetById(int contentId) + public IPublishedContent? GetById(int contentId) => GetById(PreviewDefault, contentId); public abstract IPublishedContent GetById(bool preview, Guid contentId); diff --git a/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs b/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs index 6c1e9198de..5d9ac79c81 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByUrlAlias.cs @@ -102,9 +102,9 @@ namespace Umbraco.Cms.Core.Routing } IPublishedProperty? p = c.GetProperty(propertyAlias); - var varies = p!.PropertyType.VariesByCulture(); + var varies = p!.PropertyType?.VariesByCulture(); string? v; - if (varies) + if (varies ?? false) { if (!c.HasCulture(culture)) { @@ -131,7 +131,7 @@ namespace Umbraco.Cms.Core.Routing // but the only solution is to entirely refactor URL providers to stop being dynamic if (rootNodeId > 0) { - IPublishedContent rootNode = cache.GetById(rootNodeId); + IPublishedContent? rootNode = cache.GetById(rootNodeId); return rootNode?.Descendants(_variationContextAccessor).FirstOrDefault(x => IsMatch(x, test1, test2)); } diff --git a/src/Umbraco.Core/Services/IContentServiceBase.cs b/src/Umbraco.Core/Services/IContentServiceBase.cs index 86689807c4..1916fb49c4 100644 --- a/src/Umbraco.Core/Services/IContentServiceBase.cs +++ b/src/Umbraco.Core/Services/IContentServiceBase.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Services public interface IContentServiceBase : IContentServiceBase where TItem: class, IContentBase { - IContent? GetById(Guid key); + TItem? GetById(Guid key); Attempt Save(IEnumerable contents, int userId = Constants.Security.SuperUserId); } diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs index 828751e7e6..48900752e2 100644 --- a/src/Umbraco.Core/Services/IMembershipMemberService.cs +++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs @@ -83,7 +83,7 @@ namespace Umbraco.Cms.Core.Services /// An can be of type or /// Id to use for retrieval /// - IUser? GetByProviderKey(object id); + T? GetByProviderKey(object id); /// /// Get an by email @@ -91,7 +91,7 @@ namespace Umbraco.Cms.Core.Services /// An can be of type or /// Email to use for retrieval /// - IUser? GetByEmail(string email); + T? GetByEmail(string email); /// /// Get an by username diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs index 0b8d981143..bf0d326a32 100644 --- a/src/Umbraco.Core/Services/MemberService.cs +++ b/src/Umbraco.Core/Services/MemberService.cs @@ -359,7 +359,7 @@ namespace Umbraco.Cms.Core.Services /// /// Id to use for retrieval /// - public IMember GetByProviderKey(object id) + public IMember? GetByProviderKey(object id) { var asGuid = id.TryConvertTo(); if (asGuid.Success) diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 26fce6f2bb..8bad0b4f43 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -9,6 +9,7 @@ Contains the core assembly needed to run Umbraco Cms. This package only contains the assembly, and can be used for package development. Use the template in the Umbraco.Templates package to setup Umbraco Umbraco CMS enable + Nullable