From 2ec92057c520377700d5d7a3fba099463f10c854 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 16 Dec 2021 13:44:20 +0100 Subject: [PATCH] Started using nullable reference types.. --- src/Umbraco.Core/Actions/ActionCollection.cs | 2 +- src/Umbraco.Core/Actions/ActionRestore.cs | 2 +- src/Umbraco.Core/Actions/IAction.cs | 2 +- src/Umbraco.Core/Cache/AppCacheExtensions.cs | 12 +- .../Cache/AppPolicedCacheDictionary.cs | 1 + .../Cache/CacheRefresherCollection.cs | 2 +- src/Umbraco.Core/Cache/DeepCloneAppCache.cs | 14 +- src/Umbraco.Core/Cache/DictionaryAppCache.cs | 16 +- src/Umbraco.Core/Cache/DistributedCache.cs | 2 +- .../Cache/FastDictionaryAppCache.cs | 12 +- .../Cache/FastDictionaryAppCacheBase.cs | 24 +-- src/Umbraco.Core/Cache/IAppCache.cs | 8 +- src/Umbraco.Core/Cache/IAppPolicyCache.cs | 10 +- .../Cache/IRepositoryCachePolicy.cs | 6 +- src/Umbraco.Core/Cache/IRequestCache.cs | 2 +- .../Cache/MemberCacheRefresher.cs | 4 +- src/Umbraco.Core/Cache/NoAppCache.cs | 10 +- .../Cache/NoCacheRepositoryCachePolicy.cs | 4 +- src/Umbraco.Core/Cache/ObjectCacheAppCache.cs | 32 ++-- .../Cache/RepositoryCachePolicyOptions.cs | 2 +- src/Umbraco.Core/Cache/SafeLazy.cs | 6 +- src/Umbraco.Core/Cache/ValueEditorCache.cs | 5 +- .../UmbracoObjectTypeAttribute.cs | 2 +- .../Collections/CompositeIntStringKey.cs | 2 +- .../Collections/CompositeNStringNStringKey.cs | 2 +- .../Collections/CompositeStringStringKey.cs | 2 +- .../Collections/CompositeTypeTypeKey.cs | 2 +- .../Collections/ConcurrentHashSet.cs | 2 +- .../Collections/DeepCloneableList.cs | 2 +- .../EventClearingObservableCollection.cs | 4 +- .../Collections/ObservableDictionary.cs | 15 +- .../Collections/OrderedHashSet.cs | 2 +- src/Umbraco.Core/Collections/StackQueue.cs | 28 ++-- src/Umbraco.Core/Collections/TopoGraph.cs | 4 +- .../Composing/CollectionBuilderBase.cs | 2 +- .../Composing/ComponentCollectionBuilder.cs | 10 +- src/Umbraco.Core/Composing/ComposerGraph.cs | 22 +-- .../DefaultUmbracoAssemblyProvider.cs | 6 +- .../Composing/DisableAttribute.cs | 2 +- src/Umbraco.Core/Composing/EnableAttribute.cs | 2 +- src/Umbraco.Core/Composing/ITypeFinder.cs | 6 +- .../Composing/LazyReadOnlyCollection.cs | 2 +- .../Composing/ReferenceResolver.cs | 2 +- src/Umbraco.Core/Composing/RuntimeHash.cs | 2 +- src/Umbraco.Core/Composing/TypeFinder.cs | 24 +-- .../Composing/TypeFinderConfig.cs | 2 +- .../Composing/TypeFinderExtensions.cs | 6 +- src/Umbraco.Core/Composing/TypeLoader.cs | 61 ++++---- .../Configuration/ConfigConnectionString.cs | 12 +- .../ContentSettingsExtensions.cs | 2 +- .../Configuration/GlobalSettingsExtensions.cs | 4 +- .../Configuration/Grid/GridEditorsConfig.cs | 2 +- .../Models/ActiveDirectorySettings.cs | 2 +- .../Configuration/Models/ConnectionStrings.cs | 2 +- .../Configuration/Models/ContentErrorPage.cs | 4 +- .../Models/ContentNotificationSettings.cs | 2 +- .../Configuration/Models/GlobalSettings.cs | 4 +- .../Configuration/Models/HostingSettings.cs | 4 +- .../Models/ImagingAutoFillUploadField.cs | 10 +- .../Models/RequestHandlerSettings.cs | 7 +- .../Models/RichTextEditorSettings.cs | 10 +- .../Models/RuntimeMinificationSettings.cs | 4 +- .../Configuration/Models/SecuritySettings.cs | 6 +- .../Configuration/Models/SmtpSettings.cs | 10 +- .../Models/TypeFinderSettings.cs | 6 +- .../Models/UnattendedSettings.cs | 6 +- .../Validation/ConfigurationValidatorBase.cs | 2 +- .../Validation/GlobalSettingsValidator.cs | 2 +- .../Models/WebRoutingSettings.cs | 2 +- .../ModelsBuilderConfigExtensions.cs | 2 +- .../ContentAppFactoryCollection.cs | 6 +- .../ContentEditorContentAppFactory.cs | 8 +- .../ContentInfoContentAppFactory.cs | 20 +-- .../ContentTypeDesignContentAppFactory.cs | 8 +- .../ContentTypeListViewContentAppFactory.cs | 8 +- ...ContentTypePermissionsContentAppFactory.cs | 8 +- .../ContentTypeTemplatesContentAppFactory.cs | 8 +- .../ContentApps/ListViewContentAppFactory.cs | 2 +- .../MemberEditorContentAppFactory.cs | 4 +- src/Umbraco.Core/Dashboards/AccessRule.cs | 5 +- src/Umbraco.Core/Dashboards/DashboardSlim.cs | 4 +- src/Umbraco.Core/Dashboards/IAccessRule.cs | 2 +- src/Umbraco.Core/Dashboards/IDashboardSlim.cs | 4 +- .../DependencyInjection/IUmbracoBuilder.cs | 2 +- .../StaticServiceProvider.cs | 2 +- .../DependencyInjection/UmbracoBuilder.cs | 4 +- .../UniqueServiceDescriptor.cs | 8 +- src/Umbraco.Core/Deploy/ArtifactBase.cs | 8 +- .../Deploy/ArtifactDeployState.cs | 6 +- .../ArtifactDeployStateOfTArtifactTEntity.cs | 6 +- src/Umbraco.Core/Deploy/ArtifactSignature.cs | 2 +- src/Umbraco.Core/Deploy/Difference.cs | 6 +- src/Umbraco.Core/Deploy/IArtifact.cs | 2 +- src/Umbraco.Core/Deploy/IArtifactSignature.cs | 2 +- src/Umbraco.Core/Deploy/IServiceConnector.cs | 2 +- .../Editors/UserEditorAuthorizationHelper.cs | 2 +- src/Umbraco.Core/Enum.cs | 2 +- src/Umbraco.Core/Events/EventDefinition.cs | 2 +- .../Events/EventDefinitionBase.cs | 4 +- src/Umbraco.Core/Events/IEventDispatcher.cs | 12 +- .../Extensions/ContentExtensions.cs | 26 ++-- .../Extensions/DataTableExtensions.cs | 18 +-- .../Extensions/DictionaryExtensions.cs | 18 +-- .../Extensions/EnumerableExtensions.cs | 4 +- src/Umbraco.Core/Extensions/IfExtensions.cs | 13 +- .../Extensions/ObjectExtensions.cs | 2 +- .../Extensions/PublishedContentExtensions.cs | 143 ++++++++++-------- .../Extensions/PublishedElementExtensions.cs | 8 +- .../Extensions/PublishedPropertyExtension.cs | 4 +- .../Extensions/StringExtensions.cs | 2 +- src/Umbraco.Core/GuidUdi.cs | 4 +- src/Umbraco.Core/HashCodeHelper.cs | 18 +-- src/Umbraco.Core/HybridAccessorBase.cs | 10 +- .../HybridEventMessagesAccessor.cs | 3 +- src/Umbraco.Core/IO/MediaFileManager.cs | 20 +-- .../Install/InstallStatusTracker.cs | 2 +- .../Models/InstallProgressResultModel.cs | 6 +- src/Umbraco.Core/Models/Content.cs | 12 +- src/Umbraco.Core/Models/ContentBase.cs | 12 +- .../Models/ContentBaseExtensions.cs | 4 +- .../ContentEditing/ContentPropertyBasic.cs | 12 +- .../ContentEditing/IContentAppFactory.cs | 2 +- .../Models/ContentTagsExtensions.cs | 4 +- src/Umbraco.Core/Models/IContentBase.cs | 6 +- src/Umbraco.Core/Models/IDataValueEditor.cs | 2 +- src/Umbraco.Core/Models/IProperty.cs | 4 +- src/Umbraco.Core/Models/Property.cs | 4 +- .../Models/PropertyTagsExtensions.cs | 8 +- .../PublishedContent/IPublishedProperty.cs | 8 +- .../IPublishedValueFallback.cs | 12 +- .../PublishedContent/PublishedPropertyBase.cs | 8 +- .../PublishedContent/RawValueProperty.cs | 8 +- .../PublishedContent/VariationContext.cs | 2 +- .../Repositories/ITagRepository.cs | 14 +- .../Repositories/RepositoryCacheKeys.cs | 6 +- .../PropertyEditors/DataValueEditor.cs | 2 +- .../PropertyEditors/DateValueEditor.cs | 2 +- .../PropertyEditors/TextOnlyValueEditor.cs | 2 +- .../PublishedCache/IPublishedCache.cs | 2 +- .../PublishedCache/IPublishedContentCache.cs | 8 +- src/Umbraco.Core/PublishedCache/ITagQuery.cs | 20 +-- .../Internal/InternalPublishedContentCache.cs | 10 +- .../Internal/InternalPublishedProperty.cs | 8 +- .../PublishedCache/PublishedCacheBase.cs | 2 +- .../PublishedElementPropertyBase.cs | 8 +- src/Umbraco.Core/Routing/DomainUtilities.cs | 4 +- .../Routing/IPublishedUrlProvider.cs | 10 +- src/Umbraco.Core/Routing/UrlInfo.cs | 4 +- src/Umbraco.Core/Routing/UrlProvider.cs | 10 +- .../Services/ContentTypeServiceExtensions.cs | 4 +- .../Services/IContentVersionService.cs | 2 +- .../Services/IEntityXmlSerializer.cs | 2 +- .../Services/IRedirectUrlService.cs | 2 +- src/Umbraco.Core/Services/ITagService.cs | 28 ++-- src/Umbraco.Core/Services/Ordering.cs | 4 +- .../Strings/DefaultUrlSegmentProvider.cs | 2 +- .../Strings/IUrlSegmentProvider.cs | 2 +- src/Umbraco.Core/UdiParser.cs | 17 +-- src/Umbraco.Core/UdiRange.cs | 5 +- src/Umbraco.Core/Umbraco.Core.csproj | 4 +- src/Umbraco.Core/UriUtilityCore.cs | 2 +- .../Migrations/Install/DatabaseBuilder.cs | 2 +- .../PublishedElementExtensions.cs | 2 +- .../Repositories/Implement/TagRepository.cs | 6 +- .../BlockEditorPropertyEditor.cs | 2 +- .../PropertyEditors/GridPropertyEditor.cs | 2 +- .../ImageCropperPropertyValueEditor.cs | 2 +- .../MediaPicker3PropertyEditor.cs | 2 +- .../MultiUrlPickerValueEditor.cs | 2 +- .../MultipleTextStringPropertyEditor.cs | 2 +- .../PropertyEditors/MultipleValueEditor.cs | 2 +- .../NestedContentPropertyEditor.cs | 2 +- .../PropertyEditors/RichTextPropertyEditor.cs | 2 +- .../Search/UmbracoTreeSearcher.cs | 4 +- .../Implement/ContentVersionService.cs | 2 +- .../Services/Implement/RedirectUrlService.cs | 2 +- .../Services/Implement/TagService.cs | 28 ++-- src/Umbraco.Infrastructure/TagQuery.cs | 20 +-- .../ContentCache.cs | 8 +- .../MediaCache.cs | 2 +- .../Property.cs | 8 +- .../Controllers/ContentController.cs | 6 +- .../Controllers/EntityController.cs | 6 +- .../Cache/HttpContextRequestAppCache.cs | 4 +- .../FriendlyPublishedContentExtensions.cs | 80 +++++----- .../FriendlyPublishedElementExtensions.cs | 4 +- .../Umbraco.TestData/SegmentTestController.cs | 2 +- .../Builders/ContentBuilder.cs | 4 +- .../Builders/Extensions/BuilderExtensions.cs | 2 +- .../Builders/PropertyDataBuilder.cs | 2 +- .../Extensions/ContentBaseExtensions.cs | 2 +- .../Published/NestedContentTests.cs | 8 +- 192 files changed, 752 insertions(+), 723 deletions(-) diff --git a/src/Umbraco.Core/Actions/ActionCollection.cs b/src/Umbraco.Core/Actions/ActionCollection.cs index 841f71b988..1e396952a2 100644 --- a/src/Umbraco.Core/Actions/ActionCollection.cs +++ b/src/Umbraco.Core/Actions/ActionCollection.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Actions /// /// The specified type to get /// The action - public T GetAction() + public T? GetAction() where T : IAction => this.OfType().FirstOrDefault(); /// diff --git a/src/Umbraco.Core/Actions/ActionRestore.cs b/src/Umbraco.Core/Actions/ActionRestore.cs index dc844dd818..164c93e2d5 100644 --- a/src/Umbraco.Core/Actions/ActionRestore.cs +++ b/src/Umbraco.Core/Actions/ActionRestore.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.Actions public string Alias => ActionAlias; /// - public string Category => null; + public string? Category => null; /// public string Icon => "undo"; diff --git a/src/Umbraco.Core/Actions/IAction.cs b/src/Umbraco.Core/Actions/IAction.cs index 8178b3a557..2d9876afc6 100644 --- a/src/Umbraco.Core/Actions/IAction.cs +++ b/src/Umbraco.Core/Actions/IAction.cs @@ -44,6 +44,6 @@ namespace Umbraco.Cms.Core.Actions /// /// Used in the UI when assigning permissions /// - string Category { get; } + string? Category { get; } } } diff --git a/src/Umbraco.Core/Cache/AppCacheExtensions.cs b/src/Umbraco.Core/Cache/AppCacheExtensions.cs index 7e6e115fd9..dfb0a7ae72 100644 --- a/src/Umbraco.Core/Cache/AppCacheExtensions.cs +++ b/src/Umbraco.Core/Cache/AppCacheExtensions.cs @@ -10,12 +10,12 @@ namespace Umbraco.Extensions /// public static class AppCacheExtensions { - public static T GetCacheItem(this IAppPolicyCache provider, + public static T? GetCacheItem(this IAppPolicyCache provider, string cacheKey, - Func getCacheItem, + Func getCacheItem, TimeSpan? timeout, bool isSliding = false, - string[] dependentFiles = null) + string[]? dependentFiles = null) { var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); return result == null ? default(T) : result.TryConvertTo().Result; @@ -26,7 +26,7 @@ namespace Umbraco.Extensions Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, - string[] dependentFiles = null) + string[]? dependentFiles = null) { provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, dependentFiles); } @@ -43,7 +43,7 @@ namespace Umbraco.Extensions return result.Select(x => x.TryConvertTo().Result); } - public static T GetCacheItem(this IAppCache provider, string cacheKey) + public static T? GetCacheItem(this IAppCache provider, string cacheKey) { var result = provider.Get(cacheKey); if (result == null) @@ -53,7 +53,7 @@ namespace Umbraco.Extensions return result.TryConvertTo().Result; } - public static T GetCacheItem(this IAppCache provider, string cacheKey, Func getCacheItem) + public static T? GetCacheItem(this IAppCache provider, string cacheKey, Func getCacheItem) { var result = provider.Get(cacheKey, () => getCacheItem()); if (result == null) diff --git a/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs b/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs index af7c1db228..8239ee4abf 100644 --- a/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs +++ b/src/Umbraco.Core/Cache/AppPolicedCacheDictionary.cs @@ -9,6 +9,7 @@ namespace Umbraco.Cms.Core.Cache /// /// The type of the dictionary key. public abstract class AppPolicedCacheDictionary : IDisposable + where TKey : notnull { private readonly ConcurrentDictionary _caches = new ConcurrentDictionary(); diff --git a/src/Umbraco.Core/Cache/CacheRefresherCollection.cs b/src/Umbraco.Core/Cache/CacheRefresherCollection.cs index a61dd81368..b9dc7f5984 100644 --- a/src/Umbraco.Core/Cache/CacheRefresherCollection.cs +++ b/src/Umbraco.Core/Cache/CacheRefresherCollection.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Cache { } - public ICacheRefresher this[Guid id] + public ICacheRefresher? this[Guid id] => this.FirstOrDefault(x => x.RefresherUniqueId == id); } } diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs index be8bf7bdec..60a0d8d7b3 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs @@ -35,14 +35,14 @@ namespace Umbraco.Cms.Core.Cache private IAppPolicyCache InnerCache { get; } /// - public object Get(string key) + public object? Get(string key) { var item = InnerCache.Get(key); return CheckCloneableAndTracksChanges(item); } /// - public object Get(string key, Func factory) + public object? Get(string key, Func factory) { var cached = InnerCache.Get(key, () => { @@ -55,21 +55,21 @@ namespace Umbraco.Cms.Core.Cache } /// - public IEnumerable SearchByKey(string keyStartsWith) + public IEnumerable SearchByKey(string keyStartsWith) { return InnerCache.SearchByKey(keyStartsWith) .Select(CheckCloneableAndTracksChanges); } /// - public IEnumerable SearchByRegex(string regex) + public IEnumerable SearchByRegex(string regex) { return InnerCache.SearchByRegex(regex) .Select(CheckCloneableAndTracksChanges); } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) + public object? Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[]? dependentFiles = null) { var cached = InnerCache.Get(key, () => { @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[]? dependentFiles = null) { InnerCache.Insert(key, () => { @@ -139,7 +139,7 @@ namespace Umbraco.Cms.Core.Cache InnerCache.ClearByRegex(regex); } - private static object CheckCloneableAndTracksChanges(object input) + private static object? CheckCloneableAndTracksChanges(object? input) { if (input is IDeepCloneable cloneable) { diff --git a/src/Umbraco.Core/Cache/DictionaryAppCache.cs b/src/Umbraco.Core/Cache/DictionaryAppCache.cs index 8857da0187..f6c733d1cc 100644 --- a/src/Umbraco.Core/Cache/DictionaryAppCache.cs +++ b/src/Umbraco.Core/Cache/DictionaryAppCache.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Cache /// /// Gets the internal items dictionary, for tests only! /// - private readonly ConcurrentDictionary _items = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _items = new ConcurrentDictionary(); public int Count => _items.Count; @@ -23,13 +23,13 @@ namespace Umbraco.Cms.Core.Cache public bool IsAvailable => true; /// - public virtual object Get(string key) + public virtual object? Get(string key) { return _items.TryGetValue(key, out var value) ? value : null; } /// - public virtual object Get(string key, Func factory) + public virtual object? Get(string key, Func factory) { return _items.GetOrAdd(key, _ => factory()); } @@ -39,9 +39,9 @@ namespace Umbraco.Cms.Core.Cache public bool Remove(string key) => _items.TryRemove(key, out _); /// - public virtual IEnumerable SearchByKey(string keyStartsWith) + public virtual IEnumerable SearchByKey(string keyStartsWith) { - var items = new List(); + var items = new List(); foreach (var (key, value) in _items) if (key.InvariantStartsWith(keyStartsWith)) items.Add(value); @@ -49,10 +49,10 @@ namespace Umbraco.Cms.Core.Cache } /// - public IEnumerable SearchByRegex(string regex) + public IEnumerable SearchByRegex(string regex) { var compiled = new Regex(regex, RegexOptions.Compiled); - var items = new List(); + var items = new List(); foreach (var (key, value) in _items) if (compiled.IsMatch(key)) items.Add(value); @@ -104,7 +104,7 @@ namespace Umbraco.Cms.Core.Cache _items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); } - public IEnumerator> GetEnumerator() => _items.GetEnumerator(); + public IEnumerator> GetEnumerator() => _items.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } diff --git a/src/Umbraco.Core/Cache/DistributedCache.cs b/src/Umbraco.Core/Cache/DistributedCache.cs index bfd1162bc4..95c17b946d 100644 --- a/src/Umbraco.Core/Cache/DistributedCache.cs +++ b/src/Umbraco.Core/Cache/DistributedCache.cs @@ -164,7 +164,7 @@ namespace Umbraco.Cms.Core.Cache // helper method to get an ICacheRefresher by its unique identifier private ICacheRefresher GetRefresherById(Guid refresherGuid) { - ICacheRefresher refresher = _cacheRefreshers[refresherGuid]; + ICacheRefresher? refresher = _cacheRefreshers[refresherGuid]; if (refresher == null) { throw new InvalidOperationException($"No cache refresher found with id {refresherGuid}"); diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs index 670574896e..6c3b8855d2 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCache.cs @@ -16,21 +16,21 @@ namespace Umbraco.Cms.Core.Cache /// /// Gets the internal items dictionary, for tests only! /// - private readonly ConcurrentDictionary> _items = new ConcurrentDictionary>(); + private readonly ConcurrentDictionary> _items = new ConcurrentDictionary>(); public IEnumerable Keys => _items.Keys; public int Count => _items.Count; /// - public object Get(string cacheKey) + public object? Get(string cacheKey) { _items.TryGetValue(cacheKey, out var result); // else null - return result == null ? null : SafeLazy.GetSafeLazyValue(result); // return exceptions as null + return result == null ? null : SafeLazy.GetSafeLazyValue(result!); // return exceptions as null } /// - public object Get(string cacheKey, Func getCacheItem) + public object? Get(string cacheKey, Func getCacheItem) { var result = _items.GetOrAdd(cacheKey, k => SafeLazy.GetSafeLazy(getCacheItem)); @@ -48,7 +48,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public IEnumerable SearchByKey(string keyStartsWith) + public IEnumerable SearchByKey(string keyStartsWith) { return _items .Where(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)) @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public IEnumerable SearchByRegex(string regex) + public IEnumerable SearchByRegex(string regex) { var compiled = new Regex(regex, RegexOptions.Compiled); return _items diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs index 9eaf5fb833..940876dc75 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs @@ -17,14 +17,14 @@ namespace Umbraco.Cms.Core.Cache #region IAppCache /// - public virtual object Get(string key) + public virtual object? Get(string key) { key = GetCacheKey(key); - Lazy result; + Lazy? result; try { EnterReadLock(); - result = GetEntry(key) as Lazy; // null if key not found + result = GetEntry(key) as Lazy; // null if key not found } finally { @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public abstract object Get(string key, Func factory); + public abstract object Get(string key, Func factory); /// public virtual IEnumerable SearchByKey(string keyStartsWith) @@ -54,12 +54,12 @@ namespace Umbraco.Cms.Core.Cache } return entries - .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null - .Where(x => x != null); // backward compat, don't store null values in the cache + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Where(x => x != null)!; // backward compat, don't store null values in the cache } /// - public virtual IEnumerable SearchByRegex(string regex) + public virtual IEnumerable SearchByRegex(string regex) { const string prefix = CacheItemPrefix + "-"; var compiled = new Regex(regex, RegexOptions.Compiled); @@ -77,7 +77,7 @@ namespace Umbraco.Cms.Core.Cache ExitReadLock(); } return entries - .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue( (Lazy)x.Value)) // return exceptions as null .Where(x => x != null); // backward compatible, don't store null values in the cache } @@ -127,7 +127,7 @@ namespace Umbraco.Cms.Core.Cache // entry.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -159,7 +159,7 @@ namespace Umbraco.Cms.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -192,7 +192,7 @@ namespace Umbraco.Cms.Core.Cache // remove null values as well, does not hurt // compare on exact type, don't use "is" // get non-created as NonCreatedValue & exceptions as null - var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy) x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface @@ -261,7 +261,7 @@ namespace Umbraco.Cms.Core.Cache // and use the full prefixed cache keys protected abstract IEnumerable> GetDictionaryEntries(); protected abstract void RemoveEntry(string key); - protected abstract object GetEntry(string key); + protected abstract object? GetEntry(string key); // read-write lock the underlying cache //protected abstract IDisposable ReadLock { get; } diff --git a/src/Umbraco.Core/Cache/IAppCache.cs b/src/Umbraco.Core/Cache/IAppCache.cs index 9b9b03af35..81cfc2e114 100644 --- a/src/Umbraco.Core/Cache/IAppCache.cs +++ b/src/Umbraco.Core/Cache/IAppCache.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Cache /// /// The key of the item. /// The item, or null if the item was not found. - object Get(string key); + object? Get(string key); /// /// Gets or creates an item identified by its key. @@ -21,21 +21,21 @@ namespace Umbraco.Cms.Core.Cache /// The key of the item. /// A factory function that can create the item. /// The item. - object Get(string key, Func factory); + object? Get(string key, Func factory); /// /// Gets items with a key starting with the specified value. /// /// The StartsWith value to use in the search. /// Items matching the search. - IEnumerable SearchByKey(string keyStartsWith); + IEnumerable SearchByKey(string keyStartsWith); /// /// Gets items with a key matching a regular expression. /// /// The regular expression. /// Items matching the search. - IEnumerable SearchByRegex(string regex); + IEnumerable SearchByRegex(string regex); /// /// Removes all items from the cache. diff --git a/src/Umbraco.Core/Cache/IAppPolicyCache.cs b/src/Umbraco.Core/Cache/IAppPolicyCache.cs index a345ca1333..ec59bf390b 100644 --- a/src/Umbraco.Core/Cache/IAppPolicyCache.cs +++ b/src/Umbraco.Core/Cache/IAppPolicyCache.cs @@ -18,12 +18,12 @@ namespace Umbraco.Cms.Core.Cache /// An optional value indicating whether the cache timeout is sliding (default is false). /// Files the cache entry depends on. /// The item. - object Get( + object? Get( string key, - Func factory, + Func factory, TimeSpan? timeout, bool isSliding = false, - string[] dependentFiles = null); + string[]? dependentFiles = null); /// /// Inserts an item. @@ -35,9 +35,9 @@ namespace Umbraco.Cms.Core.Cache /// Files the cache entry depends on. void Insert( string key, - Func factory, + Func factory, TimeSpan? timeout = null, bool isSliding = false, - string[] dependentFiles = null); + string[]? dependentFiles = null); } } diff --git a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs index dff547c1ce..c167181be0 100644 --- a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Cache /// The repository PerformGetAll method. /// The entity with the specified identifier, if it exits, else null. /// First considers the cache then the repository. - TEntity Get(TId id, Func performGet, Func> performGetAll); + TEntity? Get(TId id, Func performGet, Func> performGetAll); /// /// Gets an entity from the cache. @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Core.Cache /// The identifier. /// The entity with the specified identifier, if it is in the cache already, else null. /// Does not consider the repository at all. - TEntity GetCached(TId id); + TEntity? GetCached(TId id); /// /// Gets a value indicating whether an entity with a specified identifier exists. @@ -66,7 +66,7 @@ namespace Umbraco.Cms.Core.Cache /// The repository PerformGetAll method. /// If is empty, all entities, else the entities with the specified identifiers. /// Get all the entities. Either from the cache or the repository depending on the implementation. - TEntity[] GetAll(TId[] ids, Func> performGetAll); + TEntity?[] GetAll(TId[] ids, Func> performGetAll); /// /// Clears the entire cache. diff --git a/src/Umbraco.Core/Cache/IRequestCache.cs b/src/Umbraco.Core/Cache/IRequestCache.cs index 1da08019c0..fa69725dcd 100644 --- a/src/Umbraco.Core/Cache/IRequestCache.cs +++ b/src/Umbraco.Core/Cache/IRequestCache.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; namespace Umbraco.Cms.Core.Cache { - public interface IRequestCache : IAppCache, IEnumerable> + public interface IRequestCache : IAppCache, IEnumerable> { bool Set(string key, object value); bool Remove(string key); diff --git a/src/Umbraco.Core/Cache/MemberCacheRefresher.cs b/src/Umbraco.Core/Cache/MemberCacheRefresher.cs index 4f199389d6..af073706ed 100644 --- a/src/Umbraco.Core/Cache/MemberCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/MemberCacheRefresher.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.Cache public class JsonPayload { //[JsonConstructor] - public JsonPayload(int id, string username, bool removed) + public JsonPayload(int id, string? username, bool removed) { Id = id; Username = username; @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Core.Cache } public int Id { get; } - public string Username { get; } + public string? Username { get; } public bool Removed { get; } } diff --git a/src/Umbraco.Core/Cache/NoAppCache.cs b/src/Umbraco.Core/Cache/NoAppCache.cs index 475e67b94a..759d8af9e1 100644 --- a/src/Umbraco.Core/Cache/NoAppCache.cs +++ b/src/Umbraco.Core/Cache/NoAppCache.cs @@ -21,13 +21,13 @@ namespace Umbraco.Cms.Core.Cache public bool IsAvailable => false; /// - public virtual object Get(string cacheKey) + public virtual object? Get(string cacheKey) { return null; } /// - public virtual object Get(string cacheKey, Func factory) + public virtual object? Get(string cacheKey, Func factory) { return factory(); } @@ -49,13 +49,13 @@ namespace Umbraco.Cms.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) + public object? Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[]? dependentFiles = null) { return factory(); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[]? dependentFiles = null) { } /// @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Cache public virtual void ClearByRegex(string regex) { } - public IEnumerator> GetEnumerator() => new Dictionary().GetEnumerator(); + public IEnumerator> GetEnumerator() => new Dictionary().GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } diff --git a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs index 48aab0a5ee..7c912d5c22 100644 --- a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Cache return performGet(id); } - public TEntity GetCached(TId id) + public TEntity? GetCached(TId id) { return null; } @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Core.Cache persistDeleted(entity); } - public TEntity[] GetAll(TId[] ids, Func> performGetAll) + public TEntity?[] GetAll(TId[] ids, Func> performGetAll) { return performGetAll(ids).ToArray(); } diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index a848e7cb30..4ec91c4933 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -33,13 +33,13 @@ namespace Umbraco.Cms.Core.Cache public ObjectCache MemoryCache { get; private set; } /// - public object Get(string key) + public object? Get(string key) { - Lazy result; + Lazy? result; try { _locker.EnterReadLock(); - result = MemoryCache.Get(key) as Lazy; // null if key not found + result = MemoryCache.Get(key) as Lazy; // null if key not found } finally { @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public object Get(string key, Func factory) + public object? Get(string key, Func factory) { return Get(key, factory, null); } @@ -72,9 +72,9 @@ namespace Umbraco.Cms.Core.Cache _locker.ExitReadLock(); } return entries - .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null) // backward compat, don't store null values in the cache - .ToList(); + .ToList()!; } /// @@ -96,23 +96,23 @@ namespace Umbraco.Cms.Core.Cache _locker.ExitReadLock(); } return entries - .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null + .Select(x => SafeLazy.GetSafeLazyValue((Lazy)x.Value)) // return exceptions as null .Where(x => x != null) // backward compat, don't store null values in the cache - .ToList(); + .ToList()!; } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[] dependentFiles = null) + public object? Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, string[]? dependentFiles = null) { // see notes in HttpRuntimeAppCache - Lazy result; + Lazy? result; try { _locker.EnterUpgradeableReadLock(); - result = MemoryCache.Get(key) as Lazy; + result = MemoryCache.Get(key) as Lazy; if (result == null || SafeLazy.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { result = SafeLazy.GetSafeLazy(factory); @@ -145,7 +145,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, string[]? dependentFiles = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. @@ -205,7 +205,7 @@ namespace Umbraco.Cms.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -236,7 +236,7 @@ namespace Umbraco.Cms.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); // if T is an interface remove anything that implements that interface // otherwise remove exact types (not inherited types) @@ -268,7 +268,7 @@ namespace Umbraco.Cms.Core.Cache // x.Value is Lazy and not null, its value may be null // remove null values as well, does not hurt // get non-created as NonCreatedValue & exceptions as null - var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); + var value = SafeLazy.GetSafeLazyValue((Lazy)x.Value, true); if (value == null) return true; // if T is an interface remove anything that implements that interface @@ -327,7 +327,7 @@ namespace Umbraco.Cms.Core.Cache } } - private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) + private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, string[]? dependentFiles = null) { var absolute = isSliding ? ObjectCache.InfiniteAbsoluteExpiration : (timeout == null ? ObjectCache.InfiniteAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? ObjectCache.NoSlidingExpiration : (timeout ?? ObjectCache.NoSlidingExpiration); diff --git a/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs b/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs index 94c3380bfd..c719ce72e5 100644 --- a/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs +++ b/src/Umbraco.Core/Cache/RepositoryCachePolicyOptions.cs @@ -30,7 +30,7 @@ namespace Umbraco.Cms.Core.Cache /// /// Callback required to get count for GetAllCacheValidateCount /// - public Func PerformCount { get; set; } + public Func? PerformCount { get; set; } /// /// True/false as to validate the total item count when all items are returned from cache, the default is true but this diff --git a/src/Umbraco.Core/Cache/SafeLazy.cs b/src/Umbraco.Core/Cache/SafeLazy.cs index 9f2ad8f114..e57ac21085 100644 --- a/src/Umbraco.Core/Cache/SafeLazy.cs +++ b/src/Umbraco.Core/Cache/SafeLazy.cs @@ -8,13 +8,13 @@ namespace Umbraco.Cms.Core.Cache // an object that represent a value that has not been created yet internal static readonly object ValueNotCreated = new object(); - public static Lazy GetSafeLazy(Func getCacheItem) + public static Lazy GetSafeLazy(Func getCacheItem) { // try to generate the value and if it fails, // wrap in an ExceptionHolder - would be much simpler // to just use lazy.IsValueFaulted alas that field is // internal - return new Lazy(() => + return new Lazy(() => { try { @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.Cache }); } - public static object GetSafeLazyValue(Lazy lazy, bool onlyIfValueIsCreated = false) + public static object? GetSafeLazyValue(Lazy lazy, bool onlyIfValueIsCreated = false) { // if onlyIfValueIsCreated, do not trigger value creation // must return something, though, to differentiate from null values diff --git a/src/Umbraco.Core/Cache/ValueEditorCache.cs b/src/Umbraco.Core/Cache/ValueEditorCache.cs index 44aa83d44d..7d5f20efb4 100644 --- a/src/Umbraco.Core/Cache/ValueEditorCache.cs +++ b/src/Umbraco.Core/Cache/ValueEditorCache.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors; @@ -23,8 +24,8 @@ namespace Umbraco.Cms.Core.Cache // We try and get the dictionary based on the IDataEditor alias, // this is here just in case a data type can have more than one value data editor. // If this is not the case this could be simplified quite a bit, by just using the inner dictionary only. - IDataValueEditor valueEditor; - if (_valueEditorCache.TryGetValue(editor.Alias, out Dictionary dataEditorCache)) + IDataValueEditor? valueEditor; + if (_valueEditorCache.TryGetValue(editor.Alias, out Dictionary? dataEditorCache)) { if (dataEditorCache.TryGetValue(dataType.Id, out valueEditor)) { diff --git a/src/Umbraco.Core/CodeAnnotations/UmbracoObjectTypeAttribute.cs b/src/Umbraco.Core/CodeAnnotations/UmbracoObjectTypeAttribute.cs index 126567de02..6c4e2b9d04 100644 --- a/src/Umbraco.Core/CodeAnnotations/UmbracoObjectTypeAttribute.cs +++ b/src/Umbraco.Core/CodeAnnotations/UmbracoObjectTypeAttribute.cs @@ -21,6 +21,6 @@ namespace Umbraco.Cms.Core.CodeAnnotations public Guid ObjectId { get; private set; } - public Type ModelType { get; private set; } + public Type? ModelType { get; private set; } } } diff --git a/src/Umbraco.Core/Collections/CompositeIntStringKey.cs b/src/Umbraco.Core/Collections/CompositeIntStringKey.cs index 542a6337bd..a9bd71c6cc 100644 --- a/src/Umbraco.Core/Collections/CompositeIntStringKey.cs +++ b/src/Umbraco.Core/Collections/CompositeIntStringKey.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Collections public bool Equals(CompositeIntStringKey other) => _key2 == other._key2 && _key1 == other._key1; - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is CompositeIntStringKey other && _key2 == other._key2 && _key1 == other._key1; public override int GetHashCode() diff --git a/src/Umbraco.Core/Collections/CompositeNStringNStringKey.cs b/src/Umbraco.Core/Collections/CompositeNStringNStringKey.cs index f247f3b76b..450037e652 100644 --- a/src/Umbraco.Core/Collections/CompositeNStringNStringKey.cs +++ b/src/Umbraco.Core/Collections/CompositeNStringNStringKey.cs @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Core.Collections public bool Equals(CompositeNStringNStringKey other) => _key2 == other._key2 && _key1 == other._key1; - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is CompositeNStringNStringKey other && _key2 == other._key2 && _key1 == other._key1; public override int GetHashCode() diff --git a/src/Umbraco.Core/Collections/CompositeStringStringKey.cs b/src/Umbraco.Core/Collections/CompositeStringStringKey.cs index 652717cfdb..b0b7ca2b7b 100644 --- a/src/Umbraco.Core/Collections/CompositeStringStringKey.cs +++ b/src/Umbraco.Core/Collections/CompositeStringStringKey.cs @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Core.Collections public bool Equals(CompositeStringStringKey other) => _key2 == other._key2 && _key1 == other._key1; - public override bool Equals(object obj) + public override bool Equals(object? obj) => obj is CompositeStringStringKey other && _key2 == other._key2 && _key1 == other._key1; public override int GetHashCode() diff --git a/src/Umbraco.Core/Collections/CompositeTypeTypeKey.cs b/src/Umbraco.Core/Collections/CompositeTypeTypeKey.cs index 321f12c592..ea737e0522 100644 --- a/src/Umbraco.Core/Collections/CompositeTypeTypeKey.cs +++ b/src/Umbraco.Core/Collections/CompositeTypeTypeKey.cs @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Collections } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj is CompositeTypeTypeKey key ? key : default; return Type1 == other.Type1 && Type2 == other.Type2; diff --git a/src/Umbraco.Core/Collections/ConcurrentHashSet.cs b/src/Umbraco.Core/Collections/ConcurrentHashSet.cs index 4cbce05f4c..f9c10e5607 100644 --- a/src/Umbraco.Core/Collections/ConcurrentHashSet.cs +++ b/src/Umbraco.Core/Collections/ConcurrentHashSet.cs @@ -189,7 +189,7 @@ namespace Umbraco.Cms.Core.Collections private HashSet GetThreadSafeClone() { - HashSet clone = null; + HashSet? clone = null; try { _instanceLocker.EnterReadLock(); diff --git a/src/Umbraco.Core/Collections/DeepCloneableList.cs b/src/Umbraco.Core/Collections/DeepCloneableList.cs index ecd17aab46..db7677153c 100644 --- a/src/Umbraco.Core/Collections/DeepCloneableList.cs +++ b/src/Umbraco.Core/Collections/DeepCloneableList.cs @@ -153,7 +153,7 @@ namespace Umbraco.Cms.Core.Collections return Enumerable.Empty(); } - public event PropertyChangedEventHandler PropertyChanged; // noop + public event PropertyChangedEventHandler? PropertyChanged; // noop #endregion } } diff --git a/src/Umbraco.Core/Collections/EventClearingObservableCollection.cs b/src/Umbraco.Core/Collections/EventClearingObservableCollection.cs index df98fa5220..f4702f0124 100644 --- a/src/Umbraco.Core/Collections/EventClearingObservableCollection.cs +++ b/src/Umbraco.Core/Collections/EventClearingObservableCollection.cs @@ -26,8 +26,8 @@ namespace Umbraco.Cms.Core.Collections // c# events are weird, they do not behave the same way as other c# things that are 'virtual', // a good article is here: https://medium.com/@unicorn_dev/virtual-events-in-c-something-went-wrong-c6f6f5fbe252 // and https://stackoverflow.com/questions/2268065/c-sharp-language-design-explicit-interface-implementation-of-an-event - private NotifyCollectionChangedEventHandler _changed; - event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged + private NotifyCollectionChangedEventHandler? _changed; + event NotifyCollectionChangedEventHandler? INotifyCollectionChanged.CollectionChanged { add { _changed += value; } remove { _changed -= value; } diff --git a/src/Umbraco.Core/Collections/ObservableDictionary.cs b/src/Umbraco.Core/Collections/ObservableDictionary.cs index a3c705e151..9e6b005407 100644 --- a/src/Umbraco.Core/Collections/ObservableDictionary.cs +++ b/src/Umbraco.Core/Collections/ObservableDictionary.cs @@ -17,16 +17,17 @@ namespace Umbraco.Cms.Core.Collections /// The type of elements contained in the BindableCollection /// The type of the indexing key public class ObservableDictionary : ObservableCollection, IReadOnlyDictionary, IDictionary, INotifyCollectionChanged + where TKey : notnull { protected Dictionary Indecies { get; } - protected Func KeySelector { get; } + protected Func KeySelector { get; } /// /// Create new ObservableDictionary /// /// Selector function to create key from value /// The equality comparer to use when comparing keys, or null to use the default comparer. - public ObservableDictionary(Func keySelector, IEqualityComparer equalityComparer = null) + public ObservableDictionary(Func keySelector, IEqualityComparer? equalityComparer = null) { KeySelector = keySelector ?? throw new ArgumentException(nameof(keySelector)); Indecies = new Dictionary(equalityComparer); @@ -79,8 +80,8 @@ namespace Umbraco.Cms.Core.Collections // c# events are weird, they do not behave the same way as other c# things that are 'virtual', // a good article is here: https://medium.com/@unicorn_dev/virtual-events-in-c-something-went-wrong-c6f6f5fbe252 // and https://stackoverflow.com/questions/2268065/c-sharp-language-design-explicit-interface-implementation-of-an-event - private NotifyCollectionChangedEventHandler _changed; - event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged + private NotifyCollectionChangedEventHandler? _changed; + event NotifyCollectionChangedEventHandler? INotifyCollectionChanged.CollectionChanged { add { _changed += value; } remove { _changed -= value; } @@ -108,7 +109,7 @@ namespace Umbraco.Cms.Core.Collections set { //confirm key matches - if (!KeySelector(value).Equals(key)) + if (!KeySelector(value)!.Equals(key)) throw new InvalidOperationException("Key of new value does not match."); if (!Indecies.ContainsKey(key)) @@ -135,7 +136,7 @@ namespace Umbraco.Cms.Core.Collections if (!Indecies.ContainsKey(key)) return false; //confirm key matches - if (!KeySelector(value).Equals(key)) + if (!KeySelector(value)!.Equals(key)) throw new InvalidOperationException("Key of new value does not match."); this[Indecies[key]] = value; @@ -196,7 +197,7 @@ namespace Umbraco.Cms.Core.Collections val = this[index]; return true; } - val = default; + val = default!; return false; } diff --git a/src/Umbraco.Core/Collections/OrderedHashSet.cs b/src/Umbraco.Core/Collections/OrderedHashSet.cs index 51ae2fea22..e5a34083be 100644 --- a/src/Umbraco.Core/Collections/OrderedHashSet.cs +++ b/src/Umbraco.Core/Collections/OrderedHashSet.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Collections /// and is customizable to keep the newest or oldest equatable item /// /// - public class OrderedHashSet : KeyedCollection + public class OrderedHashSet : KeyedCollection where T : notnull { private readonly bool _keepOldest; diff --git a/src/Umbraco.Core/Collections/StackQueue.cs b/src/Umbraco.Core/Collections/StackQueue.cs index b760ffe646..c4b49e3092 100644 --- a/src/Umbraco.Core/Collections/StackQueue.cs +++ b/src/Umbraco.Core/Collections/StackQueue.cs @@ -6,34 +6,42 @@ namespace Umbraco.Core.Collections /// Collection that can be both a queue and a stack. /// /// - public class StackQueue + public class StackQueue { - private readonly LinkedList _linkedList = new(); + private readonly LinkedList _linkedList = new (); public int Count => _linkedList.Count; public void Clear() => _linkedList.Clear(); - public void Push(T obj) => _linkedList.AddFirst(obj); + public void Push(T? obj) => _linkedList.AddFirst(obj); - public void Enqueue(T obj) => _linkedList.AddFirst(obj); + public void Enqueue(T? obj) => _linkedList.AddFirst(obj); public T Pop() { - T obj = _linkedList.First.Value; + T? obj = default(T); + if (_linkedList.First is not null) + { + obj = _linkedList.First.Value; + } _linkedList.RemoveFirst(); - return obj; + return obj!; } public T Dequeue() { - T obj = _linkedList.Last.Value; + T? obj = default(T); + if (_linkedList.Last is not null) + { + obj = _linkedList.Last.Value; + } _linkedList.RemoveLast(); - return obj; + return obj!; } - public T PeekStack() => _linkedList.First.Value; + public T? PeekStack() => _linkedList.First.Value; - public T PeekQueue() => _linkedList.Last.Value; + public T? PeekQueue() => _linkedList.Last.Value; } } diff --git a/src/Umbraco.Core/Collections/TopoGraph.cs b/src/Umbraco.Core/Collections/TopoGraph.cs index 2e199dd5a4..b568d1bc49 100644 --- a/src/Umbraco.Core/Collections/TopoGraph.cs +++ b/src/Umbraco.Core/Collections/TopoGraph.cs @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Collections public class TopoGraph : TopoGraph { private readonly Func _getKey; - private readonly Func> _getDependencies; + private readonly Func?> _getDependencies; private readonly Dictionary _items = new Dictionary(); /// @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Core.Collections /// /// A method that returns the key of an item. /// A method that returns the dependency keys of an item. - public TopoGraph(Func getKey, Func> getDependencies) + public TopoGraph(Func getKey, Func?> getDependencies) { _getKey = getKey; _getDependencies = getDependencies; diff --git a/src/Umbraco.Core/Composing/CollectionBuilderBase.cs b/src/Umbraco.Core/Composing/CollectionBuilderBase.cs index 81d80bb57c..8b5913ab1d 100644 --- a/src/Umbraco.Core/Composing/CollectionBuilderBase.cs +++ b/src/Umbraco.Core/Composing/CollectionBuilderBase.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Composing { private readonly List _types = new List(); private readonly object _locker = new object(); - private Type[] _registeredTypes; + private Type[]? _registeredTypes; /// /// Gets the internal list of types as an IEnumerable (immutable). diff --git a/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs b/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs index 1e21de0304..1e36c4e8e9 100644 --- a/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs +++ b/src/Umbraco.Core/Composing/ComponentCollectionBuilder.cs @@ -12,8 +12,6 @@ namespace Umbraco.Cms.Core.Composing { private const int LogThresholdMilliseconds = 100; - private IProfilingLogger _logger; - public ComponentCollectionBuilder() { } @@ -21,9 +19,9 @@ namespace Umbraco.Cms.Core.Composing protected override IEnumerable CreateItems(IServiceProvider factory) { - _logger = factory.GetRequiredService(); + var logger = factory.GetRequiredService(); - using (_logger.DebugDuration($"Creating components. (log when >{LogThresholdMilliseconds}ms)", "Created.")) + using (logger.DebugDuration($"Creating components. (log when >{LogThresholdMilliseconds}ms)", "Created.")) { return base.CreateItems(factory); } @@ -31,7 +29,9 @@ namespace Umbraco.Cms.Core.Composing protected override IComponent CreateItem(IServiceProvider factory, Type itemType) { - using (_logger.DebugDuration($"Creating {itemType.FullName}.", $"Created {itemType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds)) + var logger = factory.GetRequiredService(); + + using (logger.DebugDuration($"Creating {itemType.FullName}.", $"Created {itemType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds)) { return base.CreateItem(factory, itemType); } diff --git a/src/Umbraco.Core/Composing/ComposerGraph.cs b/src/Umbraco.Core/Composing/ComposerGraph.cs index 71470d2d73..9e61414029 100644 --- a/src/Umbraco.Core/Composing/ComposerGraph.cs +++ b/src/Umbraco.Core/Composing/ComposerGraph.cs @@ -81,7 +81,7 @@ namespace Umbraco.Cms.Core.Composing return sortedComposerTypes; } - internal Dictionary> GetRequirements(bool throwOnMissing = true) + internal Dictionary?> GetRequirements(bool throwOnMissing = true) { // create a list, remove those that cannot be enabled due to runtime level var composerTypeList = _composerTypes.ToList(); @@ -131,7 +131,7 @@ namespace Umbraco.Cms.Core.Composing } // sort the composers according to their dependencies - var requirements = new Dictionary>(); + var requirements = new Dictionary?>(); foreach (var type in composerTypeList) requirements[type] = null; foreach (var type in composerTypeList) @@ -143,10 +143,10 @@ namespace Umbraco.Cms.Core.Composing return requirements; } - internal IEnumerable SortComposers(Dictionary> requirements) + internal IEnumerable SortComposers(Dictionary?> requirements) { // sort composers - var graph = new TopoGraph>>(kvp => kvp.Key, kvp => kvp.Value); + var graph = new TopoGraph?>>(kvp => kvp.Key, kvp => kvp.Value); graph.AddItems(requirements); List sortedComposerTypes; try @@ -164,7 +164,7 @@ namespace Umbraco.Cms.Core.Composing return sortedComposerTypes; } - internal static string GetComposersReport(Dictionary> requirements) + internal static string GetComposersReport(Dictionary?> requirements) { var text = new StringBuilder(); text.AppendLine("Composers & Dependencies:"); @@ -258,7 +258,7 @@ namespace Umbraco.Cms.Core.Composing types.Remove(kvp.Key); } - private static void GatherRequirementsFromAfterAttribute(Type type, ICollection types, IDictionary> requirements, bool throwOnMissing = true) + private static void GatherRequirementsFromAfterAttribute(Type type, ICollection types, IDictionary?> requirements, bool throwOnMissing = true) { // get 'require' attributes // these attributes are *not* inherited because we want to "custom-inherit" for interfaces only @@ -279,7 +279,7 @@ namespace Umbraco.Cms.Core.Composing if (implems.Count > 0) { if (requirements[type] == null) requirements[type] = new List(); - requirements[type].AddRange(implems); + requirements[type]!.AddRange(implems); } else if (attr.Weak == false && throwOnMissing) // if explicitly set to !weak, is strong, else is weak throw new Exception($"Broken composer dependency: {type.FullName} -> {attr.RequiredType.FullName}."); @@ -291,7 +291,7 @@ namespace Umbraco.Cms.Core.Composing if (types.Contains(attr.RequiredType)) { if (requirements[type] == null) requirements[type] = new List(); - requirements[type].Add(attr.RequiredType); + requirements[type]!.Add(attr.RequiredType); } else if (attr.Weak != true && throwOnMissing) // if not explicitly set to weak, is strong throw new Exception($"Broken composer dependency: {type.FullName} -> {attr.RequiredType.FullName}."); @@ -299,7 +299,7 @@ namespace Umbraco.Cms.Core.Composing } } - private static void GatherRequirementsFromBeforeAttribute(Type type, ICollection types, IDictionary> requirements) + private static void GatherRequirementsFromBeforeAttribute(Type type, ICollection types, IDictionary?> requirements) { // get 'required' attributes // these attributes are *not* inherited because we want to "custom-inherit" for interfaces only @@ -318,7 +318,7 @@ namespace Umbraco.Cms.Core.Composing foreach (var implem in implems) { if (requirements[implem] == null) requirements[implem] = new List(); - requirements[implem].Add(type); + requirements[implem]!.Add(type); } } // required by a class @@ -327,7 +327,7 @@ namespace Umbraco.Cms.Core.Composing if (types.Contains(attr.RequiringType)) { if (requirements[attr.RequiringType] == null) requirements[attr.RequiringType] = new List(); - requirements[attr.RequiringType].Add(type); + requirements[attr.RequiringType]!.Add(type); } } } diff --git a/src/Umbraco.Core/Composing/DefaultUmbracoAssemblyProvider.cs b/src/Umbraco.Core/Composing/DefaultUmbracoAssemblyProvider.cs index 56d798ea0c..366a9bddcb 100644 --- a/src/Umbraco.Core/Composing/DefaultUmbracoAssemblyProvider.cs +++ b/src/Umbraco.Core/Composing/DefaultUmbracoAssemblyProvider.cs @@ -17,13 +17,13 @@ namespace Umbraco.Cms.Core.Composing { private readonly Assembly _entryPointAssembly; private readonly ILoggerFactory _loggerFactory; - private readonly IEnumerable _additionalTargetAssemblies; - private List _discovered; + private readonly IEnumerable? _additionalTargetAssemblies; + private List? _discovered; public DefaultUmbracoAssemblyProvider( Assembly entryPointAssembly, ILoggerFactory loggerFactory, - IEnumerable additionalTargetAssemblies = null) + IEnumerable? additionalTargetAssemblies = null) { _entryPointAssembly = entryPointAssembly ?? throw new ArgumentNullException(nameof(entryPointAssembly)); _loggerFactory = loggerFactory; diff --git a/src/Umbraco.Core/Composing/DisableAttribute.cs b/src/Umbraco.Core/Composing/DisableAttribute.cs index b3cfe59f11..23d825ee1c 100644 --- a/src/Umbraco.Core/Composing/DisableAttribute.cs +++ b/src/Umbraco.Core/Composing/DisableAttribute.cs @@ -38,6 +38,6 @@ namespace Umbraco.Cms.Core.Composing /// /// Gets the disabled type, or null if it is the composer marked with the attribute. /// - public Type DisabledType { get; } + public Type? DisabledType { get; } } } diff --git a/src/Umbraco.Core/Composing/EnableAttribute.cs b/src/Umbraco.Core/Composing/EnableAttribute.cs index 91fdd9e7e5..90fb1a9cc6 100644 --- a/src/Umbraco.Core/Composing/EnableAttribute.cs +++ b/src/Umbraco.Core/Composing/EnableAttribute.cs @@ -32,6 +32,6 @@ namespace Umbraco.Cms.Core.Composing /// /// Gets the enabled type, or null if it is the composer marked with the attribute. /// - public Type EnabledType { get; } + public Type? EnabledType { get; } } } diff --git a/src/Umbraco.Core/Composing/ITypeFinder.cs b/src/Umbraco.Core/Composing/ITypeFinder.cs index 2522c2f593..55e9da31fd 100644 --- a/src/Umbraco.Core/Composing/ITypeFinder.cs +++ b/src/Umbraco.Core/Composing/ITypeFinder.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Composing IEnumerable FindClassesOfTypeWithAttribute( Type assignTypeFrom, Type attributeType, - IEnumerable assemblies = null, + IEnumerable? assemblies = null, bool onlyConcreteClasses = true); /// @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Composing /// /// /// - IEnumerable FindClassesOfType(Type assignTypeFrom, IEnumerable assemblies = null, bool onlyConcreteClasses = true); + IEnumerable FindClassesOfType(Type assignTypeFrom, IEnumerable? assemblies = null, bool onlyConcreteClasses = true); /// /// Finds any classes with the attribute. @@ -49,7 +49,7 @@ namespace Umbraco.Cms.Core.Composing /// IEnumerable FindClassesWithAttribute( Type attributeType, - IEnumerable assemblies, + IEnumerable? assemblies, bool onlyConcreteClasses); } } diff --git a/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs b/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs index 7fee8eaf26..67116524ac 100644 --- a/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs +++ b/src/Umbraco.Core/Composing/LazyReadOnlyCollection.cs @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Composing get { EnsureCollection(); - return _count.Value; + return _count.GetValueOrDefault(); } } diff --git a/src/Umbraco.Core/Composing/ReferenceResolver.cs b/src/Umbraco.Core/Composing/ReferenceResolver.cs index fdc72a183b..ed2a0c0059 100644 --- a/src/Umbraco.Core/Composing/ReferenceResolver.cs +++ b/src/Umbraco.Core/Composing/ReferenceResolver.cs @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Core.Composing { foreach(var dll in Directory.EnumerateFiles(dir, "*.dll")) { - AssemblyName assemblyName = null; + AssemblyName? assemblyName = null; try { assemblyName = AssemblyName.GetAssemblyName(dll); diff --git a/src/Umbraco.Core/Composing/RuntimeHash.cs b/src/Umbraco.Core/Composing/RuntimeHash.cs index 7ca35855de..5e0523f09d 100644 --- a/src/Umbraco.Core/Composing/RuntimeHash.cs +++ b/src/Umbraco.Core/Composing/RuntimeHash.cs @@ -14,7 +14,7 @@ namespace Umbraco.Cms.Core.Composing { private readonly IProfilingLogger _logger; private readonly RuntimeHashPaths _paths; - private string _calculated; + private string? _calculated; public RuntimeHash(IProfilingLogger logger, RuntimeHashPaths paths) { diff --git a/src/Umbraco.Core/Composing/TypeFinder.cs b/src/Umbraco.Core/Composing/TypeFinder.cs index 07a2eb72c9..6f21845399 100644 --- a/src/Umbraco.Core/Composing/TypeFinder.cs +++ b/src/Umbraco.Core/Composing/TypeFinder.cs @@ -17,23 +17,23 @@ namespace Umbraco.Cms.Core.Composing { private readonly ILogger _logger; private readonly IAssemblyProvider _assemblyProvider; - private volatile HashSet _localFilteredAssemblyCache; + private volatile HashSet? _localFilteredAssemblyCache; private readonly object _localFilteredAssemblyCacheLocker = new object(); private readonly List _notifiedLoadExceptionAssemblies = new List(); private static readonly ConcurrentDictionary s_typeNamesCache = new ConcurrentDictionary(); - private readonly ITypeFinderConfig _typeFinderConfig; + private readonly ITypeFinderConfig? _typeFinderConfig; // used for benchmark tests internal bool QueryWithReferencingAssemblies { get; set; } = true; - public TypeFinder(ILogger logger, IAssemblyProvider assemblyProvider, ITypeFinderConfig typeFinderConfig = null) + public TypeFinder(ILogger logger, IAssemblyProvider assemblyProvider, ITypeFinderConfig? typeFinderConfig = null) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _assemblyProvider = assemblyProvider; _typeFinderConfig = typeFinderConfig; } - private string[] _assembliesAcceptingLoadExceptions = null; + private string[]? _assembliesAcceptingLoadExceptions = null; private string[] AssembliesAcceptingLoadExceptions { @@ -99,8 +99,8 @@ namespace Umbraco.Cms.Core.Composing /// /// private IEnumerable GetFilteredAssemblies( - IEnumerable excludeFromResults = null, - string[] exclusionFilter = null) + IEnumerable? excludeFromResults = null, + string[]? exclusionFilter = null) { if (excludeFromResults == null) excludeFromResults = new HashSet(); @@ -195,7 +195,7 @@ namespace Umbraco.Cms.Core.Composing public IEnumerable FindClassesOfTypeWithAttribute( Type assignTypeFrom, Type attributeType, - IEnumerable assemblies = null, + IEnumerable? assemblies = null, bool onlyConcreteClasses = true) { var assemblyList = (assemblies ?? AssembliesToScan).ToList(); @@ -212,7 +212,7 @@ namespace Umbraco.Cms.Core.Composing /// /// /// - public IEnumerable FindClassesOfType(Type assignTypeFrom, IEnumerable assemblies = null, bool onlyConcreteClasses = true) + public IEnumerable FindClassesOfType(Type assignTypeFrom, IEnumerable? assemblies = null, bool onlyConcreteClasses = true) { var assemblyList = (assemblies ?? AssembliesToScan).ToList(); @@ -228,7 +228,7 @@ namespace Umbraco.Cms.Core.Composing /// public IEnumerable FindClassesWithAttribute( Type attributeType, - IEnumerable assemblies = null, + IEnumerable? assemblies = null, bool onlyConcreteClasses = true) { var assemblyList = (assemblies ?? AssembliesToScan).ToList(); @@ -308,7 +308,7 @@ namespace Umbraco.Cms.Core.Composing { var assembly = stack.Pop(); - IReadOnlyList assemblyTypes = null; + IReadOnlyList? assemblyTypes = null; if (assembly != attributeType.Assembly || attributeAssemblyIsCandidate) { // get all assembly types that can be assigned to baseType @@ -362,7 +362,7 @@ namespace Umbraco.Cms.Core.Composing Type baseType, IEnumerable assemblies, bool onlyConcreteClasses, - Func additionalFilter = null) + Func? additionalFilter = null) { var candidateAssemblies = new HashSet(assemblies); var baseTypeAssemblyIsCandidate = candidateAssemblies.Contains(baseType.Assembly); @@ -383,7 +383,7 @@ namespace Umbraco.Cms.Core.Composing var assembly = stack.Pop(); // get all assembly types that can be assigned to baseType - IReadOnlyList assemblyTypes = null; + IReadOnlyList? assemblyTypes = null; if (assembly != baseType.Assembly || baseTypeAssemblyIsCandidate) { try diff --git a/src/Umbraco.Core/Composing/TypeFinderConfig.cs b/src/Umbraco.Core/Composing/TypeFinderConfig.cs index adb82e5336..4b5271039f 100644 --- a/src/Umbraco.Core/Composing/TypeFinderConfig.cs +++ b/src/Umbraco.Core/Composing/TypeFinderConfig.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.Composing public class TypeFinderConfig : ITypeFinderConfig { private readonly TypeFinderSettings _settings; - private IEnumerable _assembliesAcceptingLoadExceptions; + private IEnumerable? _assembliesAcceptingLoadExceptions; public TypeFinderConfig(IOptions settings) => _settings = settings.Value; diff --git a/src/Umbraco.Core/Composing/TypeFinderExtensions.cs b/src/Umbraco.Core/Composing/TypeFinderExtensions.cs index cad92aa17b..adb920b64a 100644 --- a/src/Umbraco.Core/Composing/TypeFinderExtensions.cs +++ b/src/Umbraco.Core/Composing/TypeFinderExtensions.cs @@ -16,7 +16,7 @@ namespace Umbraco.Extensions /// /// /// - public static IEnumerable FindClassesOfTypeWithAttribute(this ITypeFinder typeFinder, IEnumerable assemblies = null, bool onlyConcreteClasses = true) + public static IEnumerable FindClassesOfTypeWithAttribute(this ITypeFinder typeFinder, IEnumerable? assemblies = null, bool onlyConcreteClasses = true) where TAttribute : Attribute => typeFinder.FindClassesOfTypeWithAttribute(typeof(T), typeof(TAttribute), assemblies, onlyConcreteClasses); @@ -28,7 +28,7 @@ namespace Umbraco.Extensions /// /// /// - public static IEnumerable FindClassesOfType(this ITypeFinder typeFinder, IEnumerable assemblies = null, bool onlyConcreteClasses = true) + public static IEnumerable FindClassesOfType(this ITypeFinder typeFinder, IEnumerable? assemblies = null, bool onlyConcreteClasses = true) => typeFinder.FindClassesOfType(typeof(T), assemblies, onlyConcreteClasses); /// @@ -39,7 +39,7 @@ namespace Umbraco.Extensions /// The assemblies. /// if set to true only concrete classes. /// - public static IEnumerable FindClassesWithAttribute(this ITypeFinder typeFinder, IEnumerable assemblies = null, bool onlyConcreteClasses = true) + public static IEnumerable FindClassesWithAttribute(this ITypeFinder typeFinder, IEnumerable? assemblies = null, bool onlyConcreteClasses = true) where T : Attribute => typeFinder.FindClassesWithAttribute(typeof(T), assemblies, onlyConcreteClasses); } diff --git a/src/Umbraco.Core/Composing/TypeLoader.cs b/src/Umbraco.Core/Composing/TypeLoader.cs index 6af8cb5ced..3d47054520 100644 --- a/src/Umbraco.Core/Composing/TypeLoader.cs +++ b/src/Umbraco.Core/Composing/TypeLoader.cs @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Composing /// on a hash of the DLLs in the ~/bin folder to check for cache expiration. /// public sealed class TypeLoader - { + { private readonly IRuntimeHash _runtimeHash; private readonly IAppPolicyCache _runtimeCache; private readonly ILogger _logger; @@ -35,17 +35,17 @@ namespace Umbraco.Cms.Core.Composing private readonly object _locko = new object(); private readonly object _timerLock = new object(); - private Timer _timer; + private Timer? _timer; private bool _timing; - private string _cachedAssembliesHash; - private string _currentAssembliesHash; - private IEnumerable _assemblies; + private string? _cachedAssembliesHash; + private string? _currentAssembliesHash; + private IEnumerable? _assemblies; private bool _reportedChange; private readonly DirectoryInfo _localTempPath; - private readonly Lazy _fileBasePath; + private readonly Lazy _fileBasePath; private readonly Dictionary<(string, string), IEnumerable> _emptyCache = new Dictionary<(string, string), IEnumerable>(); - private string _typesListFilePath; - private string _typesHashFilePath; + private string? _typesListFilePath; + private string? _typesHashFilePath; /// /// Initializes a new instance of the class. @@ -55,7 +55,7 @@ namespace Umbraco.Cms.Core.Composing /// Files storage location. /// A profiling logger. /// - public TypeLoader(ITypeFinder typeFinder, IRuntimeHash runtimeHash, IAppPolicyCache runtimeCache, DirectoryInfo localTempPath, ILogger logger, IProfiler profiler, IEnumerable assembliesToScan = null) + public TypeLoader(ITypeFinder typeFinder, IRuntimeHash runtimeHash, IAppPolicyCache runtimeCache, DirectoryInfo localTempPath, ILogger logger, IProfiler profiler, IEnumerable? assembliesToScan = null) : this(typeFinder, runtimeHash, runtimeCache, localTempPath, logger, profiler, true, assembliesToScan) { } @@ -68,7 +68,7 @@ namespace Umbraco.Cms.Core.Composing /// A profiling logger. /// Whether to detect changes using hashes. /// - public TypeLoader(ITypeFinder typeFinder, IRuntimeHash runtimeHash, IAppPolicyCache runtimeCache, DirectoryInfo localTempPath, ILogger logger, IProfiler profiler, bool detectChanges, IEnumerable assembliesToScan = null) + public TypeLoader(ITypeFinder typeFinder, IRuntimeHash runtimeHash, IAppPolicyCache runtimeCache, DirectoryInfo localTempPath, ILogger logger, IProfiler profiler, bool detectChanges, IEnumerable? assembliesToScan = null) { if (profiler is null) { @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Composing _profilingLogger = new ProfilingLogger(logger, profiler); _assemblies = assembliesToScan; - _fileBasePath = new Lazy(GetFileBasePath); + _fileBasePath = new Lazy(GetFileBasePath); if (detectChanges) { @@ -105,7 +105,7 @@ namespace Umbraco.Cms.Core.Composing if (typesListFilePath != null) { DeleteFile(typesListFilePath, FileDeleteTimeout); - } + } WriteCacheTypesHash(); } @@ -230,7 +230,7 @@ namespace Umbraco.Cms.Core.Composing if (typesHashFilePath != null) { File.WriteAllText(typesHashFilePath, CurrentAssembliesHash, Encoding.UTF8); - } + } } #endregion @@ -244,9 +244,10 @@ namespace Umbraco.Cms.Core.Composing private const int FileDeleteTimeout = 4000; // milliseconds // internal for tests - public Attempt> TryGetCached(Type baseType, Type attributeType) + public Attempt> TryGetCached(Type? baseType, Type? attributeType) { - var cache = _runtimeCache.GetCacheItem(CacheKey, ReadCacheSafe, TimeSpan.FromSeconds(ListFileCacheDuration)); + var cache = + _runtimeCache.GetCacheItem(CacheKey, ReadCacheSafe, TimeSpan.FromSeconds(ListFileCacheDuration))!; cache.TryGetValue( (baseType == null ? string.Empty : baseType.FullName, attributeType == null ? string.Empty : attributeType.FullName), @@ -343,15 +344,15 @@ namespace Umbraco.Cms.Core.Composing } // internal for tests - public string GetTypesListFilePath() => _typesListFilePath ??= _fileBasePath.Value == null ? null : _fileBasePath.Value + ".list"; + public string? GetTypesListFilePath() => _typesListFilePath ??= _fileBasePath.Value == null ? null : _fileBasePath.Value + ".list"; - private string GetTypesHashFilePath() => _typesHashFilePath ??= _fileBasePath.Value == null ? null : _fileBasePath.Value + ".hash"; + private string? GetTypesHashFilePath() => _typesHashFilePath ??= _fileBasePath.Value == null ? null : _fileBasePath.Value + ".hash"; /// /// Used to produce the Lazy value of _fileBasePath /// /// - private string GetFileBasePath() + private string? GetFileBasePath() { if (_localTempPath == null) { @@ -557,7 +558,7 @@ namespace Umbraco.Cms.Core.Composing /// A set of assemblies for type resolution. /// All class types inheriting from or implementing the specified type. /// Caching is disabled when using specific assemblies. - public IEnumerable GetTypes(bool cache = true, IEnumerable specificAssemblies = null) + public IEnumerable GetTypes(bool cache = true, IEnumerable? specificAssemblies = null) { if (_logger == null) { @@ -611,7 +612,7 @@ namespace Umbraco.Cms.Core.Composing /// A set of assemblies for type resolution. /// All class types inheriting from or implementing the specified type and marked with the specified attribute. /// Caching is disabled when using specific assemblies. - public IEnumerable GetTypesWithAttribute(bool cache = true, IEnumerable specificAssemblies = null) + public IEnumerable GetTypesWithAttribute(bool cache = true, IEnumerable? specificAssemblies = null) where TAttribute : Attribute { if (_logger == null) @@ -665,7 +666,7 @@ namespace Umbraco.Cms.Core.Composing /// A set of assemblies for type resolution. /// All class types marked with the specified attribute. /// Caching is disabled when using specific assemblies. - public IEnumerable GetAttributedTypes(bool cache = true, IEnumerable specificAssemblies = null) + public IEnumerable GetAttributedTypes(bool cache = true, IEnumerable? specificAssemblies = null) where TAttribute : Attribute { if (_logger == null) @@ -690,7 +691,7 @@ namespace Umbraco.Cms.Core.Composing private IEnumerable GetTypesInternal( Type baseType, - Type attributeType, + Type? attributeType, Func> finder, string action, bool cache) @@ -714,7 +715,7 @@ namespace Umbraco.Cms.Core.Composing } } - private static string GetName(Type baseType, Type attributeType) + private static string GetName(Type? baseType, Type? attributeType) { var s = attributeType == null ? string.Empty : ("[" + attributeType + "]"); s += baseType; @@ -722,15 +723,17 @@ namespace Umbraco.Cms.Core.Composing } private IEnumerable GetTypesInternalLocked( - Type baseType, Type attributeType, + Type? baseType, + Type? attributeType, Func> finder, string action, bool cache) { // check if the TypeList already exists, if so return it, if not we'll create it var tobject = typeof(object); // CompositeTypeTypeKey does not support null values + var listKey = new CompositeTypeTypeKey(baseType ?? tobject, attributeType ?? tobject); - TypeList typeList = null; + TypeList? typeList = null; if (cache) { _types.TryGetValue(listKey, out typeList); // else null @@ -847,21 +850,21 @@ namespace Umbraco.Cms.Core.Composing { private readonly HashSet _types = new HashSet(); - public TypeList(Type baseType, Type attributeType) + public TypeList(Type? baseType, Type? attributeType) { BaseType = baseType; AttributeType = attributeType; } - public Type BaseType { get; } - public Type AttributeType { get; } + public Type? BaseType { get; } + public Type? AttributeType { get; } /// /// Adds a type. /// public void Add(Type type) { - if (BaseType.IsAssignableFrom(type) == false) + if (BaseType?.IsAssignableFrom(type) == false) throw new ArgumentException("Base type " + BaseType + " is not assignable from type " + type + ".", nameof(type)); _types.Add(type); } diff --git a/src/Umbraco.Core/Configuration/ConfigConnectionString.cs b/src/Umbraco.Core/Configuration/ConfigConnectionString.cs index 116b96df9c..899a95a2da 100644 --- a/src/Umbraco.Core/Configuration/ConfigConnectionString.cs +++ b/src/Umbraco.Core/Configuration/ConfigConnectionString.cs @@ -7,18 +7,18 @@ namespace Umbraco.Cms.Core.Configuration { public string Name { get; } - public string ConnectionString { get; } + public string? ConnectionString { get; } - public string ProviderName { get; } + public string? ProviderName { get; } - public ConfigConnectionString(string name, string connectionString, string providerName = null) + public ConfigConnectionString(string name, string? connectionString, string? providerName = null) { Name = name ?? throw new ArgumentNullException(nameof(name)); ConnectionString = ParseConnectionString(connectionString, ref providerName); - ProviderName = providerName; + ProviderName = providerName!; } - private static string ParseConnectionString(string connectionString, ref string providerName) + private static string? ParseConnectionString(string? connectionString, ref string? providerName) { if (string.IsNullOrEmpty(connectionString)) { @@ -63,7 +63,7 @@ namespace Umbraco.Cms.Core.Configuration /// /// The provider name or null is the connection string is empty. /// - public static string ParseProviderName(string connectionString) + public static string? ParseProviderName(string? connectionString) { if (string.IsNullOrEmpty(connectionString)) { diff --git a/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs index ac4e6b0864..c8f5c41988 100644 --- a/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/ContentSettingsExtensions.cs @@ -23,7 +23,7 @@ namespace Umbraco.Extensions /// /// The property type alias. /// The auto-fill configuration for the specified property alias, or null. - public static ImagingAutoFillUploadField GetConfig(this ContentSettings contentSettings, string propertyTypeAlias) + public static ImagingAutoFillUploadField? GetConfig(this ContentSettings contentSettings, string propertyTypeAlias) { var autoFillConfigs = contentSettings.Imaging.AutoFillImageProperties; return autoFillConfigs?.FirstOrDefault(x => x.Alias == propertyTypeAlias); diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs index 560835a7e4..2b22b0f28b 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -7,8 +7,8 @@ namespace Umbraco.Extensions { public static class GlobalSettingsExtensions { - private static string _mvcArea; - private static string _backOfficePath; + private static string? _mvcArea; + private static string? _backOfficePath; /// /// Returns the absolute path for the Umbraco back office diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs index f1a4f0643c..abaee9b0f7 100644 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs @@ -77,7 +77,7 @@ namespace Umbraco.Cms.Core.Configuration.Grid ? GetResult() : _appCaches.RuntimeCache.GetCacheItem>(typeof(GridEditorsConfig) + ".Editors",GetResult, TimeSpan.FromMinutes(10)); - return result; + return result!; } } } diff --git a/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs index c8544dcebc..5e4f371c73 100644 --- a/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ActiveDirectorySettings.cs @@ -12,6 +12,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the Active Directory domain. /// - public string Domain { get; set; } + public string? Domain { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs index c0421be7e3..44568c33c0 100644 --- a/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs +++ b/src/Umbraco.Core/Configuration/Models/ConnectionStrings.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Configuration.Models // See: https://stackoverflow.com/a/54607296/489433 #pragma warning disable SA1300 // Element should begin with upper-case letter #pragma warning disable IDE1006 // Naming Styles - private string umbracoDbDSN + private string? umbracoDbDSN #pragma warning restore IDE1006 // Naming Styles #pragma warning restore SA1300 // Element should begin with upper-case letter { diff --git a/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs b/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs index 53bc96bbf5..6a6d3a8e61 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentErrorPage.cs @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the content XPath. /// - public string ContentXPath { get; set; } + public string? ContentXPath { get; set; } /// /// Gets a value indicating whether the field is populated. @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// Gets or sets a value for the content culture. /// [Required] - public string Culture { get; set; } + public string Culture { get; set; } = null!; internal override bool IsValid() => base.IsValid() && diff --git a/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs b/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs index b4ae2b34a1..c23eac75b2 100644 --- a/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/ContentNotificationSettings.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the email address for notifications. /// - public string Email { get; set; } + public string? Email { get; set; } /// /// Gets or sets a value indicating whether HTML email notifications should be disabled. diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index 97fb91b0ec..efcd9ee1cd 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -152,7 +152,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the SMTP settings. /// - public SmtpSettings Smtp { get; set; } + public SmtpSettings? Smtp { get; set; } /// /// Gets a value indicating whether SMTP is configured. @@ -179,4 +179,4 @@ namespace Umbraco.Cms.Core.Configuration.Models [DefaultValue(StaticSqlWriteLockTimeOut)] public TimeSpan SqlWriteLockTimeOut { get; } = TimeSpan.Parse(StaticSqlWriteLockTimeOut); } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs index b9e11e99ca..26c2b26803 100644 --- a/src/Umbraco.Core/Configuration/Models/HostingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/HostingSettings.cs @@ -17,12 +17,12 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the application virtual path. /// - public string ApplicationVirtualPath { get; set; } + public string? ApplicationVirtualPath { get; set; } /// /// Gets or sets a value for the location of temporary files. /// - [DefaultValue(StaticLocalTempStorageLocation)] + [DefaultValue(StaticLocalTempStorageLocation)] public LocalTempStorage LocalTempStorageLocation { get; set; } = Enum.Parse(StaticLocalTempStorageLocation); /// diff --git a/src/Umbraco.Core/Configuration/Models/ImagingAutoFillUploadField.cs b/src/Umbraco.Core/Configuration/Models/ImagingAutoFillUploadField.cs index 462a90c351..8a0a1658b2 100644 --- a/src/Umbraco.Core/Configuration/Models/ImagingAutoFillUploadField.cs +++ b/src/Umbraco.Core/Configuration/Models/ImagingAutoFillUploadField.cs @@ -15,30 +15,30 @@ namespace Umbraco.Cms.Core.Configuration.Models /// Gets or sets a value for the alias of the image upload property. /// [Required] - public string Alias { get; set; } + public string Alias { get; set; } = null!; /// /// Gets or sets a value for the width field alias of the image upload property. /// [Required] - public string WidthFieldAlias { get; set; } + public string WidthFieldAlias { get; set; } = null!; /// /// Gets or sets a value for the height field alias of the image upload property. /// [Required] - public string HeightFieldAlias { get; set; } + public string HeightFieldAlias { get; set; } = null!; /// /// Gets or sets a value for the length field alias of the image upload property. /// [Required] - public string LengthFieldAlias { get; set; } + public string LengthFieldAlias { get; set; } = null!; /// /// Gets or sets a value for the extension field alias of the image upload property. /// [Required] - public string ExtensionFieldAlias { get; set; } + public string ExtensionFieldAlias { get; set; } = null!; } } diff --git a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs index ee223b36c6..540db22670 100644 --- a/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using Umbraco.Cms.Core.Configuration.UmbracoSettings; using Umbraco.Extensions; @@ -98,10 +99,12 @@ namespace Umbraco.Cms.Core.Configuration.Models public class CharItem : IChar { /// - public string Char { get; set; } + [Required] + public string Char { get; set; } = null!; /// - public string Replacement { get; set; } + [Required] + public string Replacement { get; set; } = null!; } } } diff --git a/src/Umbraco.Core/Configuration/Models/RichTextEditorSettings.cs b/src/Umbraco.Core/Configuration/Models/RichTextEditorSettings.cs index 6ea563c741..4bcbd19a1b 100644 --- a/src/Umbraco.Core/Configuration/Models/RichTextEditorSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RichTextEditorSettings.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using Umbraco.Cms.Core.Models.ContentEditing; namespace Umbraco.Cms.Core.Configuration.Models @@ -97,8 +98,13 @@ namespace Umbraco.Cms.Core.Configuration.Models public class RichTextEditorCommand { - public string Alias { get; set; } - public string Name { get; set; } + [Required] + public string Alias { get; set; } = null!; + + [Required] + public string Name { get; set; } = null!; + + [Required] public RichTextEditorCommandMode Mode { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/RuntimeMinificationSettings.cs b/src/Umbraco.Core/Configuration/Models/RuntimeMinificationSettings.cs index fe999f7bc0..643e83bcac 100644 --- a/src/Umbraco.Core/Configuration/Models/RuntimeMinificationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/RuntimeMinificationSettings.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.Configuration.Models { internal const bool StaticUseInMemoryCache = false; internal const string StaticCacheBuster = "Version"; - internal const string StaticVersion = null; + internal const string? StaticVersion = null; /// /// Use in memory cache @@ -25,6 +25,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// The unique version string used if CacheBuster is 'Version'. /// [DefaultValue(StaticVersion)] - public string Version { get; set; } = StaticVersion; + public string? Version { get; set; } = StaticVersion; } } diff --git a/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs index 7d4dd45fb8..327240ebd8 100644 --- a/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the authorization cookie domain. /// - public string AuthCookieDomain { get; set; } + public string? AuthCookieDomain { get; set; } /// /// Gets or sets a value indicating whether the user's email address is to be considered as their username. @@ -60,11 +60,11 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the user password settings. /// - public UserPasswordConfigurationSettings UserPassword { get; set; } + public UserPasswordConfigurationSettings? UserPassword { get; set; } /// /// Gets or sets a value for the member password settings. /// - public MemberPasswordConfigurationSettings MemberPassword { get; set; } + public MemberPasswordConfigurationSettings? MemberPassword { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs b/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs index dca2b70558..54b9ad6c84 100644 --- a/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SmtpSettings.cs @@ -54,12 +54,12 @@ namespace Umbraco.Cms.Core.Configuration.Models /// [Required] [EmailAddress] - public string From { get; set; } + public string From { get; set; } = null!; /// /// Gets or sets a value for the SMTP host. /// - public string Host { get; set; } + public string? Host { get; set; } /// /// Gets or sets a value for the SMTP port. @@ -75,7 +75,7 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the SMTP pick-up directory. /// - public string PickupDirectoryLocation { get; set; } + public string? PickupDirectoryLocation { get; set; } /// /// Gets or sets a value for the SMTP delivery method. @@ -86,11 +86,11 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the SMTP user name. /// - public string Username { get; set; } + public string? Username { get; set; } /// /// Gets or sets a value for the SMTP password. /// - public string Password { get; set; } + public string? Password { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs b/src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs index e41921de8c..30ef3718f4 100644 --- a/src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/TypeFinderSettings.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace Umbraco.Cms.Core.Configuration.Models { @@ -15,12 +16,13 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the assemblies that accept load exceptions during type finder operations. /// - public string AssembliesAcceptingLoadExceptions { get; set; } + [Required] + public string AssembliesAcceptingLoadExceptions { get; set; } = null!; /// /// By default the entry assemblies for scanning plugin types is the Umbraco DLLs. If you require /// scanning for plugins based on different root referenced assemblies you can add the assembly name to this list. /// - public IEnumerable AdditionalEntryAssemblies { get; set; } + public IEnumerable? AdditionalEntryAssemblies { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs b/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs index 7103a9534e..08a4af5667 100644 --- a/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs @@ -44,17 +44,17 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value to use for creating a user with a name for Unattended Installs /// - public string UnattendedUserName { get; set; } = null; + public string? UnattendedUserName { get; set; } = null; /// /// Gets or sets a value to use for creating a user with an email for Unattended Installs /// [EmailAddress] - public string UnattendedUserEmail { get; set; } = null; + public string? UnattendedUserEmail { get; set; } = null; /// /// Gets or sets a value to use for creating a user with a password for Unattended Installs /// - public string UnattendedUserPassword { get; set; } = null; + public string? UnattendedUserPassword { get; set; } = null; } } diff --git a/src/Umbraco.Core/Configuration/Models/Validation/ConfigurationValidatorBase.cs b/src/Umbraco.Core/Configuration/Models/Validation/ConfigurationValidatorBase.cs index 9f0a23467d..ca5d4d11e5 100644 --- a/src/Umbraco.Core/Configuration/Models/Validation/ConfigurationValidatorBase.cs +++ b/src/Umbraco.Core/Configuration/Models/Validation/ConfigurationValidatorBase.cs @@ -60,7 +60,7 @@ namespace Umbraco.Cms.Core.Configuration.Models.Validation /// Description of validation appended to message if validation fails. /// A message to output if the value does not match. /// True if valid, false if not. - public bool ValidateOptionalEntry(string configPath, ValidatableEntryBase value, string validationDescription, out string message) + public bool ValidateOptionalEntry(string configPath, ValidatableEntryBase? value, string validationDescription, out string message) { if (value != null && !value.IsValid()) { diff --git a/src/Umbraco.Core/Configuration/Models/Validation/GlobalSettingsValidator.cs b/src/Umbraco.Core/Configuration/Models/Validation/GlobalSettingsValidator.cs index 5a7a0ad2f5..40b82ee09d 100644 --- a/src/Umbraco.Core/Configuration/Models/Validation/GlobalSettingsValidator.cs +++ b/src/Umbraco.Core/Configuration/Models/Validation/GlobalSettingsValidator.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Configuration.Models.Validation return ValidateOptionsResult.Success; } - private bool ValidateSmtpSetting(SmtpSettings value, out string message) => + private bool ValidateSmtpSetting(SmtpSettings? value, out string message) => ValidateOptionalEntry($"{Constants.Configuration.ConfigGlobal}:{nameof(GlobalSettings.Smtp)}", value, "A valid From email address is required", out message); private bool ValidateSqlWriteLockTimeOutSetting(TimeSpan configuredTimeOut, out string message) { diff --git a/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs b/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs index 629095e32c..0c78b3ae24 100644 --- a/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs @@ -79,6 +79,6 @@ namespace Umbraco.Cms.Core.Configuration.Models /// /// Gets or sets a value for the Umbraco application URL. /// - public string UmbracoApplicationUrl { get; set; } + public string? UmbracoApplicationUrl { get; set; } } } diff --git a/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs b/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs index 0f397a749f..1b1ebc6af5 100644 --- a/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs +++ b/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs @@ -7,7 +7,7 @@ namespace Umbraco.Extensions { public static class ModelsBuilderConfigExtensions { - private static string _modelsDirectoryAbsolute = null; + private static string? _modelsDirectoryAbsolute = null; public static string ModelsDirectoryAbsolute(this ModelsBuilderSettings modelsBuilderConfig, IHostingEnvironment hostingEnvironment) { diff --git a/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs b/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs index 0c6e6f0f68..eaaad72eb6 100644 --- a/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs +++ b/src/Umbraco.Core/ContentApps/ContentAppFactoryCollection.cs @@ -31,18 +31,18 @@ namespace Umbraco.Cms.Core.ContentApps } - public IEnumerable GetContentAppsFor(object o, IEnumerable userGroups=null) + public IEnumerable GetContentAppsFor(object o, IEnumerable? userGroups = null) { var roles = GetCurrentUserGroups(); var apps = this.Select(x => x.GetContentAppFor(o, roles)).WhereNotNull().OrderBy(x => x.Weight).ToList(); var aliases = new HashSet(); - List dups = null; + List? dups = null; foreach (var app in apps) { - if (aliases.Contains(app.Alias)) + if (aliases.Contains(app!.Alias)) (dups ?? (dups = new List())).Add(app.Alias); else aliases.Add(app.Alias); diff --git a/src/Umbraco.Core/ContentApps/ContentEditorContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ContentEditorContentAppFactory.cs index 44cd9d5bbe..948c563ea9 100644 --- a/src/Umbraco.Core/ContentApps/ContentEditorContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ContentEditorContentAppFactory.cs @@ -10,11 +10,11 @@ namespace Umbraco.Cms.Core.ContentApps // see note on ContentApp internal const int Weight = -100; - private ContentApp _contentApp; - private ContentApp _mediaApp; - private ContentApp _memberApp; + private ContentApp? _contentApp; + private ContentApp? _mediaApp; + private ContentApp? _memberApp; - public ContentApp GetContentAppFor(object o, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object o, IEnumerable userGroups) { switch (o) { diff --git a/src/Umbraco.Core/ContentApps/ContentInfoContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ContentInfoContentAppFactory.cs index 865218b134..3e068750c4 100644 --- a/src/Umbraco.Core/ContentApps/ContentInfoContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ContentInfoContentAppFactory.cs @@ -10,42 +10,42 @@ namespace Umbraco.Cms.Core.ContentApps // see note on ContentApp private const int Weight = +100; - private ContentApp _contentApp; - private ContentApp _mediaApp; - private ContentApp _memberApp; + private ContentApp? _contentApp; + private ContentApp? _mediaApp; + private ContentApp? _memberApp; - public ContentApp GetContentAppFor(object o, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object o, IEnumerable userGroups) { switch (o) { case IContent _: - return _contentApp ?? (_contentApp = new ContentApp + return _contentApp ??= new ContentApp { Alias = "umbInfo", Name = "Info", Icon = "icon-info", View = "views/content/apps/info/info.html", Weight = Weight - }); + }; case IMedia _: - return _mediaApp ?? (_mediaApp = new ContentApp + return _mediaApp ??= new ContentApp { Alias = "umbInfo", Name = "Info", Icon = "icon-info", View = "views/media/apps/info/info.html", Weight = Weight - }); + }; case IMember _: - return _memberApp ?? (_memberApp = new ContentApp + return _memberApp ??= new ContentApp { Alias = "umbInfo", Name = "Info", Icon = "icon-info", View = "views/member/apps/info/info.html", Weight = Weight - }); + }; default: return null; diff --git a/src/Umbraco.Core/ContentApps/ContentTypeDesignContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ContentTypeDesignContentAppFactory.cs index 673737d209..0fe482e7d4 100644 --- a/src/Umbraco.Core/ContentApps/ContentTypeDesignContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ContentTypeDesignContentAppFactory.cs @@ -9,21 +9,21 @@ namespace Umbraco.Cms.Core.ContentApps { private const int Weight = -200; - private ContentApp _contentTypeApp; + private ContentApp? _contentTypeApp; - public ContentApp GetContentAppFor(object source, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object source, IEnumerable userGroups) { switch (source) { case IContentType _: - return _contentTypeApp ?? (_contentTypeApp = new ContentApp() + return _contentTypeApp ??= new ContentApp() { Alias = "design", Name = "Design", Icon = "icon-document-dashed-line", View = "views/documentTypes/views/design/design.html", Weight = Weight - }); + }; default: return null; } diff --git a/src/Umbraco.Core/ContentApps/ContentTypeListViewContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ContentTypeListViewContentAppFactory.cs index 2433991ae5..6ddf98e132 100644 --- a/src/Umbraco.Core/ContentApps/ContentTypeListViewContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ContentTypeListViewContentAppFactory.cs @@ -9,21 +9,21 @@ namespace Umbraco.Cms.Core.ContentApps { private const int Weight = -180; - private ContentApp _contentTypeApp; + private ContentApp? _contentTypeApp; - public ContentApp GetContentAppFor(object source, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object source, IEnumerable userGroups) { switch (source) { case IContentType _: - return _contentTypeApp ?? (_contentTypeApp = new ContentApp() + return _contentTypeApp ??= new ContentApp() { Alias = "listView", Name = "List view", Icon = "icon-list", View = "views/documentTypes/views/listview/listview.html", Weight = Weight - }); + }; default: return null; } diff --git a/src/Umbraco.Core/ContentApps/ContentTypePermissionsContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ContentTypePermissionsContentAppFactory.cs index bd8b07db9d..98b82d24e7 100644 --- a/src/Umbraco.Core/ContentApps/ContentTypePermissionsContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ContentTypePermissionsContentAppFactory.cs @@ -9,21 +9,21 @@ namespace Umbraco.Cms.Core.ContentApps { private const int Weight = -160; - private ContentApp _contentTypeApp; + private ContentApp? _contentTypeApp; - public ContentApp GetContentAppFor(object source, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object source, IEnumerable userGroups) { switch (source) { case IContentType _: - return _contentTypeApp ?? (_contentTypeApp = new ContentApp() + return _contentTypeApp ??= new ContentApp() { Alias = "permissions", Name = "Permissions", Icon = "icon-keychain", View = "views/documentTypes/views/permissions/permissions.html", Weight = Weight - }); + }; default: return null; } diff --git a/src/Umbraco.Core/ContentApps/ContentTypeTemplatesContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ContentTypeTemplatesContentAppFactory.cs index d4bbac6e55..74e57d76c9 100644 --- a/src/Umbraco.Core/ContentApps/ContentTypeTemplatesContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ContentTypeTemplatesContentAppFactory.cs @@ -9,21 +9,21 @@ namespace Umbraco.Cms.Core.ContentApps { private const int Weight = -140; - private ContentApp _contentTypeApp; + private ContentApp? _contentTypeApp; - public ContentApp GetContentAppFor(object source, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object source, IEnumerable userGroups) { switch (source) { case IContentType _: - return _contentTypeApp ?? (_contentTypeApp = new ContentApp() + return _contentTypeApp ??= new ContentApp() { Alias = "templates", Name = "Templates", Icon = "icon-layout", View = "views/documentTypes/views/templates/templates.html", Weight = Weight - }); + }; default: return null; } diff --git a/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs index e945f7ffd4..d33c50499f 100644 --- a/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Core.ContentApps _propertyEditors = propertyEditors; } - public ContentApp GetContentAppFor(object o, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object o, IEnumerable userGroups) { string contentTypeAlias, entityType; int dtdId; diff --git a/src/Umbraco.Core/ContentApps/MemberEditorContentAppFactory.cs b/src/Umbraco.Core/ContentApps/MemberEditorContentAppFactory.cs index 3763b06e0b..ae5e783bbc 100644 --- a/src/Umbraco.Core/ContentApps/MemberEditorContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/MemberEditorContentAppFactory.cs @@ -10,9 +10,9 @@ namespace Umbraco.Cms.Core.ContentApps // see note on ContentApp internal const int Weight = +50; - private ContentApp _memberApp; + private ContentApp? _memberApp; - public ContentApp GetContentAppFor(object source, IEnumerable userGroups) + public ContentApp? GetContentAppFor(object source, IEnumerable userGroups) { switch (source) { diff --git a/src/Umbraco.Core/Dashboards/AccessRule.cs b/src/Umbraco.Core/Dashboards/AccessRule.cs index b1b5c37bd6..070659518e 100644 --- a/src/Umbraco.Core/Dashboards/AccessRule.cs +++ b/src/Umbraco.Core/Dashboards/AccessRule.cs @@ -6,9 +6,8 @@ public class AccessRule : IAccessRule { /// - public AccessRuleType Type { get; set; } - + public AccessRuleType Type { get; set; } = AccessRuleType.Unknown; /// - public string Value { get; set; } + public string? Value { get; set; } } } diff --git a/src/Umbraco.Core/Dashboards/DashboardSlim.cs b/src/Umbraco.Core/Dashboards/DashboardSlim.cs index 2b39c91100..9ff2b51baf 100644 --- a/src/Umbraco.Core/Dashboards/DashboardSlim.cs +++ b/src/Umbraco.Core/Dashboards/DashboardSlim.cs @@ -5,8 +5,8 @@ namespace Umbraco.Cms.Core.Dashboards [DataContract(IsReference = true)] public class DashboardSlim : IDashboardSlim { - public string Alias { get; set; } + public string? Alias { get; set; } - public string View { get; set; } + public string? View { get; set; } } } diff --git a/src/Umbraco.Core/Dashboards/IAccessRule.cs b/src/Umbraco.Core/Dashboards/IAccessRule.cs index 13d118e195..9f8c120910 100644 --- a/src/Umbraco.Core/Dashboards/IAccessRule.cs +++ b/src/Umbraco.Core/Dashboards/IAccessRule.cs @@ -13,6 +13,6 @@ /// /// Gets or sets the value for the rule. /// - string Value { get; set; } + string? Value { get; set; } } } diff --git a/src/Umbraco.Core/Dashboards/IDashboardSlim.cs b/src/Umbraco.Core/Dashboards/IDashboardSlim.cs index c85b969b83..4859f5dc84 100644 --- a/src/Umbraco.Core/Dashboards/IDashboardSlim.cs +++ b/src/Umbraco.Core/Dashboards/IDashboardSlim.cs @@ -11,12 +11,12 @@ namespace Umbraco.Cms.Core.Dashboards /// Gets the alias of the dashboard. /// [DataMember(Name = "alias")] - string Alias { get; } + string? Alias { get; } /// /// Gets the view used to render the dashboard. /// [DataMember(Name = "view")] - string View { get; } + string? View { get; } } } diff --git a/src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs index 738cfed26e..ec6669b177 100644 --- a/src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/IUmbracoBuilder.cs @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.DependencyInjection /// /// This may be null. /// - IHostingEnvironment BuilderHostingEnvironment { get; } + IHostingEnvironment? BuilderHostingEnvironment { get; } IProfiler Profiler { get; } AppCaches AppCaches { get; } diff --git a/src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs b/src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs index 8d195c56f4..fdc4e3f622 100644 --- a/src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs +++ b/src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs @@ -20,6 +20,6 @@ namespace Umbraco.Cms.Web.Common.DependencyInjection /// The service locator. /// [EditorBrowsable(EditorBrowsableState.Never)] - public static IServiceProvider Instance { get; set; } + public static IServiceProvider Instance { get; set; } = null!; // This is set doing startup and will always exists after that } } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 1af25e16e8..d5a1d7bf4b 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -58,7 +58,7 @@ namespace Umbraco.Cms.Core.DependencyInjection public ILoggerFactory BuilderLoggerFactory { get; } /// - public IHostingEnvironment BuilderHostingEnvironment { get; } + public IHostingEnvironment? BuilderHostingEnvironment { get; } public IProfiler Profiler { get; } @@ -81,7 +81,7 @@ namespace Umbraco.Cms.Core.DependencyInjection ILoggerFactory loggerFactory, IProfiler profiler, AppCaches appCaches, - IHostingEnvironment hostingEnvironment) + IHostingEnvironment? hostingEnvironment) { Services = services; Config = config; diff --git a/src/Umbraco.Core/DependencyInjection/UniqueServiceDescriptor.cs b/src/Umbraco.Core/DependencyInjection/UniqueServiceDescriptor.cs index f0fc5b14c9..239604eb52 100644 --- a/src/Umbraco.Core/DependencyInjection/UniqueServiceDescriptor.cs +++ b/src/Umbraco.Core/DependencyInjection/UniqueServiceDescriptor.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.DependencyInjection public override bool Equals(object obj) => Equals(obj as UniqueServiceDescriptor); /// - public bool Equals(UniqueServiceDescriptor other) => other != null && Lifetime == other.Lifetime && EqualityComparer.Default.Equals(ServiceType, other.ServiceType) && EqualityComparer.Default.Equals(ImplementationType, other.ImplementationType) && EqualityComparer.Default.Equals(ImplementationInstance, other.ImplementationInstance) && EqualityComparer>.Default.Equals(ImplementationFactory, other.ImplementationFactory); + public bool Equals(UniqueServiceDescriptor? other) => other != null && Lifetime == other.Lifetime && EqualityComparer.Default.Equals(ServiceType, other.ServiceType) && EqualityComparer.Default.Equals(ImplementationType, other.ImplementationType) && EqualityComparer.Default.Equals(ImplementationInstance, other.ImplementationInstance) && EqualityComparer?>.Default.Equals(ImplementationFactory, other.ImplementationFactory); /// public override int GetHashCode() @@ -36,9 +36,9 @@ namespace Umbraco.Cms.Core.DependencyInjection int hashCode = 493849952; hashCode = (hashCode * -1521134295) + Lifetime.GetHashCode(); hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(ServiceType); - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(ImplementationType); - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(ImplementationInstance); - hashCode = (hashCode * -1521134295) + EqualityComparer>.Default.GetHashCode(ImplementationFactory); + hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(ImplementationType); + hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(ImplementationInstance); + hashCode = (hashCode * -1521134295) + EqualityComparer?>.Default.GetHashCode(ImplementationFactory); return hashCode; } } diff --git a/src/Umbraco.Core/Deploy/ArtifactBase.cs b/src/Umbraco.Core/Deploy/ArtifactBase.cs index 61bf7b2abf..b0cd0f6753 100644 --- a/src/Umbraco.Core/Deploy/ArtifactBase.cs +++ b/src/Umbraco.Core/Deploy/ArtifactBase.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.Deploy public abstract class ArtifactBase : IArtifact where TUdi : Udi { - protected ArtifactBase(TUdi udi, IEnumerable dependencies = null) + protected ArtifactBase(TUdi udi, IEnumerable? dependencies = null) { Udi = udi ?? throw new ArgumentNullException("udi"); Name = Udi.ToString(); @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Deploy private readonly Lazy _checksum; - private IEnumerable _dependencies; + private IEnumerable? _dependencies; protected abstract string GetChecksum(); @@ -43,7 +43,7 @@ namespace Umbraco.Cms.Core.Deploy /// public bool ShouldSerializeChecksum() => false; - public IEnumerable Dependencies + public IEnumerable? Dependencies { get => _dependencies; set => _dependencies = value.OrderBy(x => x.Udi); @@ -53,6 +53,6 @@ namespace Umbraco.Cms.Core.Deploy public string Name { get; set; } - public string Alias { get; set; } + public string? Alias { get; set; } } } diff --git a/src/Umbraco.Core/Deploy/ArtifactDeployState.cs b/src/Umbraco.Core/Deploy/ArtifactDeployState.cs index edd958c346..0da78292f2 100644 --- a/src/Umbraco.Core/Deploy/ArtifactDeployState.cs +++ b/src/Umbraco.Core/Deploy/ArtifactDeployState.cs @@ -24,7 +24,7 @@ /// /// Gets the artifact. /// - public IArtifact Artifact + public IArtifact? Artifact { get { return GetArtifactAsIArtifact(); } } @@ -35,12 +35,12 @@ /// The artifact, as an . /// This is because classes that inherit from this class cannot override the Artifact property /// with a property that specializes the return type, and so they need to 'new' the property. - protected abstract IArtifact GetArtifactAsIArtifact(); + protected abstract IArtifact? GetArtifactAsIArtifact(); /// /// Gets or sets the service connector in charge of deploying the artifact. /// - public IServiceConnector Connector { get; set; } + public IServiceConnector? Connector { get; set; } /// /// Gets or sets the next pass number. diff --git a/src/Umbraco.Core/Deploy/ArtifactDeployStateOfTArtifactTEntity.cs b/src/Umbraco.Core/Deploy/ArtifactDeployStateOfTArtifactTEntity.cs index b0d7dd56b8..bb9a06274e 100644 --- a/src/Umbraco.Core/Deploy/ArtifactDeployStateOfTArtifactTEntity.cs +++ b/src/Umbraco.Core/Deploy/ArtifactDeployStateOfTArtifactTEntity.cs @@ -32,15 +32,15 @@ /// /// Gets or sets the artifact. /// - public new TArtifact Artifact { get; set; } + public new TArtifact? Artifact { get; set; } /// /// Gets or sets the entity. /// - public TEntity Entity { get; set; } + public TEntity? Entity { get; set; } /// - protected sealed override IArtifact GetArtifactAsIArtifact() + protected sealed override IArtifact? GetArtifactAsIArtifact() { return Artifact; } diff --git a/src/Umbraco.Core/Deploy/ArtifactSignature.cs b/src/Umbraco.Core/Deploy/ArtifactSignature.cs index e0e4dab1ac..629d65593c 100644 --- a/src/Umbraco.Core/Deploy/ArtifactSignature.cs +++ b/src/Umbraco.Core/Deploy/ArtifactSignature.cs @@ -5,7 +5,7 @@ namespace Umbraco.Cms.Core.Deploy { public sealed class ArtifactSignature : IArtifactSignature { - public ArtifactSignature(Udi udi, string checksum, IEnumerable dependencies = null) + public ArtifactSignature(Udi udi, string checksum, IEnumerable? dependencies = null) { Udi = udi; Checksum = checksum; diff --git a/src/Umbraco.Core/Deploy/Difference.cs b/src/Umbraco.Core/Deploy/Difference.cs index f45f14f8e6..be0c086c0b 100644 --- a/src/Umbraco.Core/Deploy/Difference.cs +++ b/src/Umbraco.Core/Deploy/Difference.cs @@ -2,7 +2,7 @@ { public class Difference { - public Difference(string title, string text = null, string category = null) + public Difference(string title, string? text = null, string? category = null) { Title = title; Text = text; @@ -10,8 +10,8 @@ } public string Title { get; set; } - public string Text { get; set; } - public string Category { get; set; } + public string? Text { get; set; } + public string? Category { get; set; } public override string ToString() { diff --git a/src/Umbraco.Core/Deploy/IArtifact.cs b/src/Umbraco.Core/Deploy/IArtifact.cs index 7712e53afa..5eb9c079f3 100644 --- a/src/Umbraco.Core/Deploy/IArtifact.cs +++ b/src/Umbraco.Core/Deploy/IArtifact.cs @@ -6,6 +6,6 @@ public interface IArtifact : IArtifactSignature { string Name { get; } - string Alias { get; } + string? Alias { get; } } } diff --git a/src/Umbraco.Core/Deploy/IArtifactSignature.cs b/src/Umbraco.Core/Deploy/IArtifactSignature.cs index ae856866d9..edd4d1ad42 100644 --- a/src/Umbraco.Core/Deploy/IArtifactSignature.cs +++ b/src/Umbraco.Core/Deploy/IArtifactSignature.cs @@ -36,6 +36,6 @@ namespace Umbraco.Cms.Core.Deploy /// /// Gets the dependencies of this artifact. /// - IEnumerable Dependencies { get; } + IEnumerable? Dependencies { get; } } } diff --git a/src/Umbraco.Core/Deploy/IServiceConnector.cs b/src/Umbraco.Core/Deploy/IServiceConnector.cs index 3a57f722cf..b28989f5de 100644 --- a/src/Umbraco.Core/Deploy/IServiceConnector.cs +++ b/src/Umbraco.Core/Deploy/IServiceConnector.cs @@ -78,7 +78,7 @@ namespace Umbraco.Cms.Core.Deploy /// A collection of differences to append to, if not null. /// A boolean value indicating whether the artifacts are identical. /// ServiceConnectorBase{TArtifact} provides a very basic default implementation. - bool Compare(IArtifact art1, IArtifact art2, ICollection differences = null); + bool Compare(IArtifact art1, IArtifact art2, ICollection? differences = null); } } diff --git a/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs b/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs index 7cb97ec57c..c5d8d01449 100644 --- a/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs +++ b/src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs @@ -120,7 +120,7 @@ namespace Umbraco.Cms.Core.Editors return Attempt.Succeed(); } - private Attempt AuthorizePath(IUser currentUser, IEnumerable startContentIds, IEnumerable startMediaIds) + private Attempt AuthorizePath(IUser currentUser, IEnumerable? startContentIds, IEnumerable? startMediaIds) { if (startContentIds != null) { diff --git a/src/Umbraco.Core/Enum.cs b/src/Umbraco.Core/Enum.cs index 8e2beca025..90de399300 100644 --- a/src/Umbraco.Core/Enum.cs +++ b/src/Umbraco.Core/Enum.cs @@ -64,7 +64,7 @@ namespace Umbraco.Cms.Core return ValueToName.Values.ToArray(); } - public static string GetName(T value) + public static string? GetName(T value) { return ValueToName.TryGetValue(value, out var name) ? name : null; } diff --git a/src/Umbraco.Core/Events/EventDefinition.cs b/src/Umbraco.Core/Events/EventDefinition.cs index 9502fac332..0b28900ada 100644 --- a/src/Umbraco.Core/Events/EventDefinition.cs +++ b/src/Umbraco.Core/Events/EventDefinition.cs @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.Events private readonly object _sender; private readonly EventArgs _args; - public EventDefinition(EventHandler trackedEvent, object sender, EventArgs args, string eventName = null) + public EventDefinition(EventHandler trackedEvent, object sender, EventArgs args, string? eventName = null) : base(sender, args, eventName) { _trackedEvent = trackedEvent; diff --git a/src/Umbraco.Core/Events/EventDefinitionBase.cs b/src/Umbraco.Core/Events/EventDefinitionBase.cs index 3fc6040c71..7dfd8a647c 100644 --- a/src/Umbraco.Core/Events/EventDefinitionBase.cs +++ b/src/Umbraco.Core/Events/EventDefinitionBase.cs @@ -6,7 +6,7 @@ namespace Umbraco.Cms.Core.Events { public abstract class EventDefinitionBase : IEventDefinition, IEquatable { - protected EventDefinitionBase(object sender, object args, string eventName = null) + protected EventDefinitionBase(object sender, object args, string? eventName = null) { Sender = sender ?? throw new ArgumentNullException(nameof(sender)); Args = args ?? throw new ArgumentNullException(nameof(args)); @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.Events public object Sender { get; } public object Args { get; } - public string EventName { get; } + public string? EventName { get; } public abstract void RaiseEvent(); diff --git a/src/Umbraco.Core/Events/IEventDispatcher.cs b/src/Umbraco.Core/Events/IEventDispatcher.cs index 84e522761c..bef94b6d4a 100644 --- a/src/Umbraco.Core/Events/IEventDispatcher.cs +++ b/src/Umbraco.Core/Events/IEventDispatcher.cs @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.Events /// The optional name of the event. /// A value indicating whether the cancelable event was cancelled. /// See general remarks on the interface. - bool DispatchCancelable(EventHandler eventHandler, object sender, CancellableEventArgs args, string name = null); + bool DispatchCancelable(EventHandler eventHandler, object sender, CancellableEventArgs args, string? name = null); /// /// Dispatches a cancelable event. @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Events /// The optional name of the event. /// A value indicating whether the cancelable event was cancelled. /// See general remarks on the interface. - bool DispatchCancelable(EventHandler eventHandler, object sender, TArgs args, string name = null) + bool DispatchCancelable(EventHandler eventHandler, object sender, TArgs args, string? name = null) where TArgs : CancellableEventArgs; /// @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Events /// The optional name of the event. /// A value indicating whether the cancelable event was cancelled. /// See general remarks on the interface. - bool DispatchCancelable(TypedEventHandler eventHandler, TSender sender, TArgs args, string name = null) + bool DispatchCancelable(TypedEventHandler eventHandler, TSender sender, TArgs args, string? name = null) where TArgs : CancellableEventArgs; /// @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Events /// The event data. /// The optional name of the event. /// See general remarks on the interface. - void Dispatch(EventHandler eventHandler, object sender, EventArgs args, string name = null); + void Dispatch(EventHandler eventHandler, object sender, EventArgs args, string? name = null); /// /// Dispatches an event. @@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Events /// The event data. /// The optional name of the event. /// See general remarks on the interface. - void Dispatch(EventHandler eventHandler, object sender, TArgs args, string name = null); + void Dispatch(EventHandler eventHandler, object sender, TArgs args, string? name = null); /// /// Dispatches an event. @@ -81,7 +81,7 @@ namespace Umbraco.Cms.Core.Events /// The event data. /// The optional name of the event. /// See general remarks on the interface. - void Dispatch(TypedEventHandler eventHandler, TSender sender, TArgs args, string name = null); + void Dispatch(TypedEventHandler eventHandler, TSender sender, TArgs args, string? name = null); /// /// Notifies the dispatcher that the scope is exiting. diff --git a/src/Umbraco.Core/Extensions/ContentExtensions.cs b/src/Umbraco.Core/Extensions/ContentExtensions.cs index b9d1c0b7b4..7f34446f61 100644 --- a/src/Umbraco.Core/Extensions/ContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/ContentExtensions.cs @@ -33,9 +33,9 @@ namespace Umbraco.Extensions this IContentBase content, string propertyTypeAlias, MediaUrlGeneratorCollection mediaUrlGenerators, - out string mediaFilePath, - string culture = null, - string segment = null) + out string? mediaFilePath, + string? culture = null, + string? segment = null) { if (!content.Properties.TryGetValue(propertyTypeAlias, out IProperty property)) { @@ -141,7 +141,7 @@ namespace Umbraco.Extensions /// /// Gets the current status of the Content /// - public static ContentStatus GetStatus(this IContent content, ContentScheduleCollection contentSchedule, string culture = null) + public static ContentStatus GetStatus(this IContent content, ContentScheduleCollection contentSchedule, string? culture = null) { if (content.Trashed) return ContentStatus.Trashed; @@ -151,11 +151,11 @@ namespace Umbraco.Extensions else if (culture.IsNullOrWhiteSpace()) throw new ArgumentNullException($"{nameof(culture)} cannot be null or empty"); - var expires = contentSchedule.GetSchedule(culture, ContentScheduleAction.Expire); + var expires = contentSchedule.GetSchedule(culture!, ContentScheduleAction.Expire); if (expires != null && expires.Any(x => x.Date > DateTime.MinValue && DateTime.Now > x.Date)) return ContentStatus.Expired; - var release = contentSchedule.GetSchedule(culture, ContentScheduleAction.Release); + var release = contentSchedule.GetSchedule(culture!, ContentScheduleAction.Release); if (release != null && release.Any(x => x.Date > DateTime.MinValue && x.Date > DateTime.Now)) return ContentStatus.AwaitingRelease; @@ -258,8 +258,8 @@ namespace Umbraco.Extensions string propertyTypeAlias, string filename, Stream filestream, - string culture = null, - string segment = null) + string? culture = null, + string? segment = null) { if (filename == null || filestream == null) return; @@ -280,18 +280,18 @@ namespace Umbraco.Extensions string propertyTypeAlias, string filename, Stream filestream, - string culture = null, - string segment = null) + string? culture = null, + string? segment = null) { var property = GetProperty(content, contentTypeBaseServiceProvider, propertyTypeAlias); // Fixes https://github.com/umbraco/Umbraco-CMS/issues/3937 - Assigning a new file to an // existing IMedia with extension SetValue causes exception 'Illegal characters in path' - string oldpath = null; + string? oldpath = null; - if (content.TryGetMediaPath(property.Alias, mediaUrlGenerators, out string mediaFilePath, culture, segment)) + if (content.TryGetMediaPath(property.Alias, mediaUrlGenerators, out string? mediaFilePath, culture, segment)) { - oldpath = mediaFileManager.FileSystem.GetRelativePath(mediaFilePath); + oldpath = mediaFileManager.FileSystem.GetRelativePath(mediaFilePath!); } var filepath = mediaFileManager.StoreFile(content, property.PropertyType, filename, filestream, oldpath); diff --git a/src/Umbraco.Core/Extensions/DataTableExtensions.cs b/src/Umbraco.Core/Extensions/DataTableExtensions.cs index 5221fff3fa..4594709407 100644 --- a/src/Umbraco.Core/Extensions/DataTableExtensions.cs +++ b/src/Umbraco.Core/Extensions/DataTableExtensions.cs @@ -27,7 +27,7 @@ namespace Umbraco.Extensions public static DataTable GenerateDataTable( string tableAlias, Func>> getHeaders, - Func>, IEnumerable>>>> rowData) + Func>, IEnumerable>>>> rowData) { var dt = new DataTable(tableAlias); @@ -60,9 +60,9 @@ namespace Umbraco.Extensions /// /// This is for legacy code, I didn't want to go creating custom classes for these /// - public static List>, IEnumerable>>> CreateTableData() + public static List>, IEnumerable>>> CreateTableData() { - return new List>, IEnumerable>>>(); + return new List>, IEnumerable>>>(); } /// @@ -75,11 +75,11 @@ namespace Umbraco.Extensions /// This is for legacy code, I didn't want to go creating custom classes for these /// public static void AddRowData( - List>, IEnumerable>>> rowData, - IEnumerable> standardVals, - IEnumerable> userVals) + List>, IEnumerable>>> rowData, + IEnumerable> standardVals, + IEnumerable> userVals) { - rowData.Add(new System.Tuple>, IEnumerable>>( + rowData.Add(new System.Tuple>, IEnumerable>>( standardVals, userVals )); @@ -95,8 +95,8 @@ namespace Umbraco.Extensions private static void PopulateRow( this DataTable dt, IDictionary aliasesToNames, - IEnumerable> standardVals, - IEnumerable> userPropertyVals) + IEnumerable> standardVals, + IEnumerable> userPropertyVals) { var dr = dt.NewRow(); foreach (var r in standardVals) diff --git a/src/Umbraco.Core/Extensions/DictionaryExtensions.cs b/src/Umbraco.Core/Extensions/DictionaryExtensions.cs index b524961f7e..6227d506f3 100644 --- a/src/Umbraco.Core/Extensions/DictionaryExtensions.cs +++ b/src/Umbraco.Core/Extensions/DictionaryExtensions.cs @@ -190,7 +190,7 @@ namespace Umbraco.Extensions /// The key. /// The default value. /// - public static TVal GetValue(this IDictionary d, TKey key, TVal defaultValue = default(TVal)) + public static TVal? GetValue(this IDictionary d, TKey key, TVal? defaultValue = default(TVal)) { if (d.ContainsKey(key)) { @@ -206,13 +206,7 @@ namespace Umbraco.Extensions /// /// public static string GetValueAsString(this IDictionary d, TKey key) - { - if (d.ContainsKey(key)) - { - return d[key].ToString(); - } - return String.Empty; - } + => d.ContainsKey(key) ? d[key]!.ToString() : string.Empty; /// /// Returns the value of the key value based on the key as it's string value, if the key is not found or is an empty string, then the provided default value is returned @@ -225,7 +219,7 @@ namespace Umbraco.Extensions { if (d.ContainsKey(key)) { - var value = d[key].ToString(); + var value = d[key]!.ToString(); if (value != string.Empty) return value; } @@ -266,10 +260,8 @@ namespace Umbraco.Extensions /// The key. /// The type /// The entry - public static TValue GetValueIgnoreCase(this IDictionary dictionary, string key) - { - return dictionary.GetValueIgnoreCase(key, default(TValue)); - } + public static TValue? GetValueIgnoreCase(this IDictionary dictionary, string key) + => dictionary!.GetValueIgnoreCase(key, default(TValue)); /// The get entry ignore case. /// The dictionary. diff --git a/src/Umbraco.Core/Extensions/EnumerableExtensions.cs b/src/Umbraco.Core/Extensions/EnumerableExtensions.cs index 1833a59b1e..6120c569d4 100644 --- a/src/Umbraco.Core/Extensions/EnumerableExtensions.cs +++ b/src/Umbraco.Core/Extensions/EnumerableExtensions.cs @@ -223,9 +223,9 @@ namespace Umbraco.Extensions /// The coll. /// /// - public static IEnumerable WhereNotNull(this IEnumerable coll) where T : class + public static IEnumerable WhereNotNull(this IEnumerable coll) where T : class { - return coll.Where(x => x != null); + return coll.Where(x => x != null)!; } public static IEnumerable ForAllThatAre(this IEnumerable sequence, Action projection) diff --git a/src/Umbraco.Core/Extensions/IfExtensions.cs b/src/Umbraco.Core/Extensions/IfExtensions.cs index a9de084d08..b4ef60ea57 100644 --- a/src/Umbraco.Core/Extensions/IfExtensions.cs +++ b/src/Umbraco.Core/Extensions/IfExtensions.cs @@ -42,11 +42,9 @@ namespace Umbraco.Extensions /// The action. /// The default value. /// - public static TResult IfNotNull(this TItem item, Func action, TResult defaultValue = default(TResult)) + public static TResult? IfNotNull(this TItem? item, Func action, TResult? defaultValue = default(TResult)) where TItem : class - { - return item != null ? action(item) : defaultValue; - } + => item != null ? action(item) : defaultValue; /// /// Checks if the value is null, if it is it returns the value specified, otherwise returns the non-null value @@ -55,11 +53,8 @@ namespace Umbraco.Extensions /// /// /// - public static TItem IfNull(this TItem item, Func action) + public static TItem IfNull(this TItem? item, Func action) where TItem : class - { - return item ?? action(item); - } - + => item ?? action(item!); } } diff --git a/src/Umbraco.Core/Extensions/ObjectExtensions.cs b/src/Umbraco.Core/Extensions/ObjectExtensions.cs index d666046e4b..fae727b8f3 100644 --- a/src/Umbraco.Core/Extensions/ObjectExtensions.cs +++ b/src/Umbraco.Core/Extensions/ObjectExtensions.cs @@ -75,7 +75,7 @@ namespace Umbraco.Extensions /// The type to convert to /// The input. /// The - public static Attempt TryConvertTo(this object input) + public static Attempt TryConvertTo(this object? input) { Attempt result = TryConvertTo(input, typeof(T)); diff --git a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs index 197f6f6d63..b241316242 100644 --- a/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedContentExtensions.cs @@ -25,18 +25,23 @@ namespace Umbraco.Extensions /// The content item. /// /// The specific culture to get the name for. If null is used the current culture is used (Default is null). - public static string Name(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static string? Name(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + // invariant has invariant value (whatever the requested culture) if (!content.ContentType.VariesByCulture()) - return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.Name : null; + return content.Cultures.TryGetValue(string.Empty, out var invariantInfos) ? invariantInfos.Name : null; // handle context culture for variant if (culture == null) - culture = variationContextAccessor?.VariationContext?.Culture ?? ""; + culture = variationContextAccessor?.VariationContext?.Culture ?? string.Empty; // get - return culture != "" && content.Cultures.TryGetValue(culture, out var infos) ? infos.Name : null; + return culture != string.Empty && content.Cultures.TryGetValue(culture, out var infos) ? infos.Name : null; } #endregion @@ -49,8 +54,13 @@ namespace Umbraco.Extensions /// The content item. /// /// The specific culture to get the URL segment for. If null is used the current culture is used (Default is null). - public static string UrlSegment(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static string? UrlSegment(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + // invariant has invariant value (whatever the requested culture) if (!content.ContentType.VariesByCulture()) return content.Cultures.TryGetValue("", out var invariantInfos) ? invariantInfos.UrlSegment : null; @@ -71,8 +81,15 @@ namespace Umbraco.Extensions /// Determines whether the content has a culture. /// /// Culture is case-insensitive. - public static bool HasCulture(this IPublishedContent content, string culture) - => content.Cultures.ContainsKey(culture ?? string.Empty); + public static bool HasCulture(this IPublishedContent content, string? culture) + { + if (content == null) + { + throw new ArgumentNullException(nameof(content)); + } + + return content.Cultures.ContainsKey(culture ?? string.Empty); + } /// /// Determines whether the content is invariant, or has a culture. @@ -87,7 +104,7 @@ namespace Umbraco.Extensions /// The content items. /// /// The specific culture to filter for. If null is used the current culture is used. (Default is null). - internal static IEnumerable WhereIsInvariantOrHasCulture(this IEnumerable contents, IVariationContextAccessor variationContextAccessor, string culture = null) + internal static IEnumerable WhereIsInvariantOrHasCulture(this IEnumerable contents, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { if (contents == null) throw new ArgumentNullException(nameof(contents)); @@ -104,7 +121,7 @@ namespace Umbraco.Extensions /// The content item. /// /// The specific culture to get the name for. If null is used the current culture is used (Default is null). - public static DateTime CultureDate(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static DateTime CultureDate(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { // invariant has invariant value (whatever the requested culture) if (!content.ContentType.VariesByCulture()) @@ -196,7 +213,7 @@ namespace Umbraco.Extensions /// Optional fallback strategy. /// A value indicating whether the content has a value for the property identified by the alias. /// Returns true if HasValue is true, or a fallback strategy can provide a value. - public static bool HasValue(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default) + public static bool HasValue(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string? culture = null, string? segment = null, Fallback fallback = default) { var property = content.GetProperty(alias); @@ -219,7 +236,7 @@ namespace Umbraco.Extensions /// Optional fallback strategy. /// The default value. /// The value of the content's property identified by the alias, if it exists, otherwise a default value. - public static object Value(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default) + public static object? Value(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string? culture = null, string? segment = null, Fallback fallback = default, object? defaultValue = default) { var property = content.GetProperty(alias); @@ -248,7 +265,7 @@ namespace Umbraco.Extensions /// Optional fallback strategy. /// The default value. /// The value of the content's property identified by the alias, converted to the specified type. - public static T Value(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default) + public static T? Value(this IPublishedContent content, IPublishedValueFallback publishedValueFallback, string alias, string? culture = null, string? segment = null, Fallback fallback = default, T? defaultValue = default) { var property = content.GetProperty(alias); @@ -612,7 +629,7 @@ namespace Umbraco.Extensions return content.AncestorsOrSelf(maxLevel).FirstOrDefault(); } - public static IEnumerable AncestorsOrSelf(this IPublishedContent content, bool orSelf, Func func) + public static IEnumerable AncestorsOrSelf(this IPublishedContent content, bool orSelf, Func? func) { var ancestorsOrSelf = content.EnumerateAncestors(orSelf); return func == null ? ancestorsOrSelf : ancestorsOrSelf.Where(func); @@ -705,7 +722,7 @@ namespace Umbraco.Extensions /// /// This can be useful in order to return all nodes in an entire site by a type when combined with TypedContentAtRoot /// - public static IEnumerable DescendantsOrSelfOfType(this IEnumerable parentNodes, IVariationContextAccessor variationContextAccessor, string docTypeAlias, string culture = null) + public static IEnumerable DescendantsOrSelfOfType(this IEnumerable parentNodes, IVariationContextAccessor variationContextAccessor, string docTypeAlias, string? culture = null) { return parentNodes.SelectMany(x => x.DescendantsOrSelfOfType(variationContextAccessor, docTypeAlias, culture)); } @@ -720,7 +737,7 @@ namespace Umbraco.Extensions /// /// This can be useful in order to return all nodes in an entire site by a type when combined with TypedContentAtRoot /// - public static IEnumerable DescendantsOrSelf(this IEnumerable parentNodes, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IEnumerable DescendantsOrSelf(this IEnumerable parentNodes, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return parentNodes.SelectMany(x => x.DescendantsOrSelf(variationContextAccessor, culture)); @@ -746,120 +763,120 @@ namespace Umbraco.Extensions // - the relative order of siblings is the order in which they occur in the children property of their parent node. // - children and descendants occur before following siblings. - public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { return content.DescendantsOrSelf(variationContextAccessor, false, null, culture); } - public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) { return content.DescendantsOrSelf(variationContextAccessor, false, p => p.Level >= level, culture); } - public static IEnumerable DescendantsOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string culture = null) + public static IEnumerable DescendantsOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { return content.DescendantsOrSelf(variationContextAccessor, false, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); } - public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return content.Descendants(variationContextAccessor, culture).OfType(); } - public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) where T : class, IPublishedContent { return content.Descendants(variationContextAccessor, level, culture).OfType(); } - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { return content.DescendantsOrSelf(variationContextAccessor, true, null, culture); } - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) { return content.DescendantsOrSelf(variationContextAccessor, true, p => p.Level >= level, culture); } - public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string culture = null) + public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string ?culture = null) { return content.DescendantsOrSelf(variationContextAccessor, true, p => p.ContentType.Alias.InvariantEquals(contentTypeAlias), culture); } - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return content.DescendantsOrSelf(variationContextAccessor, culture).OfType(); } - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) where T : class, IPublishedContent { return content.DescendantsOrSelf(variationContextAccessor, level, culture).OfType(); } - public static IPublishedContent Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IPublishedContent Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { return content.Children(variationContextAccessor, culture).FirstOrDefault(); } - public static IPublishedContent Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static IPublishedContent Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) { return content.EnumerateDescendants(variationContextAccessor, false, culture).FirstOrDefault(x => x.Level == level); } - public static IPublishedContent DescendantOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string culture = null) + public static IPublishedContent DescendantOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { return content.EnumerateDescendants(variationContextAccessor, false, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)); } - public static T Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static T? Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return content.EnumerateDescendants(variationContextAccessor, false, culture).FirstOrDefault(x => x is T) as T; } - public static T Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static T? Descendant(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) where T : class, IPublishedContent { return content.Descendant(variationContextAccessor, level, culture) as T; } - public static IPublishedContent DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IPublishedContent DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { return content; } - public static IPublishedContent DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static IPublishedContent DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) { return content.EnumerateDescendants(variationContextAccessor, true, culture).FirstOrDefault(x => x.Level == level); } - public static IPublishedContent DescendantOrSelfOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string culture = null) + public static IPublishedContent DescendantOrSelfOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { return content.EnumerateDescendants(variationContextAccessor, true, culture).FirstOrDefault(x => x.ContentType.Alias.InvariantEquals(contentTypeAlias)); } - public static T DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static T? DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return content.EnumerateDescendants(variationContextAccessor, true, culture).FirstOrDefault(x => x is T) as T; } - public static T DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string culture = null) + public static T? DescendantOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, int level, string? culture = null) where T : class, IPublishedContent { return content.DescendantOrSelf(variationContextAccessor, level, culture) as T; } - internal static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, bool orSelf, Func func, string culture = null) + internal static IEnumerable DescendantsOrSelf(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, bool orSelf, Func? func, string? culture = null) { return content.EnumerateDescendants(variationContextAccessor, orSelf, culture).Where(x => func == null || func(x)); } - internal static IEnumerable EnumerateDescendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, bool orSelf, string culture = null) + internal static IEnumerable EnumerateDescendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, bool orSelf, string? culture = null) { if (content == null) throw new ArgumentNullException(nameof(content)); if (orSelf) yield return content; @@ -868,7 +885,7 @@ namespace Umbraco.Extensions yield return desc; } - internal static IEnumerable EnumerateDescendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + internal static IEnumerable EnumerateDescendants(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { yield return content; @@ -903,7 +920,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) @@ -926,7 +943,7 @@ 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); } @@ -939,7 +956,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); } @@ -955,13 +972,13 @@ 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(); } - public static IPublishedContent FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static IPublishedContent FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) { return content.Children(variationContextAccessor, culture).FirstOrDefault(); } @@ -969,28 +986,28 @@ namespace Umbraco.Extensions /// /// Gets the first child of the content, of a given content type. /// - public static IPublishedContent FirstChildOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string culture = null) + public static IPublishedContent FirstChildOfType(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string contentTypeAlias, string? culture = null) { return content.ChildrenOfType(variationContextAccessor, contentTypeAlias, culture).FirstOrDefault(); } - public static IPublishedContent FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string culture = null) + public static IPublishedContent FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string? culture = null) { return content.Children(variationContextAccessor, predicate, culture).FirstOrDefault(); } - public static IPublishedContent FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Guid uniqueId, string culture = null) + public static IPublishedContent FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Guid uniqueId, string? culture = null) { return content.Children(variationContextAccessor, x => x.Key == uniqueId, culture).FirstOrDefault(); } - public static T FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string culture = null) + public static T FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, string? culture = null) where T : class, IPublishedContent { return content.Children(variationContextAccessor, culture).FirstOrDefault(); } - public static T FirstChild(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, Func predicate, string culture = null) + 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); @@ -1008,7 +1025,7 @@ namespace Umbraco.Extensions /// The content type. /// The content. /// The parent of content, of the given content type, else null. - public static T Parent(this IPublishedContent content) + public static T? Parent(this IPublishedContent content) where T : class, IPublishedContent { if (content == null) throw new ArgumentNullException(nameof(content)); @@ -1030,7 +1047,7 @@ 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); } @@ -1047,7 +1064,7 @@ 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); } @@ -1064,7 +1081,7 @@ 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); @@ -1078,7 +1095,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) @@ -1094,7 +1111,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) @@ -1110,7 +1127,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 @@ -1158,13 +1175,13 @@ namespace Umbraco.Extensions #region Writer and creator - public static string GetCreatorName(this IPublishedContent content, IUserService userService) + public static string? GetCreatorName(this IPublishedContent content, IUserService userService) { var user = userService.GetProfileById(content.CreatorId); return user?.Name; } - public static string GetWriterName(this IPublishedContent content, IUserService userService) + public static string? GetWriterName(this IPublishedContent content, IUserService userService) { var user = userService.GetProfileById(content.WriterId); return user?.Name; @@ -1186,7 +1203,7 @@ namespace Umbraco.Extensions /// if any. In addition, when the content type is multi-lingual, this is the url for the /// specified culture. Otherwise, it is the invariant url. /// - public static string Url(this IPublishedContent content, IPublishedUrlProvider publishedUrlProvider, string culture = null, UrlMode mode = UrlMode.Default) + public static string Url(this IPublishedContent content, IPublishedUrlProvider publishedUrlProvider, string? culture = null, UrlMode mode = UrlMode.Default) { if (publishedUrlProvider == null) throw new InvalidOperationException("Cannot resolve a Url when Current.UmbracoContext.UrlProvider is null."); @@ -1223,7 +1240,7 @@ namespace Umbraco.Extensions public static DataTable ChildrenAsTable(this IPublishedContent content, IVariationContextAccessor variationContextAccessor, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, - IPublishedUrlProvider publishedUrlProvider, string contentTypeAliasFilter = "", string culture = null) + IPublishedUrlProvider publishedUrlProvider, string contentTypeAliasFilter = "", string? culture = null) => GenerateDataTable(content, variationContextAccessor, contentTypeService, mediaTypeService, memberTypeService, publishedUrlProvider, contentTypeAliasFilter, culture); /// @@ -1241,7 +1258,7 @@ namespace Umbraco.Extensions private static DataTable GenerateDataTable(IPublishedContent content, IVariationContextAccessor variationContextAccessor, IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService, - IPublishedUrlProvider publishedUrlProvider, string contentTypeAliasFilter = "", string culture = null) + IPublishedUrlProvider publishedUrlProvider, string contentTypeAliasFilter = "", string? culture = null) { var firstNode = contentTypeAliasFilter.IsNullOrWhiteSpace() ? content.Children(variationContextAccessor, culture).Any() @@ -1271,7 +1288,7 @@ namespace Umbraco.Extensions 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) }, @@ -1283,7 +1300,7 @@ namespace Umbraco.Extensions { "Url", n.Url(publishedUrlProvider) } }; - var userVals = new Dictionary(); + 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... @@ -1302,7 +1319,7 @@ namespace Umbraco.Extensions #region PropertyAliasesAndNames - private static Func> _getPropertyAliasesAndNames; + private static Func>? _getPropertyAliasesAndNames; /// /// This is used only for unit tests to set the delegate to look up aliases/names dictionary of a content type diff --git a/src/Umbraco.Core/Extensions/PublishedElementExtensions.cs b/src/Umbraco.Core/Extensions/PublishedElementExtensions.cs index 265a2aae77..17133cddaa 100644 --- a/src/Umbraco.Core/Extensions/PublishedElementExtensions.cs +++ b/src/Umbraco.Core/Extensions/PublishedElementExtensions.cs @@ -66,7 +66,7 @@ namespace Umbraco.Extensions /// Gets a value indicating whether the content has a value for a property identified by its alias. /// /// Returns true if GetProperty(alias) is not null and GetProperty(alias).HasValue is true. - public static bool HasValue(this IPublishedElement content, string alias, string culture = null, string segment = null) + public static bool HasValue(this IPublishedElement content, string alias, string? culture = null, string? segment = null) { var prop = content.GetProperty(alias); return prop != null && prop.HasValue(culture, segment); @@ -93,7 +93,7 @@ namespace Umbraco.Extensions /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter. /// The alias is case-insensitive. /// - public static object Value(this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default) + public static object? Value(this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string? culture = null, string? segment = null, Fallback fallback = default, object? defaultValue = default) { var property = content.GetProperty(alias); @@ -132,7 +132,7 @@ namespace Umbraco.Extensions /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter. /// The alias is case-insensitive. /// - public static T Value(this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default) + public static T? Value(this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string? culture = null, string? segment = null, Fallback fallback = default, T? defaultValue = default) { var property = content.GetProperty(alias); @@ -198,7 +198,7 @@ namespace Umbraco.Extensions /// if any. In addition, when the content type is multi-lingual, this is the url for the /// specified culture. Otherwise, it is the invariant url. /// - public static string MediaUrl(this IPublishedContent content, IPublishedUrlProvider publishedUrlProvider, string culture = null, UrlMode mode = UrlMode.Default, string propertyAlias = Constants.Conventions.Media.File) + public static string MediaUrl(this IPublishedContent content, IPublishedUrlProvider publishedUrlProvider, string? culture = null, UrlMode mode = UrlMode.Default, string propertyAlias = Constants.Conventions.Media.File) { if (publishedUrlProvider == null) throw new ArgumentNullException(nameof(publishedUrlProvider)); diff --git a/src/Umbraco.Core/Extensions/PublishedPropertyExtension.cs b/src/Umbraco.Core/Extensions/PublishedPropertyExtension.cs index a36942862a..f9bca6effd 100644 --- a/src/Umbraco.Core/Extensions/PublishedPropertyExtension.cs +++ b/src/Umbraco.Core/Extensions/PublishedPropertyExtension.cs @@ -11,7 +11,7 @@ namespace Umbraco.Extensions { #region Value - public static object Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default) + public static object Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string? culture = null, string? segment = null, Fallback fallback = default, object? defaultValue = default) { if (property.HasValue(culture, segment)) return property.GetValue(culture, segment); @@ -25,7 +25,7 @@ namespace Umbraco.Extensions #region Value - public static T Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default) + public static T? Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string? culture = null, string? segment = null, Fallback fallback = default, T? defaultValue = default) { if (property.HasValue(culture, segment)) { diff --git a/src/Umbraco.Core/Extensions/StringExtensions.cs b/src/Umbraco.Core/Extensions/StringExtensions.cs index 7a9dc53ed0..69ccda66d5 100644 --- a/src/Umbraco.Core/Extensions/StringExtensions.cs +++ b/src/Umbraco.Core/Extensions/StringExtensions.cs @@ -363,7 +363,7 @@ namespace Umbraco.Extensions /// Returns if the value is null, /// empty, or consists only of white-space characters, otherwise /// returns . - public static bool IsNullOrWhiteSpace(this string value) => string.IsNullOrWhiteSpace(value); + public static bool IsNullOrWhiteSpace(this string? value) => string.IsNullOrWhiteSpace(value); public static string IfNullOrWhiteSpace(this string str, string defaultValue) { diff --git a/src/Umbraco.Core/GuidUdi.cs b/src/Umbraco.Core/GuidUdi.cs index 74f6e2dbc8..53c495ba87 100644 --- a/src/Umbraco.Core/GuidUdi.cs +++ b/src/Umbraco.Core/GuidUdi.cs @@ -39,10 +39,10 @@ namespace Umbraco.Cms.Core Guid = guid; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { var other = obj as GuidUdi; - if (other == null) return false; + if (other is null) return false; return EntityType == other.EntityType && Guid == other.Guid; } diff --git a/src/Umbraco.Core/HashCodeHelper.cs b/src/Umbraco.Core/HashCodeHelper.cs index 9324450cf6..6d98ec57b8 100644 --- a/src/Umbraco.Core/HashCodeHelper.cs +++ b/src/Umbraco.Core/HashCodeHelper.cs @@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core { unchecked { - return 31 * arg1.GetHashCode() + arg2.GetHashCode(); + return 31 * arg1!.GetHashCode() + arg2!.GetHashCode(); } } @@ -19,9 +19,9 @@ namespace Umbraco.Cms.Core { unchecked { - int hash = arg1.GetHashCode(); - hash = 31 * hash + arg2.GetHashCode(); - return 31 * hash + arg3.GetHashCode(); + int hash = arg1!.GetHashCode(); + hash = 31 * hash + arg2!.GetHashCode(); + return 31 * hash + arg3!.GetHashCode(); } } @@ -30,10 +30,10 @@ namespace Umbraco.Cms.Core { unchecked { - int hash = arg1.GetHashCode(); - hash = 31 * hash + arg2.GetHashCode(); - hash = 31 * hash + arg3.GetHashCode(); - return 31 * hash + arg4.GetHashCode(); + int hash = arg1!.GetHashCode(); + hash = 31 * hash + arg2!.GetHashCode(); + hash = 31 * hash + arg3!.GetHashCode(); + return 31 * hash + arg4!.GetHashCode(); } } @@ -97,7 +97,7 @@ namespace Umbraco.Cms.Core { unchecked { - return 31 * hashCode + arg.GetHashCode(); + return 31 * hashCode + arg!.GetHashCode(); } } } diff --git a/src/Umbraco.Core/HybridAccessorBase.cs b/src/Umbraco.Core/HybridAccessorBase.cs index 1bb7635dcc..51c89ab66d 100644 --- a/src/Umbraco.Core/HybridAccessorBase.cs +++ b/src/Umbraco.Core/HybridAccessorBase.cs @@ -17,10 +17,10 @@ namespace Umbraco.Cms.Core public abstract class HybridAccessorBase where T : class { - private static readonly AsyncLocal s_ambientContext = new AsyncLocal(); + private static readonly AsyncLocal s_ambientContext = new AsyncLocal(); private readonly IRequestCache _requestCache; - private string _itemKey; + private string? _itemKey; protected string ItemKey => _itemKey ??= GetType().FullName; // read @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core //private static T _value; // yes! flows with async! - private T NonContextValue + private T? NonContextValue { get => s_ambientContext.Value ?? default; set => s_ambientContext.Value = value; @@ -47,7 +47,7 @@ namespace Umbraco.Cms.Core protected HybridAccessorBase(IRequestCache requestCache) => _requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); - protected T Value + protected T? Value { get { @@ -55,7 +55,7 @@ namespace Umbraco.Cms.Core { return NonContextValue; } - return (T) _requestCache.Get(ItemKey); + return (T?) _requestCache.Get(ItemKey); } set diff --git a/src/Umbraco.Core/HybridEventMessagesAccessor.cs b/src/Umbraco.Core/HybridEventMessagesAccessor.cs index df6a34aae8..d28561c12f 100644 --- a/src/Umbraco.Core/HybridEventMessagesAccessor.cs +++ b/src/Umbraco.Core/HybridEventMessagesAccessor.cs @@ -7,7 +7,8 @@ namespace Umbraco.Cms.Core { public HybridEventMessagesAccessor(IRequestCache requestCache) : base(requestCache) - { } + { + } public EventMessages EventMessages { diff --git a/src/Umbraco.Core/IO/MediaFileManager.cs b/src/Umbraco.Core/IO/MediaFileManager.cs index 96680d3f84..3754b8d076 100644 --- a/src/Umbraco.Core/IO/MediaFileManager.cs +++ b/src/Umbraco.Core/IO/MediaFileManager.cs @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.IO private readonly ILogger _logger; private readonly IShortStringHelper _shortStringHelper; private readonly IServiceProvider _serviceProvider; - private MediaUrlGeneratorCollection _mediaUrlGenerators; + private MediaUrlGeneratorCollection? _mediaUrlGenerators; private readonly ContentSettings _contentSettings; /// @@ -120,12 +120,12 @@ namespace Umbraco.Cms.Core.IO /// /// /// - public Stream GetFile( + public Stream? GetFile( IContentBase content, - out string mediaFilePath, + out string? mediaFilePath, string propertyTypeAlias = Constants.Conventions.Media.File, - string culture = null, - string segment = null) + string? culture = null, + string? segment = null) { // TODO: If collections were lazy we could just inject them if (_mediaUrlGenerators == null) @@ -133,12 +133,12 @@ namespace Umbraco.Cms.Core.IO _mediaUrlGenerators = _serviceProvider.GetRequiredService(); } - if (!content.TryGetMediaPath(propertyTypeAlias, _mediaUrlGenerators, out mediaFilePath, culture, segment)) + if (!content.TryGetMediaPath(propertyTypeAlias, _mediaUrlGenerators!, out mediaFilePath, culture, segment)) { return null; } - Stream stream = FileSystem.OpenFile(mediaFilePath); + Stream stream = FileSystem.OpenFile(mediaFilePath!); if (stream != null) { return stream; @@ -162,7 +162,7 @@ namespace Umbraco.Cms.Core.IO /// If an is provided then that file (and associated thumbnails if any) is deleted /// before the new file is saved, and depending on the media path scheme, the folder may be reused for the new file. /// - public string StoreFile(IContentBase content, IPropertyType propertyType, string filename, Stream filestream, string oldpath) + public string StoreFile(IContentBase content, IPropertyType propertyType, string filename, Stream filestream, string? oldpath) { if (content == null) { @@ -192,7 +192,7 @@ namespace Umbraco.Cms.Core.IO // clear the old file, if any if (string.IsNullOrWhiteSpace(oldpath) == false) { - FileSystem.DeleteFile(oldpath); + FileSystem.DeleteFile(oldpath!); } // get the filepath, store the data @@ -208,7 +208,7 @@ namespace Umbraco.Cms.Core.IO /// The property type owning the copy of the media file. /// The filesystem-relative path to the source media file. /// The filesystem-relative path to the copy of the media file. - public string CopyFile(IContentBase content, IPropertyType propertyType, string sourcepath) + public string? CopyFile(IContentBase content, IPropertyType propertyType, string sourcepath) { if (content == null) { diff --git a/src/Umbraco.Core/Install/InstallStatusTracker.cs b/src/Umbraco.Core/Install/InstallStatusTracker.cs index 66b05d0fe1..9f069c3081 100644 --- a/src/Umbraco.Core/Install/InstallStatusTracker.cs +++ b/src/Umbraco.Core/Install/InstallStatusTracker.cs @@ -127,7 +127,7 @@ namespace Umbraco.Cms.Core.Install return new List(_steps); } - public void SetComplete(Guid installId, string name, IDictionary additionalData = null) + public void SetComplete(Guid installId, string name, IDictionary? additionalData = null) { var trackingItem = _steps.Single(x => x.Name == name); if (additionalData != null) diff --git a/src/Umbraco.Core/Install/Models/InstallProgressResultModel.cs b/src/Umbraco.Core/Install/Models/InstallProgressResultModel.cs index 02f1d9b482..43b3fc73fe 100644 --- a/src/Umbraco.Core/Install/Models/InstallProgressResultModel.cs +++ b/src/Umbraco.Core/Install/Models/InstallProgressResultModel.cs @@ -9,7 +9,7 @@ namespace Umbraco.Cms.Core.Install.Models [DataContract(Name = "result", Namespace = "")] public class InstallProgressResultModel { - public InstallProgressResultModel(bool processComplete, string stepCompleted, string nextStep, string view = null, object viewModel = null) + public InstallProgressResultModel(bool processComplete, string stepCompleted, string nextStep, string? view = null, object? viewModel = null) { ProcessComplete = processComplete; StepCompleted = stepCompleted; @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Install.Models /// The UI view to show when this step executes, by default no views are shown for the completion of a step unless explicitly specified. /// [DataMember(Name = "view")] - public string View { get; private set; } + public string? View { get; private set; } [DataMember(Name = "complete")] public bool ProcessComplete { get; set; } @@ -37,6 +37,6 @@ namespace Umbraco.Cms.Core.Install.Models /// The view model to return to the UI if this step is returning a view (optional) /// [DataMember(Name = "model")] - public object ViewModel { get; private set; } + public object? ViewModel { get; private set; } } } diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 3648f7907e..cc475a566a 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Models /// Parent object /// ContentType for the current Content object /// An optional culture. - public Content(string name, IContent parent, IContentType contentType, string culture = null) + public Content(string name, IContent parent, IContentType contentType, string? culture = null) : this(name, parent, contentType, new PropertyCollection(), culture) { } @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Models /// ContentType for the current Content object /// The identifier of the user creating the Content object /// An optional culture. - public Content(string name, IContent parent, IContentType contentType, int userId, string culture = null) + public Content(string name, IContent parent, IContentType contentType, int userId, string? culture = null) : this(name, parent, contentType, new PropertyCollection(), culture) { CreatorId = userId; @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Models /// ContentType for the current Content object /// Collection of properties /// An optional culture. - public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties, string culture = null) + public Content(string name, IContent parent, IContentType contentType, PropertyCollection properties, string? culture = null) : base(name, parent, contentType, properties, culture) { if (contentType == null) throw new ArgumentNullException(nameof(contentType)); @@ -76,7 +76,7 @@ namespace Umbraco.Cms.Core.Models /// Id of the Parent content /// ContentType for the current Content object /// An optional culture. - public Content(string name, int parentId, IContentType contentType, string culture = null) + public Content(string name, int parentId, IContentType contentType, string? culture = null) : this(name, parentId, contentType, new PropertyCollection(), culture) { } @@ -88,7 +88,7 @@ namespace Umbraco.Cms.Core.Models /// ContentType for the current Content object /// The identifier of the user creating the Content object /// An optional culture. - public Content(string name, int parentId, IContentType contentType, int userId, string culture = null) + public Content(string name, int parentId, IContentType contentType, int userId, string? culture = null) : this(name, parentId, contentType, new PropertyCollection(), culture) { CreatorId = userId; @@ -103,7 +103,7 @@ namespace Umbraco.Cms.Core.Models /// ContentType for the current Content object /// Collection of properties /// An optional culture. - public Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string culture = null) + public Content(string name, int parentId, IContentType contentType, PropertyCollection properties, string? culture = null) : base(name, parentId, contentType, properties, culture) { if (contentType == null) throw new ArgumentNullException(nameof(contentType)); diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index 139cfca1ee..a53f2ccf51 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)); @@ -295,7 +295,7 @@ namespace Umbraco.Cms.Core.Models => Properties.Contains(propertyTypeAlias); /// - public object GetValue(string propertyTypeAlias, string culture = null, string segment = null, bool published = false) + public object GetValue(string propertyTypeAlias, string? culture = null, string? segment = null, bool published = false) { return Properties.TryGetValue(propertyTypeAlias, out var property) ? property.GetValue(culture, segment, published) @@ -303,7 +303,7 @@ namespace Umbraco.Cms.Core.Models } /// - public TValue GetValue(string propertyTypeAlias, string culture = null, string segment = null, bool published = false) + public TValue GetValue(string propertyTypeAlias, string? culture = null, string? segment = null, bool published = false) { if (!Properties.TryGetValue(propertyTypeAlias, out var property)) return default; @@ -313,7 +313,7 @@ namespace Umbraco.Cms.Core.Models } /// - public void SetValue(string propertyTypeAlias, object value, string culture = null, string segment = null) + public void SetValue(string propertyTypeAlias, object value, string? culture = null, string? segment = null) { if (!Properties.TryGetValue(propertyTypeAlias, out var property)) throw new InvalidOperationException($"No PropertyType exists with the supplied alias \"{propertyTypeAlias}\"."); diff --git a/src/Umbraco.Core/Models/ContentBaseExtensions.cs b/src/Umbraco.Core/Models/ContentBaseExtensions.cs index 9aae08c74b..973d24f13c 100644 --- a/src/Umbraco.Core/Models/ContentBaseExtensions.cs +++ b/src/Umbraco.Core/Models/ContentBaseExtensions.cs @@ -19,7 +19,7 @@ namespace Umbraco.Extensions /// /// The culture. /// The URL segment. - public static string GetUrlSegment(this IContentBase content, IShortStringHelper shortStringHelper, IEnumerable urlSegmentProviders, string culture = null) + public static string GetUrlSegment(this IContentBase content, IShortStringHelper shortStringHelper, IEnumerable urlSegmentProviders, string? culture = null) { if (content == null) throw new ArgumentNullException(nameof(content)); if (urlSegmentProviders == null) throw new ArgumentNullException(nameof(urlSegmentProviders)); @@ -34,7 +34,7 @@ namespace Umbraco.Extensions url = s_defaultUrlSegmentProvider.GetUrlSegment(content, culture); // be safe } - + return url; } diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs index 85581dc2e1..ee5a4600d4 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs @@ -27,14 +27,14 @@ namespace Umbraco.Cms.Core.Models.ContentEditing public Guid DataTypeKey { get; set; } [DataMember(Name = "value")] - public object Value { get; set; } + public object? Value { get; set; } [DataMember(Name = "alias", IsRequired = true)] [Required(AllowEmptyStrings = false)] - public string Alias { get; set; } + public string Alias { get; set; } = null!; [DataMember(Name = "editor", IsRequired = false)] - public string Editor { get; set; } + public string? Editor { get; set; } /// /// Flags the property to denote that it can contain sensitive data @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// [DataMember(Name = "culture")] [ReadOnly(true)] - public string Culture { get; set; } + public string? Culture { get; set; } /// /// The segment of the property @@ -62,12 +62,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// [DataMember(Name = "segment")] [ReadOnly(true)] - public string Segment { get; set; } + public string? Segment { get; set; } /// /// Used internally during model mapping /// [IgnoreDataMember] - public IDataEditor PropertyEditor { get; set; } + public IDataEditor? PropertyEditor { get; set; } } } diff --git a/src/Umbraco.Core/Models/ContentEditing/IContentAppFactory.cs b/src/Umbraco.Core/Models/ContentEditing/IContentAppFactory.cs index 3c0def3c1f..fc263a3b91 100644 --- a/src/Umbraco.Core/Models/ContentEditing/IContentAppFactory.cs +++ b/src/Umbraco.Core/Models/ContentEditing/IContentAppFactory.cs @@ -18,6 +18,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing /// the content app should be displayed or not, and return either a /// instance, or null. /// - ContentApp GetContentAppFor(object source, IEnumerable userGroups); + ContentApp? GetContentAppFor(object source, IEnumerable userGroups); } } diff --git a/src/Umbraco.Core/Models/ContentTagsExtensions.cs b/src/Umbraco.Core/Models/ContentTagsExtensions.cs index ed9d1fad12..0dacd78844 100644 --- a/src/Umbraco.Core/Models/ContentTagsExtensions.cs +++ b/src/Umbraco.Core/Models/ContentTagsExtensions.cs @@ -22,7 +22,7 @@ namespace Umbraco.Extensions /// A value indicating whether to merge the tags with existing tags instead of replacing them. /// A culture, for multi-lingual properties. /// - public static void AssignTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable tags, bool merge = false, string culture = null) + public static void AssignTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable tags, bool merge = false, string? culture = null) { content.GetTagProperty(propertyTypeAlias).AssignTags(propertyEditors, dataTypeService, serializer, tags, merge, culture); } @@ -36,7 +36,7 @@ namespace Umbraco.Extensions /// The tags. /// A culture, for multi-lingual properties. /// - public static void RemoveTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable tags, string culture = null) + public static void RemoveTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable tags, string? culture = null) { content.GetTagProperty(propertyTypeAlias).RemoveTags(propertyEditors, dataTypeService, serializer, tags, culture); } diff --git a/src/Umbraco.Core/Models/IContentBase.cs b/src/Umbraco.Core/Models/IContentBase.cs index 1aac7dd1a5..6053be2d38 100644 --- a/src/Umbraco.Core/Models/IContentBase.cs +++ b/src/Umbraco.Core/Models/IContentBase.cs @@ -112,19 +112,19 @@ namespace Umbraco.Cms.Core.Models /// Gets the value of a Property /// /// Values 'null' and 'empty' are equivalent for culture and segment. - object GetValue(string propertyTypeAlias, string culture = null, string segment = null, bool published = false); + object GetValue(string propertyTypeAlias, string? culture = null, string? segment = null, bool published = false); /// /// Gets the typed value of a Property /// /// Values 'null' and 'empty' are equivalent for culture and segment. - TValue GetValue(string propertyTypeAlias, string culture = null, string segment = null, bool published = false); + TValue GetValue(string propertyTypeAlias, string? culture = null, string? segment = null, bool published = false); /// /// Sets the (edited) value of a Property /// /// Values 'null' and 'empty' are equivalent for culture and segment. - void SetValue(string propertyTypeAlias, object value, string culture = null, string segment = null); + void SetValue(string propertyTypeAlias, object value, string? culture = null, string? segment = null); } } diff --git a/src/Umbraco.Core/Models/IDataValueEditor.cs b/src/Umbraco.Core/Models/IDataValueEditor.cs index 012766e75d..48aa9c1b69 100644 --- a/src/Umbraco.Core/Models/IDataValueEditor.cs +++ b/src/Umbraco.Core/Models/IDataValueEditor.cs @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Models /// /// Converts a property value to a value for the editor. /// - object ToEditor(IProperty property, string culture = null, string segment = null); + object ToEditor(IProperty property, string? culture = null, string? segment = null); // TODO: / deal with this when unplugging the xml cache // why property vs propertyType? services should be injected! etc... diff --git a/src/Umbraco.Core/Models/IProperty.cs b/src/Umbraco.Core/Models/IProperty.cs index 3991c7f2c6..8654c24d64 100644 --- a/src/Umbraco.Core/Models/IProperty.cs +++ b/src/Umbraco.Core/Models/IProperty.cs @@ -25,12 +25,12 @@ namespace Umbraco.Cms.Core.Models /// /// Gets the value. /// - object GetValue(string culture = null, string segment = null, bool published = false); + object GetValue(string? culture = null, string? segment = null, bool published = false); /// /// Sets a value. /// - void SetValue(object value, string culture = null, string segment = null); + void SetValue(object value, string? culture = null, string? segment = null); int PropertyTypeId { get; } void PublishValues(string culture = "*", string segment = "*"); diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 00a774cc25..6c172030c7 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -241,7 +241,7 @@ namespace Umbraco.Cms.Core.Models /// /// Gets the value. /// - public object GetValue(string culture = null, string segment = null, bool published = false) + public object GetValue(string culture = null, string? segment = null, bool published = false) { // ensure null or whitespace are nulls culture = culture.NullOrWhiteSpaceAsNull(); @@ -340,7 +340,7 @@ namespace Umbraco.Cms.Core.Models /// /// Sets a value. /// - public void SetValue(object value, string culture = null, string segment = null) + public void SetValue(object value, string? culture = null, string? segment = null) { culture = culture.NullOrWhiteSpaceAsNull(); segment = segment.NullOrWhiteSpaceAsNull(); diff --git a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs index 390f644831..0cfdfc8e07 100644 --- a/src/Umbraco.Core/Models/PropertyTagsExtensions.cs +++ b/src/Umbraco.Core/Models/PropertyTagsExtensions.cs @@ -44,7 +44,7 @@ namespace Umbraco.Extensions /// A culture, for multi-lingual properties. /// /// - public static void AssignTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable tags, bool merge = false, string culture = null) + public static void AssignTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable tags, bool merge = false, string? culture = null) { if (property == null) throw new ArgumentNullException(nameof(property)); @@ -100,7 +100,7 @@ namespace Umbraco.Extensions /// A culture, for multi-lingual properties. /// /// - public static void RemoveTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable tags, string culture = null) + public static void RemoveTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable tags, string? culture = null) { if (property == null) throw new ArgumentNullException(nameof(property)); @@ -134,7 +134,7 @@ namespace Umbraco.Extensions } // used by ContentRepositoryBase - public static IEnumerable GetTagsValue(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string culture = null) + public static IEnumerable GetTagsValue(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string? culture = null) { if (property == null) throw new ArgumentNullException(nameof(property)); @@ -145,7 +145,7 @@ namespace Umbraco.Extensions return property.GetTagsValue(configuration.StorageType, serializer, configuration.Delimiter, culture); } - private static IEnumerable GetTagsValue(this IProperty property, TagsStorageType storageType, IJsonSerializer serializer, char delimiter, string culture = null) + private static IEnumerable GetTagsValue(this IProperty property, TagsStorageType storageType, IJsonSerializer serializer, char delimiter, string? culture = null) { if (property == null) throw new ArgumentNullException(nameof(property)); diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs index 0c4bf4c4eb..5d2eab7830 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs @@ -23,7 +23,7 @@ /// Other caches that get their raw value from the database would consider that a property has "no /// value" if it is missing, null, or an empty string (including whitespace-only). /// - bool HasValue(string culture = null, string segment = null); + bool HasValue(string? culture = null, string? segment = null); /// /// Gets the source value of the property. @@ -37,7 +37,7 @@ /// If you're using that value, you're probably wrong, unless you're doing some internal /// Umbraco stuff. /// - object GetSourceValue(string culture = null, string segment = null); + object GetSourceValue(string? culture = null, string? segment = null); /// /// Gets the object value of the property. @@ -47,7 +47,7 @@ /// It can be null, or any type of CLR object. /// It has been fully prepared and processed by the appropriate converter. /// - object GetValue(string culture = null, string segment = null); + object GetValue(string? culture = null, string? segment = null); /// /// Gets the XPath value of the property. @@ -57,6 +57,6 @@ /// It must be either null, or a string, or an XPathNavigator. /// It has been fully prepared and processed by the appropriate converter. /// - object GetXPathValue(string culture = null, string segment = null); + object GetXPathValue(string? culture = null, string? segment = null); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedValueFallback.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedValueFallback.cs index 4ece22ab22..ba5790fca5 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedValueFallback.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedValueFallback.cs @@ -25,7 +25,7 @@ /// so the variant context should be used to contextualize them (see our default implementation in /// the web project. /// - bool TryGetValue(IPublishedProperty property, string culture, string segment, Fallback fallback, object defaultValue, out object value); + bool TryGetValue(IPublishedProperty property, string? culture, string? segment, Fallback fallback, object? defaultValue, out object value); /// /// Tries to get a fallback value for a property. @@ -45,7 +45,7 @@ /// At property level, property.GetValue() does *not* implement fallback, and one has to /// get property.Value() or property.Value{T}() to trigger fallback. /// - bool TryGetValue(IPublishedProperty property, string culture, string segment, Fallback fallback, T defaultValue, out T value); + bool TryGetValue(IPublishedProperty property, string? culture, string? segment, Fallback fallback, T? defaultValue, out T value); /// /// Tries to get a fallback value for a published element property. @@ -63,7 +63,7 @@ /// segment, either returned no property at all, or a property with HasValue(culture, segment) being false. /// It can only fallback at element level (no recurse). /// - bool TryGetValue(IPublishedElement content, string alias, string culture, string segment, Fallback fallback, object defaultValue, out object value); + bool TryGetValue(IPublishedElement content, string alias, string? culture, string? segment, Fallback fallback, object? defaultValue, out object value); /// /// Tries to get a fallback value for a published element property. @@ -82,7 +82,7 @@ /// segment, either returned no property at all, or a property with HasValue(culture, segment) being false. /// It can only fallback at element level (no recurse). /// - bool TryGetValue(IPublishedElement content, string alias, string culture, string segment, Fallback fallback, T defaultValue, out T value); + bool TryGetValue(IPublishedElement content, string alias, string? culture, string? segment, Fallback fallback, T? defaultValue, out T value); /// /// Tries to get a fallback value for a published content property. @@ -104,7 +104,7 @@ /// parameter is used to return a property with no value. That can then be used to invoke a converter and get the /// converter's interpretation of "no value". /// - bool TryGetValue(IPublishedContent content, string alias, string culture, string segment, Fallback fallback, object defaultValue, out object value, out IPublishedProperty noValueProperty); + bool TryGetValue(IPublishedContent content, string alias, string? culture, string? segment, Fallback fallback, object? defaultValue, out object value, out IPublishedProperty noValueProperty); /// /// Tries to get a fallback value for a published content property. @@ -127,6 +127,6 @@ /// parameter is used to return a property with no value. That can then be used to invoke a converter and get the /// converter's interpretation of "no value". /// - bool TryGetValue(IPublishedContent content, string alias, string culture, string segment, Fallback fallback, T defaultValue, out T value, out IPublishedProperty noValueProperty); + bool TryGetValue(IPublishedContent content, string alias, string? culture, string? segment, Fallback fallback, T defaultValue, out T value, out IPublishedProperty noValueProperty); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs index 473addecc3..d32943357e 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs @@ -55,15 +55,15 @@ namespace Umbraco.Cms.Core.Models.PublishedContent public string Alias => PropertyType.Alias; /// - public abstract bool HasValue(string culture = null, string segment = null); + public abstract bool HasValue(string culture = null, string? segment = null); /// - public abstract object GetSourceValue(string culture = null, string segment = null); + public abstract object GetSourceValue(string culture = null, string? segment = null); /// - public abstract object GetValue(string culture = null, string segment = null); + public abstract object GetValue(string culture = null, string? segment = null); /// - public abstract object GetXPathValue(string culture = null, string segment = null); + public abstract object GetXPathValue(string culture = null, string? segment = null); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs index 92509015de..730f107fa6 100644 --- a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs +++ b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs @@ -23,19 +23,19 @@ namespace Umbraco.Cms.Core.Models.PublishedContent // RawValueProperty does not (yet?) support variants, // only manages the current "default" value - public override object GetSourceValue(string culture = null, string segment = null) + public override object GetSourceValue(string culture = null, string? segment = null) => string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _sourceValue : null; - public override bool HasValue(string culture = null, string segment = null) + public override bool HasValue(string culture = null, string? segment = null) { var sourceValue = GetSourceValue(culture, segment); return sourceValue is string s ? !string.IsNullOrWhiteSpace(s) : sourceValue != null; } - public override object GetValue(string culture = null, string segment = null) + public override object GetValue(string culture = null, string? segment = null) => string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _objectValue.Value : null; - public override object GetXPathValue(string culture = null, string segment = null) + public override object GetXPathValue(string culture = null, string? segment = null) => string.IsNullOrEmpty(culture) & string.IsNullOrEmpty(segment) ? _xpathValue.Value : null; public RawValueProperty(IPublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false) diff --git a/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs b/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs index 87b5d0f517..ce50180616 100644 --- a/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs +++ b/src/Umbraco.Core/Models/PublishedContent/VariationContext.cs @@ -8,7 +8,7 @@ /// /// Initializes a new instance of the class. /// - public VariationContext(string culture = null, string segment = null) + public VariationContext(string culture = null, string? segment = null) { Culture = culture ?? ""; // cannot be null, default to invariant Segment = segment ?? ""; // cannot be null, default to neutral diff --git a/src/Umbraco.Core/Persistence/Repositories/ITagRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ITagRepository.cs index d11192c32f..5e68f68f75 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ITagRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ITagRepository.cs @@ -58,37 +58,37 @@ namespace Umbraco.Cms.Core.Persistence.Repositories TaggedEntity GetTaggedEntityById(int id); /// Gets all entities of a type, tagged with any tag in the specified group. - IEnumerable GetTaggedEntitiesByTagGroup(TaggableObjectTypes objectType, string group, string culture = null); + IEnumerable GetTaggedEntitiesByTagGroup(TaggableObjectTypes objectType, string group, string? culture = null); /// /// Gets all entities of a type, tagged with the specified tag. /// - IEnumerable GetTaggedEntitiesByTag(TaggableObjectTypes objectType, string tag, string group = null, string culture = null); + IEnumerable GetTaggedEntitiesByTag(TaggableObjectTypes objectType, string tag, string group = null, string? culture = null); /// /// Gets all tags for an entity type. /// - IEnumerable GetTagsForEntityType(TaggableObjectTypes objectType, string group = null, string culture = null); + IEnumerable GetTagsForEntityType(TaggableObjectTypes objectType, string group = null, string? culture = null); /// /// Gets all tags attached to an entity. /// - IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null); + IEnumerable GetTagsForEntity(int contentId, string group = null, string? culture = null); /// /// Gets all tags attached to an entity. /// - IEnumerable GetTagsForEntity(Guid contentId, string group = null, string culture = null); + IEnumerable GetTagsForEntity(Guid contentId, string group = null, string? culture = null); /// /// Gets all tags attached to an entity via a property. /// - IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null); + IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string? culture = null); /// /// Gets all tags attached to an entity via a property. /// - IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string group = null, string culture = null); + IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string group = null, string? culture = null); #endregion } diff --git a/src/Umbraco.Core/Persistence/Repositories/RepositoryCacheKeys.cs b/src/Umbraco.Core/Persistence/Repositories/RepositoryCacheKeys.cs index 035ca6f4ec..7e89c7c125 100644 --- a/src/Umbraco.Core/Persistence/Repositories/RepositoryCacheKeys.cs +++ b/src/Umbraco.Core/Persistence/Repositories/RepositoryCacheKeys.cs @@ -17,9 +17,9 @@ namespace Umbraco.Cms.Core.Persistence.Repositories return s_keys.TryGetValue(type, out var key) ? key : (s_keys[type] = "uRepo_" + type.Name + "_"); } - public static string GetKey(TId id) + public static string GetKey(TId? id) { - if (EqualityComparer.Default.Equals(id, default)) + if (EqualityComparer.Default.Equals(id, default)) { return string.Empty; } @@ -30,7 +30,7 @@ namespace Umbraco.Cms.Core.Persistence.Repositories } else { - return GetKey() + id.ToString().ToUpperInvariant(); + return GetKey() + id?.ToString().ToUpperInvariant(); } } } diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index 07607be2b0..1aa8fce692 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -247,7 +247,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// The object returned will automatically be serialized into json notation. For most property editors /// the value returned is probably just a string but in some cases a json structure will be returned. /// - public virtual object ToEditor(IProperty property, string culture = null, string segment = null) + public virtual object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); if (val == null) return string.Empty; diff --git a/src/Umbraco.Core/PropertyEditors/DateValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DateValueEditor.cs index 244fa1354d..308a452d9e 100644 --- a/src/Umbraco.Core/PropertyEditors/DateValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DateValueEditor.cs @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.PropertyEditors Validators.Add(new DateTimeValidator()); } - public override object ToEditor(IProperty property, string culture= null, string segment = null) + public override object ToEditor(IProperty property, string culture= null, string? segment = null) { var date = property.GetValue(culture, segment).TryConvertTo(); if (date.Success == false || date.Result == null) diff --git a/src/Umbraco.Core/PropertyEditors/TextOnlyValueEditor.cs b/src/Umbraco.Core/PropertyEditors/TextOnlyValueEditor.cs index d067c33c35..7674b92600 100644 --- a/src/Umbraco.Core/PropertyEditors/TextOnlyValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/TextOnlyValueEditor.cs @@ -33,7 +33,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// The object returned will always be a string and if the database type is not a valid string type an exception is thrown /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); diff --git a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs index 7ec0314377..757d51cb65 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedCache.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedCache.cs @@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// A culture. /// The contents. /// The value of overrides defaults. - IEnumerable GetAtRoot(bool preview, string culture = null); + IEnumerable GetAtRoot(bool preview, string? culture = null); /// /// Gets contents at root. diff --git a/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs index 5fa8c16832..2958e57f92 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedContentCache.cs @@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// If is null then the settings value is used. /// The value of overrides defaults. /// - IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null); + IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null); /// /// Gets content identified by a route. @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// If is null then the settings value is used. /// Considers published or unpublished content depending on defaults. /// - IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null); + IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null); /// /// Gets the route for a content identified by its unique identifier. @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.PublishedCache /// /// The value of overrides defaults. /// - string GetRouteById(bool preview, int contentId, string culture = null); + string GetRouteById(bool preview, int contentId, string? culture = null); /// /// Gets the route for a content identified by its unique identifier. @@ -56,6 +56,6 @@ namespace Umbraco.Cms.Core.PublishedCache /// The resulting string is a special encoded route string that may contain the domain ID /// for the current route. If a domain is present the string will be prefixed with the domain ID integer, example: {domainId}/route-path-of-item /// - string GetRouteById(int contentId, string culture = null); + string GetRouteById(int contentId, string? culture = null); } } diff --git a/src/Umbraco.Core/PublishedCache/ITagQuery.cs b/src/Umbraco.Core/PublishedCache/ITagQuery.cs index 4b9134bdf2..870abd5d6d 100644 --- a/src/Umbraco.Core/PublishedCache/ITagQuery.cs +++ b/src/Umbraco.Core/PublishedCache/ITagQuery.cs @@ -9,51 +9,51 @@ namespace Umbraco.Cms.Core.PublishedCache /// /// Gets all documents tagged with the specified tag. /// - IEnumerable GetContentByTag(string tag, string group = null, string culture = null); + IEnumerable GetContentByTag(string tag, string group = null, string? culture = null); /// /// Gets all documents tagged with any tag in the specified group. /// - IEnumerable GetContentByTagGroup(string group, string culture = null); + IEnumerable GetContentByTagGroup(string group, string? culture = null); /// /// Gets all media tagged with the specified tag. /// - IEnumerable GetMediaByTag(string tag, string group = null, string culture = null); + IEnumerable GetMediaByTag(string tag, string group = null, string? culture = null); /// /// Gets all media tagged with any tag in the specified group. /// - IEnumerable GetMediaByTagGroup(string group, string culture = null); + IEnumerable GetMediaByTagGroup(string group, string? culture = null); /// /// Gets all tags. /// - IEnumerable GetAllTags(string group = null, string culture = null); + IEnumerable GetAllTags(string group = null, string? culture = null); /// /// Gets all document tags. /// - IEnumerable GetAllContentTags(string group = null, string culture = null); + IEnumerable GetAllContentTags(string group = null, string? culture = null); /// /// Gets all media tags. /// - IEnumerable GetAllMediaTags(string group = null, string culture = null); + IEnumerable GetAllMediaTags(string group = null, string? culture = null); /// /// Gets all member tags. /// - IEnumerable GetAllMemberTags(string group = null, string culture = null); + IEnumerable GetAllMemberTags(string group = null, string? culture = null); /// /// Gets all tags attached to an entity via a property. /// - IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null); + IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string? culture = null); /// /// Gets all tags attached to an entity. /// - IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null); + IEnumerable GetTagsForEntity(int contentId, string group = null, string? culture = null); } } diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs index c2f8f27419..dcf05641f1 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedContentCache.cs @@ -22,13 +22,13 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal public void Clear() => _content.Clear(); - public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); + public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null) => throw new NotImplementedException(); - public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); + public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null) => throw new NotImplementedException(); - public string GetRouteById(bool preview, int contentId, string culture = null) => throw new NotImplementedException(); + public string GetRouteById(bool preview, int contentId, string? culture = null) => throw new NotImplementedException(); - public string GetRouteById(int contentId, string culture = null) => throw new NotImplementedException(); + 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; @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal public override bool HasById(bool preview, int contentId) => _content.ContainsKey(contentId); - public override IEnumerable GetAtRoot(bool preview, string culture = null) => _content.Values.Where(x => x.Parent == null); + public override IEnumerable GetAtRoot(bool preview, string? culture = null) => _content.Values.Where(x => x.Parent == null); public override IPublishedContent GetSingleByXPath(bool preview, string xpath, XPathVariable[] vars) => throw new NotImplementedException(); diff --git a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs index 7fe46d8d75..21b426aa29 100644 --- a/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs +++ b/src/Umbraco.Core/PublishedCache/Internal/InternalPublishedProperty.cs @@ -19,12 +19,12 @@ namespace Umbraco.Cms.Core.PublishedCache.Internal 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/PublishedCacheBase.cs b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs index e9e5177c17..dabe6d9305 100644 --- a/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs +++ b/src/Umbraco.Core/PublishedCache/PublishedCacheBase.cs @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.PublishedCache public bool HasById(int contentId) => HasById(PreviewDefault, contentId); - public abstract IEnumerable GetAtRoot(bool preview, string culture = null); + public abstract IEnumerable GetAtRoot(bool preview, string? culture = null); public IEnumerable GetAtRoot(string culture = null) { diff --git a/src/Umbraco.Core/PublishedCache/PublishedElementPropertyBase.cs b/src/Umbraco.Core/PublishedCache/PublishedElementPropertyBase.cs index adb1ac2ca8..69b8b4f73e 100644 --- a/src/Umbraco.Core/PublishedCache/PublishedElementPropertyBase.cs +++ b/src/Umbraco.Core/PublishedCache/PublishedElementPropertyBase.cs @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.PublishedCache IsMember = propertyType.ContentType.ItemType == PublishedItemType.Member; } - public override bool HasValue(string culture = null, string segment = null) + public override bool HasValue(string culture = null, string? segment = null) { var hasValue = PropertyType.IsValue(_sourceValue, PropertyValueLevel.Source); if (hasValue.HasValue) return hasValue.Value; @@ -158,9 +158,9 @@ namespace Umbraco.Cms.Core.PublishedCache return _interValue; } - public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue; + public override object GetSourceValue(string culture = null, string? segment = null) => _sourceValue; - public override object GetValue(string culture = null, string segment = null) + public override object GetValue(string culture = null, string? segment = null) { GetCacheLevels(out var cacheLevel, out var referenceCacheLevel); @@ -174,7 +174,7 @@ namespace Umbraco.Cms.Core.PublishedCache } } - public override object GetXPathValue(string culture = null, string segment = null) + public override object GetXPathValue(string culture = null, string? segment = null) { GetCacheLevels(out var cacheLevel, out var referenceCacheLevel); diff --git a/src/Umbraco.Core/Routing/DomainUtilities.cs b/src/Umbraco.Core/Routing/DomainUtilities.cs index 2e36e8c0ef..1c43a72fd3 100644 --- a/src/Umbraco.Core/Routing/DomainUtilities.cs +++ b/src/Umbraco.Core/Routing/DomainUtilities.cs @@ -77,7 +77,7 @@ 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) @@ -148,7 +148,7 @@ 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 diff --git a/src/Umbraco.Core/Routing/IPublishedUrlProvider.cs b/src/Umbraco.Core/Routing/IPublishedUrlProvider.cs index 9b54b71092..78d8f4024a 100644 --- a/src/Umbraco.Core/Routing/IPublishedUrlProvider.cs +++ b/src/Umbraco.Core/Routing/IPublishedUrlProvider.cs @@ -19,7 +19,7 @@ namespace Umbraco.Cms.Core.Routing /// A culture. /// The current absolute url. /// The url for the published content. - string GetUrl(Guid id, UrlMode mode = UrlMode.Default, string culture = null, Uri current = null); + string GetUrl(Guid id, UrlMode mode = UrlMode.Default, string? culture = null, Uri current = null); /// /// Gets the url of a published content. @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.Routing /// A culture. /// The current absolute url. /// The url for the published content. - string GetUrl(int id, UrlMode mode = UrlMode.Default, string culture = null, Uri current = null); + string GetUrl(int id, UrlMode mode = UrlMode.Default, string? culture = null, Uri current = null); /// /// Gets the url of a published content. @@ -45,7 +45,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 "#". /// - string GetUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string culture = null, Uri current = null); + string GetUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string? culture = null, Uri current = null); string GetUrlFromRoute(int id, string route, string culture); @@ -82,7 +82,7 @@ namespace Umbraco.Cms.Core.Routing /// /// /// - string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null); + string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null); /// /// Gets the url of a media item. @@ -99,6 +99,6 @@ namespace Umbraco.Cms.Core.Routing /// when no culture is specified, the current culture. /// If the provider is unable to provide a url, it returns . /// - string GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null); + string GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null); } } diff --git a/src/Umbraco.Core/Routing/UrlInfo.cs b/src/Umbraco.Core/Routing/UrlInfo.cs index 9165d795cd..aeab881b98 100644 --- a/src/Umbraco.Core/Routing/UrlInfo.cs +++ b/src/Umbraco.Core/Routing/UrlInfo.cs @@ -13,12 +13,12 @@ namespace Umbraco.Cms.Core.Routing /// /// Creates a instance representing a true URL. /// - public static UrlInfo Url(string text, string culture = null) => new UrlInfo(text, true, culture); + public static UrlInfo Url(string text, string? culture = null) => new UrlInfo(text, true, culture); /// /// Creates a instance representing a message. /// - public static UrlInfo Message(string text, string culture = null) => new UrlInfo(text, false, culture); + public static UrlInfo Message(string text, string? culture = null) => new UrlInfo(text, false, culture); /// /// Initializes a new instance of the class. diff --git a/src/Umbraco.Core/Routing/UrlProvider.cs b/src/Umbraco.Core/Routing/UrlProvider.cs index 5d43dedc3d..fdf62328a9 100644 --- a/src/Umbraco.Core/Routing/UrlProvider.cs +++ b/src/Umbraco.Core/Routing/UrlProvider.cs @@ -73,7 +73,7 @@ namespace Umbraco.Cms.Core.Routing /// A culture. /// The current absolute URL. /// The URL for the published content. - public string GetUrl(Guid id, UrlMode mode = UrlMode.Default, string culture = null, Uri current = null) + public string GetUrl(Guid id, UrlMode mode = UrlMode.Default, string? culture = null, Uri current = null) => GetUrl(GetDocument(id), mode, culture, current); /// @@ -84,7 +84,7 @@ namespace Umbraco.Cms.Core.Routing /// A culture. /// The current absolute URL. /// The URL for the published content. - public string GetUrl(int id, UrlMode mode = UrlMode.Default, string culture = null, Uri current = null) + public string GetUrl(int id, UrlMode mode = UrlMode.Default, string? culture = null, Uri current = null) => GetUrl(GetDocument(id), mode, culture, current); /// @@ -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 "#"; @@ -188,7 +188,7 @@ namespace Umbraco.Cms.Core.Routing /// /// /// - public string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null) + public string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null) => GetMediaUrl(GetMedia(id), mode, culture, propertyAlias, current); /// @@ -206,7 +206,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 GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null) + public string GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string? culture = null, string propertyAlias = Constants.Conventions.Media.File, Uri current = null) { if (propertyAlias == null) throw new ArgumentNullException(nameof(propertyAlias)); diff --git a/src/Umbraco.Core/Services/ContentTypeServiceExtensions.cs b/src/Umbraco.Core/Services/ContentTypeServiceExtensions.cs index bc5393a26e..654861fad5 100644 --- a/src/Umbraco.Core/Services/ContentTypeServiceExtensions.cs +++ b/src/Umbraco.Core/Services/ContentTypeServiceExtensions.cs @@ -47,8 +47,8 @@ namespace Umbraco.Extensions public static ContentTypeAvailableCompositionsResults GetAvailableCompositeContentTypes(this IContentTypeService ctService, IContentTypeComposition source, IContentTypeComposition[] allContentTypes, - string[] filterContentTypes = null, - string[] filterPropertyTypes = null, + string[]? filterContentTypes = null, + string[]? filterPropertyTypes = null, bool isElement = false) { filterContentTypes = filterContentTypes == null diff --git a/src/Umbraco.Core/Services/IContentVersionService.cs b/src/Umbraco.Core/Services/IContentVersionService.cs index 1f56138c3d..84b71213ff 100644 --- a/src/Umbraco.Core/Services/IContentVersionService.cs +++ b/src/Umbraco.Core/Services/IContentVersionService.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Services /// Gets paginated content versions for given content id paginated. /// /// Thrown when is invalid. - IEnumerable GetPagedContentVersions(int contentId, long pageIndex, int pageSize, out long totalRecords, string culture = null); + IEnumerable GetPagedContentVersions(int contentId, long pageIndex, int pageSize, out long totalRecords, string? culture = null); /// /// Updates preventCleanup value for given content version. diff --git a/src/Umbraco.Core/Services/IEntityXmlSerializer.cs b/src/Umbraco.Core/Services/IEntityXmlSerializer.cs index c3e8a29e8e..fd68a9dfca 100644 --- a/src/Umbraco.Core/Services/IEntityXmlSerializer.cs +++ b/src/Umbraco.Core/Services/IEntityXmlSerializer.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.Services XElement Serialize( IMedia media, bool withDescendants = false, - Action onMediaItemSerialized = null); + Action? onMediaItemSerialized = null); /// /// Exports an IMember item as an XElement. diff --git a/src/Umbraco.Core/Services/IRedirectUrlService.cs b/src/Umbraco.Core/Services/IRedirectUrlService.cs index 5042a25662..d97bf8cec4 100644 --- a/src/Umbraco.Core/Services/IRedirectUrlService.cs +++ b/src/Umbraco.Core/Services/IRedirectUrlService.cs @@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.Services /// The content unique key. /// The culture. /// Is a proper Umbraco route eg /path/to/foo or 123/path/tofoo. - void Register(string url, Guid contentKey, string culture = null); + void Register(string url, Guid contentKey, string? culture = null); /// /// Deletes all redirect URLs for a given content. diff --git a/src/Umbraco.Core/Services/ITagService.cs b/src/Umbraco.Core/Services/ITagService.cs index 7a75b99c24..0ec356eea7 100644 --- a/src/Umbraco.Core/Services/ITagService.cs +++ b/src/Umbraco.Core/Services/ITagService.cs @@ -28,71 +28,71 @@ namespace Umbraco.Cms.Core.Services /// /// Gets all documents tagged with any tag in the specified group. /// - IEnumerable GetTaggedContentByTagGroup(string group, string culture = null); + IEnumerable GetTaggedContentByTagGroup(string group, string? culture = null); /// /// Gets all documents tagged with the specified tag. /// - IEnumerable GetTaggedContentByTag(string tag, string group = null, string culture = null); + IEnumerable GetTaggedContentByTag(string tag, string group = null, string? culture = null); /// /// Gets all media tagged with any tag in the specified group. /// - IEnumerable GetTaggedMediaByTagGroup(string group, string culture = null); + IEnumerable GetTaggedMediaByTagGroup(string group, string? culture = null); /// /// Gets all media tagged with the specified tag. /// - IEnumerable GetTaggedMediaByTag(string tag, string group = null, string culture = null); + IEnumerable GetTaggedMediaByTag(string tag, string group = null, string? culture = null); /// /// Gets all members tagged with any tag in the specified group. /// - IEnumerable GetTaggedMembersByTagGroup(string group, string culture = null); + IEnumerable GetTaggedMembersByTagGroup(string group, string? culture = null); /// /// Gets all members tagged with the specified tag. /// - IEnumerable GetTaggedMembersByTag(string tag, string group = null, string culture = null); + IEnumerable GetTaggedMembersByTag(string tag, string group = null, string? culture = null); /// /// Gets all tags. /// - IEnumerable GetAllTags(string group = null, string culture = null); + IEnumerable GetAllTags(string group = null, string? culture = null); /// /// Gets all document tags. /// - IEnumerable GetAllContentTags(string group = null, string culture = null); + IEnumerable GetAllContentTags(string group = null, string? culture = null); /// /// Gets all media tags. /// - IEnumerable GetAllMediaTags(string group = null, string culture = null); + IEnumerable GetAllMediaTags(string group = null, string? culture = null); /// /// Gets all member tags. /// - IEnumerable GetAllMemberTags(string group = null, string culture = null); + IEnumerable GetAllMemberTags(string group = null, string? culture = null); /// /// Gets all tags attached to an entity via a property. /// - IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null); + IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string? culture = null); /// /// Gets all tags attached to an entity. /// - IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null); + IEnumerable GetTagsForEntity(int contentId, string group = null, string? culture = null); /// /// Gets all tags attached to an entity via a property. /// - IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string group = null, string culture = null); + IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string group = null, string? culture = null); /// /// Gets all tags attached to an entity. /// - IEnumerable GetTagsForEntity(Guid contentId, string group = null, string culture = null); + IEnumerable GetTagsForEntity(Guid contentId, string group = null, string? culture = null); } } diff --git a/src/Umbraco.Core/Services/Ordering.cs b/src/Umbraco.Core/Services/Ordering.cs index 7a843191d3..c90431f028 100644 --- a/src/Umbraco.Core/Services/Ordering.cs +++ b/src/Umbraco.Core/Services/Ordering.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.Services /// The can be null, meaning: not sorting. If it is the empty string, it becomes null. /// The can be the empty string, meaning: invariant. If it is null, it becomes the empty string. /// - public Ordering(string orderBy, Direction direction = Direction.Ascending, string culture = null, bool isCustomField = false) + public Ordering(string orderBy, Direction direction = Direction.Ascending, string? culture = null, bool isCustomField = false) { OrderBy = orderBy.IfNullOrWhiteSpace(null); // empty is null and means, not sorting Direction = direction; @@ -39,7 +39,7 @@ namespace Umbraco.Cms.Core.Services /// The can be null, meaning: not sorting. If it is the empty string, it becomes null. /// The can be the empty string, meaning: invariant. If it is null, it becomes the empty string. /// - public static Ordering By(string orderBy, Direction direction = Direction.Ascending, string culture = null, bool isCustomField = false) + public static Ordering By(string orderBy, Direction direction = Direction.Ascending, string? culture = null, bool isCustomField = false) => new Ordering(orderBy, direction, culture, isCustomField); /// diff --git a/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs b/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs index fff22936a0..f908856e38 100644 --- a/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs +++ b/src/Umbraco.Core/Strings/DefaultUrlSegmentProvider.cs @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Strings /// The content. /// The culture. /// The URL segment. - public string GetUrlSegment(IContentBase content, string culture = null) + public string GetUrlSegment(IContentBase content, string? culture = null) { return GetUrlSegmentSource(content, culture).ToUrlSegment(_shortStringHelper, culture); } diff --git a/src/Umbraco.Core/Strings/IUrlSegmentProvider.cs b/src/Umbraco.Core/Strings/IUrlSegmentProvider.cs index 849f04a973..6e1eccdde5 100644 --- a/src/Umbraco.Core/Strings/IUrlSegmentProvider.cs +++ b/src/Umbraco.Core/Strings/IUrlSegmentProvider.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Strings /// This is for when Umbraco is capable of managing more than one URL /// per content, in 1-to-1 multilingual configurations. Then there would be one /// URL per culture. - string GetUrlSegment(IContentBase content, string culture = null); + string GetUrlSegment(IContentBase content, string? culture = null); // TODO: For the 301 tracking, we need to add another extended interface to this so that // the RedirectTrackingEventHandler can ask the IUrlSegmentProvider if the URL is changing. diff --git a/src/Umbraco.Core/UdiParser.cs b/src/Umbraco.Core/UdiParser.cs index 92f4e46f89..427f8ce9f0 100644 --- a/src/Umbraco.Core/UdiParser.cs +++ b/src/Umbraco.Core/UdiParser.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace Umbraco.Cms.Core { @@ -34,7 +35,7 @@ namespace Umbraco.Cms.Core public static Udi Parse(string s) { ParseInternal(s, false, false, out var udi); - return udi; + return udi!; } /// @@ -53,7 +54,7 @@ namespace Umbraco.Cms.Core public static Udi Parse(string s, bool knownTypes) { ParseInternal(s, false, knownTypes, out var udi); - return udi; + return udi!; } /// @@ -62,7 +63,7 @@ namespace Umbraco.Cms.Core /// The string to convert. /// An Udi instance that contains the value that was parsed. /// A boolean value indicating whether the string could be parsed. - public static bool TryParse(string s, out Udi udi) + public static bool TryParse(string s, [MaybeNullWhen(returnValue: false)] out Udi udi) { return ParseInternal(s, true, false, out udi); } @@ -73,7 +74,7 @@ namespace Umbraco.Cms.Core /// The string to convert. /// An Udi instance that contains the value that was parsed. /// A boolean value indicating whether the string could be parsed. - public static bool TryParse(string s, out T udi) + public static bool TryParse(string s, [MaybeNullWhen(returnValue: false)] out T udi) where T : Udi { var result = ParseInternal(s, true, false, out var parsed); @@ -101,18 +102,16 @@ namespace Umbraco.Cms.Core /// If is true, assemblies are not scanned for types, /// and therefore only builtin types may be known. Unless scanning already took place. /// - public static bool TryParse(string s, bool knownTypes, out Udi udi) + public static bool TryParse(string s, bool knownTypes, [MaybeNullWhen(returnValue: false)] out Udi udi) { return ParseInternal(s, true, knownTypes, out udi); } - private static bool ParseInternal(string s, bool tryParse, bool knownTypes, out Udi udi) + private static bool ParseInternal(string s, bool tryParse, bool knownTypes,[MaybeNullWhen(returnValue: false)] out Udi udi) { udi = null; - Uri uri; - if (Uri.IsWellFormedUriString(s, UriKind.Absolute) == false - || Uri.TryCreate(s, UriKind.Absolute, out uri) == false) + || Uri.TryCreate(s, UriKind.Absolute, out var uri) == false) { if (tryParse) return false; throw new FormatException(string.Format("String \"{0}\" is not a valid udi.", s)); diff --git a/src/Umbraco.Core/UdiRange.cs b/src/Umbraco.Core/UdiRange.cs index 250eef7e71..8282ab4e3f 100644 --- a/src/Umbraco.Core/UdiRange.cs +++ b/src/Umbraco.Core/UdiRange.cs @@ -78,10 +78,9 @@ namespace Umbraco.Cms.Core return _uriValue.ToString(); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { - var other = obj as UdiRange; - return other != null && GetType() == other.GetType() && _uriValue == other._uriValue; + return obj is UdiRange other && GetType() == other.GetType() && _uriValue == other._uriValue; } public override int GetHashCode() diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 9a1da38222..944bf5396e 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -1,13 +1,15 @@ - netstandard2.0 + net5.0 Umbraco.Cms.Core Umbraco CMS Umbraco.Cms.Core Umbraco CMS Core 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 + diff --git a/src/Umbraco.Core/UriUtilityCore.cs b/src/Umbraco.Core/UriUtilityCore.cs index d63692b30a..68b6234a0f 100644 --- a/src/Umbraco.Core/UriUtilityCore.cs +++ b/src/Umbraco.Core/UriUtilityCore.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core return StartWithScheme(uri, null); } - public static string StartWithScheme(string uri, string scheme) + public static string StartWithScheme(string uri, string? scheme) { return HasScheme(uri) ? uri : String.Format("{0}://{1}", scheme ?? Uri.UriSchemeHttp, uri); } diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index 78dbdddc84..28a95b406b 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -89,7 +89,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install if (string.IsNullOrWhiteSpace(connectionString) == false) { - providerName = ConfigConnectionString.ParseProviderName(connectionString); + providerName = ConfigConnectionString.ParseProviderName(connectionString)!; } else if (integratedAuth) { diff --git a/src/Umbraco.Infrastructure/ModelsBuilder/PublishedElementExtensions.cs b/src/Umbraco.Infrastructure/ModelsBuilder/PublishedElementExtensions.cs index 88e873517b..f771d34054 100644 --- a/src/Umbraco.Infrastructure/ModelsBuilder/PublishedElementExtensions.cs +++ b/src/Umbraco.Infrastructure/ModelsBuilder/PublishedElementExtensions.cs @@ -16,7 +16,7 @@ namespace Umbraco.Extensions /// /// Gets the value of a property. /// - public static TValue ValueFor(this TModel model, IPublishedValueFallback publishedValueFallback, Expression> property, string culture = null, string segment = null, Fallback fallback = default, TValue defaultValue = default) + public static TValue ValueFor(this TModel model, IPublishedValueFallback publishedValueFallback, Expression> property, string? culture = null, string? segment = null, Fallback fallback = default, TValue defaultValue = default) where TModel : IPublishedElement { var alias = GetAlias(model, property); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs index 919bbeea31..9c0f0bfe66 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TagRepository.cs @@ -310,7 +310,7 @@ WHERE r.tagId IS NULL"; /// public IEnumerable GetTaggedEntitiesByTag(TaggableObjectTypes objectType, string tag, - string group = null, string culture = null) + string group = null, string? culture = null) { Sql sql = GetTaggedEntitiesSql(objectType, culture); @@ -408,7 +408,7 @@ WHERE r.tagId IS NULL"; } /// - public IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null) + public IEnumerable GetTagsForEntity(int contentId, string group = null, string? culture = null) { Sql sql = GetTagsSql(culture); @@ -427,7 +427,7 @@ WHERE r.tagId IS NULL"; } /// - public IEnumerable GetTagsForEntity(Guid contentId, string group = null, string culture = null) + public IEnumerable GetTagsForEntity(Guid contentId, string group = null, string? culture = null) { Sql sql = GetTagsSql(culture); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs index b4b46f2f7c..59b3585144 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockEditorPropertyEditor.cs @@ -109,7 +109,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); var valEditors = new Dictionary(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs index e3a6987110..7152894cb4 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs @@ -150,7 +150,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment)?.ToString(); if (val.IsNullOrWhiteSpace()) return string.Empty; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs index 4fa41bc7d3..587d5e146a 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyValueEditor.cs @@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// This is called to merge in the prevalue crops with the value that is saved - similar to the property value converter for the front-end /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); if (val == null) return null; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs index 45aa507a54..58a2397c5c 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Core.PropertyEditors _jsonSerializer = jsonSerializer; } - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var value = property.GetValue(culture, segment); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs index c1d8aa33f8..090a8ecaec 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerValueEditor.cs @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.PropertyEditors _publishedUrlProvider = publishedUrlProvider; } - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var value = property.GetValue(culture, segment)?.ToString(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs index c3a5bae383..574a33f9f1 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -115,7 +115,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// The legacy property editor saved this data as new line delimited! strange but we have to maintain that. /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); return val?.ToString().Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultipleValueEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultipleValueEditor.cs index c0e544b50c..f22f0e54aa 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultipleValueEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultipleValueEditor.cs @@ -43,7 +43,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var json = base.ToEditor(property, culture, segment).ToString(); return JsonConvert.DeserializeObject(json) ?? Array.Empty(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs index 80ed34e6e1..06c9db7c5b 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs @@ -155,7 +155,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); var valEditors = new Dictionary(); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs index 50b6d7a881..d1723d3601 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs @@ -125,7 +125,7 @@ namespace Umbraco.Cms.Core.PropertyEditors /// /// /// - public override object ToEditor(IProperty property, string culture = null, string segment = null) + public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); if (val == null) diff --git a/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs index 218ee4298b..98dabd22b8 100644 --- a/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Infrastructure.Search string query, UmbracoEntityTypes entityType, int pageSize, - long pageIndex, out long totalFound, string culture = null, string searchFrom = null, bool ignoreUserStartNodes = false) + long pageIndex, out long totalFound, string? culture = null, string searchFrom = null, bool ignoreUserStartNodes = false) { var pagedResult = _backOfficeExamineSearcher.Search(query, entityType, pageSize, pageIndex, out totalFound, searchFrom, ignoreUserStartNodes); @@ -150,7 +150,7 @@ namespace Umbraco.Cms.Infrastructure.Search /// /// /// - private IEnumerable ContentFromSearchResults(IEnumerable results, string culture = null) + private IEnumerable ContentFromSearchResults(IEnumerable results, string? culture = null) { var defaultLang = _languageService.GetDefaultLanguageIsoCode(); diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs index e409f3af47..320410dba6 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/ContentVersionService.cs @@ -135,7 +135,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetPagedContentVersions(int contentId, long pageIndex, int pageSize, out long totalRecords, string culture = null) + public IEnumerable GetPagedContentVersions(int contentId, long pageIndex, int pageSize, out long totalRecords, string? culture = null) { if (pageIndex < 0) { diff --git a/src/Umbraco.Infrastructure/Services/Implement/RedirectUrlService.cs b/src/Umbraco.Infrastructure/Services/Implement/RedirectUrlService.cs index a3faf64081..04cc0c8bc9 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/RedirectUrlService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/RedirectUrlService.cs @@ -19,7 +19,7 @@ namespace Umbraco.Cms.Core.Services.Implement _redirectUrlRepository = redirectUrlRepository; } - public void Register(string url, Guid contentKey, string culture = null) + public void Register(string url, Guid contentKey, string? culture = null) { using (var scope = ScopeProvider.CreateScope()) { diff --git a/src/Umbraco.Infrastructure/Services/Implement/TagService.cs b/src/Umbraco.Infrastructure/Services/Implement/TagService.cs index 907af05ab2..f701eefe58 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/TagService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/TagService.cs @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTaggedContentByTagGroup(string group, string culture = null) + public IEnumerable GetTaggedContentByTagGroup(string group, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTaggedContentByTag(string tag, string group = null, string culture = null) + public IEnumerable GetTaggedContentByTag(string tag, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -62,7 +62,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTaggedMediaByTagGroup(string group, string culture = null) + public IEnumerable GetTaggedMediaByTagGroup(string group, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTaggedMediaByTag(string tag, string group = null, string culture = null) + public IEnumerable GetTaggedMediaByTag(string tag, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -80,7 +80,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTaggedMembersByTagGroup(string group, string culture = null) + public IEnumerable GetTaggedMembersByTagGroup(string group, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -89,7 +89,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTaggedMembersByTag(string tag, string group = null, string culture = null) + public IEnumerable GetTaggedMembersByTag(string tag, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -98,7 +98,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetAllTags(string group = null, string culture = null) + public IEnumerable GetAllTags(string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -107,7 +107,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetAllContentTags(string group = null, string culture = null) + public IEnumerable GetAllContentTags(string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -116,7 +116,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetAllMediaTags(string group = null, string culture = null) + public IEnumerable GetAllMediaTags(string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -125,7 +125,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetAllMemberTags(string group = null, string culture = null) + public IEnumerable GetAllMemberTags(string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -134,7 +134,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null) + public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -143,7 +143,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null) + public IEnumerable GetTagsForEntity(int contentId, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -152,7 +152,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string group = null, string culture = null) + public IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { @@ -161,7 +161,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public IEnumerable GetTagsForEntity(Guid contentId, string group = null, string culture = null) + public IEnumerable GetTagsForEntity(Guid contentId, string group = null, string? culture = null) { using (ScopeProvider.CreateScope(autoComplete: true)) { diff --git a/src/Umbraco.Infrastructure/TagQuery.cs b/src/Umbraco.Infrastructure/TagQuery.cs index 9b49394392..284416d9d4 100644 --- a/src/Umbraco.Infrastructure/TagQuery.cs +++ b/src/Umbraco.Infrastructure/TagQuery.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core } /// - public IEnumerable GetContentByTag(string tag, string group = null, string culture = null) + public IEnumerable GetContentByTag(string tag, string group = null, string? culture = null) { var ids = _tagService.GetTaggedContentByTag(tag, group, culture) .Select(x => x.EntityId); @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core } /// - public IEnumerable GetContentByTagGroup(string group, string culture = null) + public IEnumerable GetContentByTagGroup(string group, string? culture = null) { var ids = _tagService.GetTaggedContentByTagGroup(group, culture) .Select(x => x.EntityId); @@ -47,7 +47,7 @@ namespace Umbraco.Cms.Core } /// - public IEnumerable GetMediaByTag(string tag, string group = null, string culture = null) + public IEnumerable GetMediaByTag(string tag, string group = null, string? culture = null) { var ids = _tagService.GetTaggedMediaByTag(tag, group, culture) .Select(x => x.EntityId); @@ -56,7 +56,7 @@ namespace Umbraco.Cms.Core } /// - public IEnumerable GetMediaByTagGroup(string group, string culture = null) + public IEnumerable GetMediaByTagGroup(string group, string? culture = null) { var ids = _tagService.GetTaggedMediaByTagGroup(group, culture) .Select(x => x.EntityId); @@ -65,37 +65,37 @@ namespace Umbraco.Cms.Core } /// - public IEnumerable GetAllTags(string group = null, string culture = null) + public IEnumerable GetAllTags(string group = null, string? culture = null) { return _mapper.MapEnumerable(_tagService.GetAllTags(group, culture)); } /// - public IEnumerable GetAllContentTags(string group = null, string culture = null) + public IEnumerable GetAllContentTags(string group = null, string? culture = null) { return _mapper.MapEnumerable(_tagService.GetAllContentTags(group, culture)); } /// - public IEnumerable GetAllMediaTags(string group = null, string culture = null) + public IEnumerable GetAllMediaTags(string group = null, string? culture = null) { return _mapper.MapEnumerable(_tagService.GetAllMediaTags(group, culture)); } /// - public IEnumerable GetAllMemberTags(string group = null, string culture = null) + public IEnumerable GetAllMemberTags(string group = null, string? culture = null) { return _mapper.MapEnumerable(_tagService.GetAllMemberTags(group, culture)); } /// - public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string culture = null) + public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string group = null, string? culture = null) { return _mapper.MapEnumerable(_tagService.GetTagsForProperty(contentId, propertyTypeAlias, group, culture)); } /// - public IEnumerable GetTagsForEntity(int contentId, string group = null, string culture = null) + public IEnumerable GetTagsForEntity(int contentId, string group = null, string? culture = null) { return _mapper.MapEnumerable(_tagService.GetTagsForEntity(contentId, group, culture)); } diff --git a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs index 455c31d00f..55362612b8 100644 --- a/src/Umbraco.PublishedCache.NuCache/ContentCache.cs +++ b/src/Umbraco.PublishedCache.NuCache/ContentCache.cs @@ -66,7 +66,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache // at the moment we try our best to be backward compatible, but really, // should get rid of hideTopLevelNode and other oddities entirely, eventually - public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null) => + public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null) => GetByRoute(PreviewDefault, route, hideTopLevelNode, culture); public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, @@ -139,10 +139,10 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache return content; } - public string GetRouteById(int contentId, string culture = null) => + public string GetRouteById(int contentId, string? culture = null) => GetRouteById(PreviewDefault, contentId, culture); - public string GetRouteById(bool preview, int contentId, string culture = null) + public string GetRouteById(bool preview, int contentId, string? culture = null) { IAppCache cache = preview == false || PublishedSnapshotService.FullCacheWhenPreviewing ? _elementsCache @@ -301,7 +301,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache IEnumerable INavigableData.GetAtRoot(bool preview) => GetAtRoot(preview); - public override IEnumerable GetAtRoot(bool preview, string culture = null) + public override IEnumerable GetAtRoot(bool preview, string? culture = null) { // handle context culture for variant if (culture == null) diff --git a/src/Umbraco.PublishedCache.NuCache/MediaCache.cs b/src/Umbraco.PublishedCache.NuCache/MediaCache.cs index 1d422bec9a..78e5050da5 100644 --- a/src/Umbraco.PublishedCache.NuCache/MediaCache.cs +++ b/src/Umbraco.PublishedCache.NuCache/MediaCache.cs @@ -67,7 +67,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache IEnumerable INavigableData.GetAtRoot(bool preview) => GetAtRoot(preview); - public override IEnumerable GetAtRoot(bool preview, string culture = null) + public override IEnumerable GetAtRoot(bool preview, string? culture = null) { // handle context culture for variant if (culture == null) diff --git a/src/Umbraco.PublishedCache.NuCache/Property.cs b/src/Umbraco.PublishedCache.NuCache/Property.cs index 19ddf002f4..0762b5791e 100644 --- a/src/Umbraco.PublishedCache.NuCache/Property.cs +++ b/src/Umbraco.PublishedCache.NuCache/Property.cs @@ -89,7 +89,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache } // determines whether a property has value - public override bool HasValue(string culture = null, string segment = null) + public override bool HasValue(string culture = null, string? segment = null) { _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment); @@ -194,7 +194,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache return vvalue.InterValue; } - public override object GetSourceValue(string culture = null, string segment = null) + public override object GetSourceValue(string culture = null, string? segment = null) { _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment); @@ -208,7 +208,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache } } - public override object GetValue(string culture = null, string segment = null) + public override object GetValue(string culture = null, string? segment = null) { _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment); @@ -229,7 +229,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache return value; } - public override object GetXPathValue(string culture = null, string segment = null) + public override object GetXPathValue(string culture = null, string? segment = null) { _content.VariationContextAccessor.ContextualizeVariation(_variations, _content.Id, ref culture, ref segment); diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index a2e50a8185..7ecb8d3c0c 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -2451,7 +2451,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers display.AllowPreview = display.AllowPreview && content.Trashed == false && content.ContentType.IsElement == false; return display; } - + /// /// Used to map an instance to a and ensuring AllowPreview is set correctly. /// Also allows you to pass in an action for the mapper context where you can pass additional information on to the mapper. @@ -2550,7 +2550,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers } [HttpGet] - public IEnumerable GetRollbackVersions(int contentId, string culture = null) + public IEnumerable GetRollbackVersions(int contentId, string? culture = null) { var rollbackVersions = new List(); var writerIds = new HashSet(); @@ -2595,7 +2595,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers } [HttpGet] - public ContentVariantDisplay GetRollbackVersion(int versionId, string culture = null) + public ContentVariantDisplay GetRollbackVersion(int versionId, string? culture = null) { var version = _contentService.GetVersion(versionId); var content = MapToDisplay(version); diff --git a/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs b/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs index 408ae224ab..a4588ed9f7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/EntityController.cs @@ -472,7 +472,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers [HttpGet] [HttpPost] [Obsolete("Use GetUrlsByIds instead.")] - public IDictionary GetUrlsByUdis([FromJsonPath] Udi[] udis, string culture = null) + public IDictionary GetUrlsByUdis([FromJsonPath] Udi[] udis, string? culture = null) { if (udis == null || !udis.Any()) { @@ -508,7 +508,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers /// /// We are not restricting this with security because there is no sensitive data /// - public IActionResult GetUrl(int id, UmbracoEntityTypes type, string culture = null) + public IActionResult GetUrl(int id, UmbracoEntityTypes type, string? culture = null) { culture = culture ?? ClientCulture(); @@ -1445,7 +1445,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers return x => MapEntity(x, culture); } - private EntityBasic MapEntity(object entity, string culture = null) + private EntityBasic MapEntity(object entity, string? culture = null) { culture = culture ?? ClientCulture(); return _umbracoMapper.Map(entity, context => { context.SetCulture(culture); }); diff --git a/src/Umbraco.Web.Common/Cache/HttpContextRequestAppCache.cs b/src/Umbraco.Web.Common/Cache/HttpContextRequestAppCache.cs index 03acc9abb1..9e384879e3 100644 --- a/src/Umbraco.Web.Common/Cache/HttpContextRequestAppCache.cs +++ b/src/Umbraco.Web.Common/Cache/HttpContextRequestAppCache.cs @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Cache } /// - public override object Get(string key, Func factory) + public override object Get(string key, Func factory) { //no place to cache so just return the callback result if (!TryGetContextItems(out var items)) @@ -242,7 +242,7 @@ namespace Umbraco.Cms.Core.Cache } IFeatureCollection features = httpContext.Features; - + lock (httpContext) { requestLock = new RequestLock(); diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs index 9a6615653e..abbf934e04 100644 --- a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedContentExtensions.cs @@ -175,7 +175,7 @@ namespace Umbraco.Extensions /// Optional fallback strategy. /// The default value. /// The value of the content's property identified by the alias, if it exists, otherwise a default value. - public static object Value(this IPublishedContent content, string alias, string culture = null, string segment = null, Fallback fallback = default, object defaultValue = default) + public static object Value(this IPublishedContent content, string alias, string? culture = null, string? segment = null, Fallback fallback = default, object? defaultValue = default) => content.Value(PublishedValueFallback, alias, culture, segment, fallback, defaultValue); /// @@ -189,7 +189,7 @@ namespace Umbraco.Extensions /// Optional fallback strategy. /// The default value. /// The value of the content's property identified by the alias, converted to the specified type. - public static T Value(this IPublishedContent content, string alias, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default) + public static T Value(this IPublishedContent content, string alias, string? culture = null, string? segment = null, Fallback fallback = default, T defaultValue = default) => content.Value(PublishedValueFallback, alias, culture, segment, fallback, defaultValue); /// @@ -203,7 +203,7 @@ namespace Umbraco.Extensions /// This can be useful in order to return all nodes in an entire site by a type when combined with TypedContentAtRoot /// public static IEnumerable DescendantsOrSelfOfType( - this IEnumerable parentNodes, string docTypeAlias, string culture = null) + this IEnumerable parentNodes, string docTypeAlias, string? culture = null) => parentNodes.DescendantsOrSelfOfType(VariationContextAccessor, docTypeAlias, culture); /// @@ -222,21 +222,21 @@ namespace Umbraco.Extensions where T : class, IPublishedContent => parentNodes.DescendantsOrSelf(VariationContextAccessor, culture); - public static IEnumerable Descendants(this IPublishedContent content, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, string? culture = null) => content.Descendants(VariationContextAccessor, culture); - public static IEnumerable Descendants(this IPublishedContent content, int level, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, int level, string? culture = null) => content.Descendants(VariationContextAccessor, level, culture); public static IEnumerable DescendantsOfType(this IPublishedContent content, - string contentTypeAlias, string culture = null) + string contentTypeAlias, string? culture = null) => content.DescendantsOfType(VariationContextAccessor, contentTypeAlias, culture); - public static IEnumerable Descendants(this IPublishedContent content, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.Descendants(VariationContextAccessor, culture); - public static IEnumerable Descendants(this IPublishedContent content, int level, string culture = null) + public static IEnumerable Descendants(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent => content.Descendants(VariationContextAccessor, level, culture); @@ -244,53 +244,53 @@ namespace Umbraco.Extensions => content.DescendantsOrSelf(VariationContextAccessor, culture); - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string? culture = null) => content.DescendantsOrSelf(VariationContextAccessor, level, culture); - public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null) + public static IEnumerable DescendantsOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.DescendantsOrSelfOfType(VariationContextAccessor, contentTypeAlias, culture); - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.DescendantsOrSelf(VariationContextAccessor, culture); - public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string culture = null) + public static IEnumerable DescendantsOrSelf(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent => content.DescendantsOrSelf(VariationContextAccessor, level, culture); - public static IPublishedContent Descendant(this IPublishedContent content, string culture = null) + public static IPublishedContent Descendant(this IPublishedContent content, string? culture = null) => content.Descendant(VariationContextAccessor, culture); - public static IPublishedContent Descendant(this IPublishedContent content, int level, string culture = null) + public static IPublishedContent Descendant(this IPublishedContent content, int level, string? culture = null) => content.Descendant(VariationContextAccessor, level, culture); - public static IPublishedContent DescendantOfType(this IPublishedContent content, string contentTypeAlias, string culture = null) + public static IPublishedContent DescendantOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.DescendantOfType(VariationContextAccessor, contentTypeAlias, culture); - public static T Descendant(this IPublishedContent content, string culture = null) + public static T Descendant(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.Descendant(VariationContextAccessor, culture); - public static T Descendant(this IPublishedContent content, int level, string culture = null) + public static T Descendant(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent => content.Descendant(VariationContextAccessor, level, culture); - public static IPublishedContent DescendantOrSelf(this IPublishedContent content, string culture = null) + public static IPublishedContent DescendantOrSelf(this IPublishedContent content, string? culture = null) => content.DescendantOrSelf(VariationContextAccessor, culture); - public static IPublishedContent DescendantOrSelf(this IPublishedContent content, int level, string culture = null) + public static IPublishedContent DescendantOrSelf(this IPublishedContent content, int level, string? culture = null) => content.DescendantOrSelf(VariationContextAccessor, level, culture); - public static IPublishedContent DescendantOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string culture = null) + public static IPublishedContent DescendantOrSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.DescendantOrSelfOfType(VariationContextAccessor, contentTypeAlias, culture); - public static T DescendantOrSelf(this IPublishedContent content, string culture = null) + public static T DescendantOrSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.DescendantOrSelf(VariationContextAccessor, culture); - public static T DescendantOrSelf(this IPublishedContent content, int level, string culture = null) + public static T DescendantOrSelf(this IPublishedContent content, int level, string? culture = null) where T : class, IPublishedContent => content.DescendantOrSelf(VariationContextAccessor, level, culture); @@ -317,7 +317,7 @@ namespace Umbraco.Extensions /// However, if an empty string is specified only invariant children are returned. /// /// - public static IEnumerable Children(this IPublishedContent content, string culture = null) + public static IEnumerable Children(this IPublishedContent content, string? culture = null) => content.Children(VariationContextAccessor, culture); /// @@ -330,7 +330,7 @@ namespace Umbraco.Extensions /// /// Children are sorted by their sortOrder. /// - public static IEnumerable Children(this IPublishedContent content, Func predicate, string culture = null) + public static IEnumerable Children(this IPublishedContent content, Func predicate, string? culture = null) => content.Children(VariationContextAccessor, predicate, culture); /// @@ -340,7 +340,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, string contentTypeAlias, string culture = null) + public static IEnumerable ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.ChildrenOfType(VariationContextAccessor, contentTypeAlias, culture); /// @@ -353,31 +353,31 @@ namespace Umbraco.Extensions /// /// Children are sorted by their sortOrder. /// - public static IEnumerable Children(this IPublishedContent content, string culture = null) + public static IEnumerable Children(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.Children(VariationContextAccessor, culture); - public static IPublishedContent FirstChild(this IPublishedContent content, string culture = null) + public static IPublishedContent FirstChild(this IPublishedContent content, string? culture = null) => content.FirstChild(VariationContextAccessor, culture); /// /// Gets the first child of the content, of a given content type. /// - public static IPublishedContent FirstChildOfType(this IPublishedContent content, string contentTypeAlias, string culture = null) + public static IPublishedContent FirstChildOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.FirstChildOfType(VariationContextAccessor, contentTypeAlias, culture); - public static IPublishedContent FirstChild(this IPublishedContent content, Func predicate, string culture = null) + public static IPublishedContent FirstChild(this IPublishedContent content, Func predicate, string? culture = null) => content.FirstChild(VariationContextAccessor, predicate, culture); - public static IPublishedContent FirstChild(this IPublishedContent content, Guid uniqueId, string culture = null) + public static IPublishedContent FirstChild(this IPublishedContent content, Guid uniqueId, string? culture = null) => content.FirstChild(VariationContextAccessor, uniqueId, culture); - public static T FirstChild(this IPublishedContent content, string culture = null) + public static T FirstChild(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.FirstChild(VariationContextAccessor, culture); - public static T FirstChild(this IPublishedContent content, Func predicate, string culture = null) + public static T FirstChild(this IPublishedContent content, Func predicate, string? culture = null) where T : class, IPublishedContent => content.FirstChild(VariationContextAccessor, predicate, culture); @@ -390,7 +390,7 @@ namespace Umbraco.Extensions /// /// Note that in V7 this method also return the content node self. /// - public static IEnumerable Siblings(this IPublishedContent content, string culture = null) + public static IEnumerable Siblings(this IPublishedContent content, string? culture = null) => content.Siblings(PublishedSnapshot, VariationContextAccessor, culture); /// @@ -403,7 +403,7 @@ namespace Umbraco.Extensions /// /// Note that in V7 this method also return the content node self. /// - public static IEnumerable SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string culture = null) + public static IEnumerable SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.SiblingsOfType(PublishedSnapshot, VariationContextAccessor, contentTypeAlias, culture); /// @@ -416,7 +416,7 @@ namespace Umbraco.Extensions /// /// Note that in V7 this method also return the content node self. /// - public static IEnumerable Siblings(this IPublishedContent content, string culture = null) + public static IEnumerable Siblings(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.Siblings(PublishedSnapshot, VariationContextAccessor, culture); @@ -426,7 +426,7 @@ namespace Umbraco.Extensions /// The content. /// 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, string culture = null) + public static IEnumerable SiblingsAndSelf(this IPublishedContent content, string? culture = null) => content.SiblingsAndSelf(PublishedSnapshot, VariationContextAccessor, culture); /// @@ -436,7 +436,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, string contentTypeAlias, string culture = null) + public static IEnumerable SiblingsAndSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null) => content.SiblingsAndSelfOfType(PublishedSnapshot, VariationContextAccessor, contentTypeAlias, culture); /// @@ -446,7 +446,7 @@ namespace Umbraco.Extensions /// The content. /// 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, string culture = null) + public static IEnumerable SiblingsAndSelf(this IPublishedContent content, string? culture = null) where T : class, IPublishedContent => content.SiblingsAndSelf(PublishedSnapshot, VariationContextAccessor, culture); @@ -463,7 +463,7 @@ namespace Umbraco.Extensions /// if any. In addition, when the content type is multi-lingual, this is the url for the /// specified culture. Otherwise, it is the invariant url. /// - public static string Url(this IPublishedContent content, string culture = null, UrlMode mode = UrlMode.Default) + public static string Url(this IPublishedContent content, string? culture = null, UrlMode mode = UrlMode.Default) => content.Url(PublishedUrlProvider, culture, mode); /// @@ -478,7 +478,7 @@ namespace Umbraco.Extensions /// An optional content type alias. /// The specific culture to filter for. If null is used the current culture is used. (Default is null) /// The children of the content. - public static DataTable ChildrenAsTable(this IPublishedContent content, string contentTypeAliasFilter = "", string culture = null) + public static DataTable ChildrenAsTable(this IPublishedContent content, string contentTypeAliasFilter = "", string? culture = null) => content.ChildrenAsTable(VariationContextAccessor, ContentTypeService, MediaTypeService, MemberTypeService, PublishedUrlProvider, contentTypeAliasFilter, culture); /// diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedElementExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedElementExtensions.cs index c7da62f6db..4d4f5e1992 100644 --- a/src/Umbraco.Web.Common/Extensions/FriendlyPublishedElementExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/FriendlyPublishedElementExtensions.cs @@ -33,7 +33,7 @@ namespace Umbraco.Extensions string culture = null, string segment = null, Fallback fallback = default, - object defaultValue = default) + object? defaultValue = default) => content.Value(PublishedValueFallback, alias, culture, segment, fallback, defaultValue); /// @@ -75,7 +75,7 @@ namespace Umbraco.Extensions /// /// Gets the value of a property. /// - public static TValue ValueFor(this TModel model, Expression> property, string culture = null, string segment = null, Fallback fallback = default, TValue defaultValue = default) + public static TValue ValueFor(this TModel model, Expression> property, string? culture = null, string? segment = null, Fallback fallback = default, TValue defaultValue = default) where TModel : IPublishedElement => model.ValueFor(PublishedValueFallback, property, culture, segment, fallback); } diff --git a/tests/Umbraco.TestData/SegmentTestController.cs b/tests/Umbraco.TestData/SegmentTestController.cs index 92c01bcf7f..d608602711 100644 --- a/tests/Umbraco.TestData/SegmentTestController.cs +++ b/tests/Umbraco.TestData/SegmentTestController.cs @@ -89,7 +89,7 @@ namespace Umbraco.TestData return Content($"The document type {alias} no longer allows segments"); } - public ActionResult AddSegmentData(int contentId, string propertyAlias, string value, string segment, string culture = null) + public ActionResult AddSegmentData(int contentId, string propertyAlias, string value, string segment, string? culture = null) { IContent content = Services.ContentService.GetById(contentId); if (content == null) diff --git a/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs index cb28152338..7e6cde9e39 100644 --- a/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs @@ -229,7 +229,7 @@ namespace Umbraco.Cms.Tests.Common.Builders }) .Build(); - public static Content CreateSimpleContent(IContentType contentType, string name, int parentId = -1, string culture = null, string segment = null) => + public static Content CreateSimpleContent(IContentType contentType, string name, int parentId = -1, string? culture = null, string? segment = null) => new ContentBuilder() .WithContentType(contentType) .WithName(name) @@ -245,7 +245,7 @@ namespace Umbraco.Cms.Tests.Common.Builders segment) .Build(); - public static Content CreateSimpleContent(IContentType contentType, string name, IContent parent, string culture = null, string segment = null, bool setPropertyValues = true) + public static Content CreateSimpleContent(IContentType contentType, string name, IContent parent, string? culture = null, string? segment = null, bool setPropertyValues = true) { ContentBuilder builder = new ContentBuilder() .WithContentType(contentType) diff --git a/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs b/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs index 0ca260b2c9..13b0f715b0 100644 --- a/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs +++ b/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs @@ -226,7 +226,7 @@ namespace Umbraco.Cms.Tests.Common.Builders.Extensions return builder; } - public static T WithPropertyValues(this T builder, object propertyValues, string culture = null, string segment = null) + public static T WithPropertyValues(this T builder, object propertyValues, string? culture = null, string? segment = null) where T : IWithPropertyValues { builder.PropertyValues = propertyValues; diff --git a/tests/Umbraco.Tests.Common/Builders/PropertyDataBuilder.cs b/tests/Umbraco.Tests.Common/Builders/PropertyDataBuilder.cs index 04cc32711a..b472736cff 100644 --- a/tests/Umbraco.Tests.Common/Builders/PropertyDataBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/PropertyDataBuilder.cs @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Tests.Common.Builders return this; } - public PropertyDataBuilder WithPropertyData(string alias, object value, string culture = null, string segment = null) + public PropertyDataBuilder WithPropertyData(string alias, object value, string? culture = null, string? segment = null) => WithPropertyData(alias, new PropertyData { Culture = culture ?? string.Empty, diff --git a/tests/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs b/tests/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs index 7ba0f8377e..b4b95f777e 100644 --- a/tests/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs +++ b/tests/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Tests.Common.Extensions /// Set property values by alias with an anonymous object. /// /// Does not support variants. - public static void PropertyValues(this IContentBase content, object value, string culture = null, string segment = null) + public static void PropertyValues(this IContentBase content, object value, string? culture = null, string? segment = null) { if (value == null) { diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs index fdc50484d2..742e1b9c76 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs @@ -273,13 +273,13 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published internal void SetOwner(IPublishedElement owner) => _owner = owner; - public override bool HasValue(string culture = null, string segment = null) => _hasValue; + public override bool HasValue(string culture = null, string? segment = null) => _hasValue; - public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue; + public override object GetSourceValue(string culture = null, string? segment = null) => _sourceValue; - public override object GetValue(string culture = null, string segment = null) => PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview); + public override object GetValue(string culture = null, string? segment = null) => PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview); - public override object GetXPathValue(string culture = null, string segment = null) => throw new InvalidOperationException("This method won't be implemented."); + public override object GetXPathValue(string culture = null, string? segment = null) => throw new InvalidOperationException("This method won't be implemented."); } } }