Add nullability to web.common
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentModel"/> class with a content.
|
||||
/// </summary>
|
||||
public ContentModel(IPublishedContent content) => Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
public ContentModel(IPublishedContent? content) => Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content.
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace Umbraco.Cms.Core.Models
|
||||
/// we should not store direct entity
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
public ITemplate DefaultTemplate =>
|
||||
AllowedTemplates.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId);
|
||||
public ITemplate? DefaultTemplate =>
|
||||
AllowedTemplates?.FirstOrDefault(x => x != null && x.Id == DefaultTemplateId);
|
||||
|
||||
|
||||
[DataMember]
|
||||
@@ -82,14 +82,14 @@ namespace Umbraco.Cms.Core.Models
|
||||
/// we should not store direct entity
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public IEnumerable<ITemplate> AllowedTemplates
|
||||
public IEnumerable<ITemplate>? AllowedTemplates
|
||||
{
|
||||
get => _allowedTemplates;
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(value, ref _allowedTemplates, nameof(AllowedTemplates), TemplateComparer);
|
||||
|
||||
if (_allowedTemplates.Any(x => x.Id == _defaultTemplate) == false)
|
||||
if (_allowedTemplates?.Any(x => x.Id == _defaultTemplate) == false)
|
||||
{
|
||||
DefaultTemplateId = 0;
|
||||
}
|
||||
@@ -170,6 +170,6 @@ namespace Umbraco.Cms.Core.Models
|
||||
(IContentType)DeepCloneWithResetIdentities(newAlias);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool IsDirty() => base.IsDirty() || HistoryCleanup.IsDirty();
|
||||
public override bool IsDirty() => base.IsDirty() || (HistoryCleanup?.IsDirty() ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
}
|
||||
|
||||
// We need to reset the dirty properties, because it is otherwise true, just because the json serializer has set properties
|
||||
target.HistoryCleanup.ResetDirtyProperties(false);
|
||||
target.HistoryCleanup!.ResetDirtyProperties(false);
|
||||
if (target.HistoryCleanup.PreventCleanup != source.HistoryCleanup.PreventCleanup)
|
||||
{
|
||||
target.HistoryCleanup.PreventCleanup = source.HistoryCleanup.PreventCleanup;
|
||||
@@ -558,8 +558,8 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
|
||||
target.AllowedAsRoot = source.AllowAsRoot;
|
||||
|
||||
bool allowedContentTypesUnchanged = target.AllowedContentTypes.Select(x => x.Id.Value)
|
||||
.SequenceEqual(source.AllowedContentTypes);
|
||||
bool allowedContentTypesUnchanged = target.AllowedContentTypes?.Select(x => x.Id.Value)
|
||||
.SequenceEqual(source.AllowedContentTypes) ?? false;
|
||||
|
||||
if (allowedContentTypesUnchanged is false)
|
||||
{
|
||||
@@ -617,7 +617,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
|
||||
// ensure no duplicate alias, then assign the group properties collection
|
||||
EnsureUniqueAliases(destProperties);
|
||||
if (destGroup is not null && (destGroup.PropertyTypes.SupportsPublishing != isPublishing || destGroup.PropertyTypes.SequenceEqual(destProperties) is false))
|
||||
if (destGroup is not null && (destGroup.PropertyTypes?.SupportsPublishing != isPublishing || destGroup.PropertyTypes.SequenceEqual(destProperties) is false))
|
||||
{
|
||||
destGroup.PropertyTypes = new PropertyTypeCollection(isPublishing, destProperties);
|
||||
destGroups.Add(destGroup);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
public class DictionaryMapDefinition : IMapDefinition
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly CommonMapper _commonMapper;
|
||||
private readonly CommonMapper? _commonMapper;
|
||||
|
||||
[Obsolete("Use the constructor with the CommonMapper")]
|
||||
public DictionaryMapDefinition(ILocalizationService localizationService)
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
// check if this property is flagged as sensitive
|
||||
var isSensitiveProperty = memberType?.IsSensitiveProperty(prop.Alias) ?? false;
|
||||
// check permissions for viewing sensitive data
|
||||
if (isSensitiveProperty && (_backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser.HasAccessToSensitiveData() == false))
|
||||
if (isSensitiveProperty && (_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.HasAccessToSensitiveData() == false))
|
||||
{
|
||||
// mark this property as sensitive
|
||||
prop.IsSensitive = true;
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace Umbraco.Cms.Core.Models
|
||||
|
||||
public PartialViewMacroModel(IPublishedContent page,
|
||||
int macroId,
|
||||
string macroAlias,
|
||||
string macroName,
|
||||
IDictionary<string, object> macroParams)
|
||||
string? macroAlias,
|
||||
string? macroName,
|
||||
IDictionary<string, object?> macroParams)
|
||||
{
|
||||
Content = page;
|
||||
MacroParameters = macroParams;
|
||||
@@ -23,9 +23,9 @@ namespace Umbraco.Cms.Core.Models
|
||||
}
|
||||
|
||||
public IPublishedContent Content { get; }
|
||||
public string MacroName { get; }
|
||||
public string MacroAlias { get; }
|
||||
public string? MacroName { get; }
|
||||
public string? MacroAlias { get; }
|
||||
public int MacroId { get; }
|
||||
public IDictionary<string, object> MacroParameters { get; }
|
||||
public IDictionary<string, object?> MacroParameters { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Extensions
|
||||
/// <returns>Parameter value if available, the default value that was passed otherwise.</returns>
|
||||
public static T? GetParameterValue<T>(this PartialViewMacroModel partialViewMacroModel, string parameterAlias, T defaultValue)
|
||||
{
|
||||
if (partialViewMacroModel.MacroParameters.ContainsKey(parameterAlias) == false || string.IsNullOrEmpty(partialViewMacroModel.MacroParameters[parameterAlias].ToString()))
|
||||
if (partialViewMacroModel.MacroParameters.ContainsKey(parameterAlias) == false || string.IsNullOrEmpty(partialViewMacroModel.MacroParameters[parameterAlias]?.ToString()))
|
||||
return defaultValue;
|
||||
|
||||
var attempt = partialViewMacroModel.MacroParameters[parameterAlias].TryConvertTo(typeof(T));
|
||||
|
||||
@@ -50,25 +50,25 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="modelTypes">The model types map.</param>
|
||||
/// <returns>The actual CLR type.</returns>
|
||||
public static Type Map(Type type, Dictionary<string, Type> modelTypes)
|
||||
public static Type Map(Type type, Dictionary<string, Type>? modelTypes)
|
||||
=> Map(type, modelTypes, false);
|
||||
|
||||
public static Type Map(Type type, Dictionary<string, Type> modelTypes, bool dictionaryIsInvariant)
|
||||
public static Type Map(Type type, Dictionary<string, Type>? modelTypes, bool dictionaryIsInvariant)
|
||||
{
|
||||
// it may be that senders forgot to send an invariant dictionary (garbage-in)
|
||||
if (!dictionaryIsInvariant)
|
||||
if (modelTypes is not null && !dictionaryIsInvariant)
|
||||
modelTypes = new Dictionary<string, Type>(modelTypes, StringComparer.InvariantCultureIgnoreCase);
|
||||
|
||||
if (type is ModelType modelType)
|
||||
{
|
||||
if (modelTypes.TryGetValue(modelType.ContentTypeAlias, out var actualType))
|
||||
if (modelTypes?.TryGetValue(modelType.ContentTypeAlias, out var actualType) ?? false)
|
||||
return actualType;
|
||||
throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{modelType.ContentTypeAlias}\".");
|
||||
}
|
||||
|
||||
if (type is ModelTypeArrayType arrayType)
|
||||
{
|
||||
if (modelTypes.TryGetValue(arrayType.ContentTypeAlias, out var actualType))
|
||||
if (modelTypes?.TryGetValue(arrayType.ContentTypeAlias, out var actualType) ?? false)
|
||||
return actualType.MakeArrayType();
|
||||
throw new InvalidOperationException($"Don't know how to map ModelType with content type alias \"{arrayType.ContentTypeAlias}\".");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
public string? NodeName { get; set; }
|
||||
|
||||
[DataMember(Name = "type")]
|
||||
public string NodeType { get; set; }
|
||||
public string? NodeType { get; set; }
|
||||
|
||||
[DataMember(Name = "udi")]
|
||||
public Udi NodeUdi => Udi.Create(NodeType, NodeKey);
|
||||
|
||||
Reference in New Issue
Block a user