Add nullability to core project
This commit is contained in:
@@ -33,7 +33,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// </summary>
|
||||
/// <remarks>Contains one <c>IPublishedProperty</c> for each property defined for the content type, including
|
||||
/// inherited properties. Some properties may have no value.</remarks>
|
||||
IEnumerable<IPublishedProperty> Properties { get; }
|
||||
IEnumerable<IPublishedProperty>? Properties { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a property identified by its alias.
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// <para>otherwise return a property -- that may have no value (ie <c>HasValue</c> is <c>false</c>).</para>
|
||||
/// <para>The alias is case-insensitive.</para>
|
||||
/// </remarks>
|
||||
IPublishedProperty GetProperty(string alias);
|
||||
IPublishedProperty? GetProperty(string alias);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// </summary>
|
||||
/// <param name="alias">The model type alias.</param>
|
||||
/// <returns>A List{T} of the strongly-typed model, exposed as an IList.</returns>
|
||||
IList CreateModelList(string alias);
|
||||
IList? CreateModelList(string alias);
|
||||
|
||||
/// <summary>
|
||||
/// Maps a CLR type that may contain model types, to an actual CLR type.
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// Determines whether a value is an actual value, or not a value.
|
||||
/// </summary>
|
||||
/// <remarks>Used by property.HasValue and, for instance, in fallback scenarios.</remarks>
|
||||
bool? IsValue(object value, PropertyValueLevel level);
|
||||
bool? IsValue(object? value, PropertyValueLevel level);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property cache level.
|
||||
@@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// <param name="source">The source value.</param>
|
||||
/// <param name="preview">A value indicating whether content should be considered draft.</param>
|
||||
/// <returns>The intermediate value.</returns>
|
||||
object ConvertSourceToInter(IPublishedElement owner, object source, bool preview);
|
||||
object? ConvertSourceToInter(IPublishedElement owner, object? source, bool preview);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the intermediate value into the object value.
|
||||
@@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// <param name="inter">The intermediate value.</param>
|
||||
/// <param name="preview">A value indicating whether content should be considered draft.</param>
|
||||
/// <returns>The object value.</returns>
|
||||
object ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
|
||||
object? ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the intermediate value into the XPath value.
|
||||
@@ -84,7 +84,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// <remarks>
|
||||
/// <para>The XPath value can be either a string or an XPathNavigator.</para>
|
||||
/// </remarks>
|
||||
object? ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview);
|
||||
object? ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property model CLR type.
|
||||
|
||||
@@ -122,10 +122,10 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
#region Properties
|
||||
|
||||
/// <inheritdoc cref="IPublishedElement.Properties"/>
|
||||
public virtual IEnumerable<IPublishedProperty> Properties => _content.Properties;
|
||||
public virtual IEnumerable<IPublishedProperty>? Properties => _content.Properties;
|
||||
|
||||
/// <inheritdoc cref="IPublishedElement.GetProperty(string)"/>
|
||||
public virtual IPublishedProperty GetProperty(string alias)
|
||||
public virtual IPublishedProperty? GetProperty(string alias)
|
||||
{
|
||||
return _content.GetProperty(alias);
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
public Guid Key => _content.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IPublishedProperty> Properties => _content.Properties;
|
||||
public IEnumerable<IPublishedProperty>? Properties => _content.Properties;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IPublishedProperty GetProperty(string alias) => _content.GetProperty(alias);
|
||||
public IPublishedProperty? GetProperty(string alias) => _content.GetProperty(alias);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IList CreateModelList(string alias)
|
||||
public IList? CreateModelList(string alias)
|
||||
{
|
||||
// fail fast
|
||||
if (_modelInfos == null)
|
||||
@@ -118,7 +118,8 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
|
||||
var listType = typeof(List<>).MakeGenericType(modelInfo.ModelType);
|
||||
ctor = modelInfo.ListCtor = ReflectionUtilities.EmitConstructor<Func<IList>>(declaring: listType);
|
||||
return ctor();
|
||||
if(ctor is not null) return ctor();
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool? IsValue(object value, PropertyValueLevel level)
|
||||
public bool? IsValue(object? value, PropertyValueLevel level)
|
||||
{
|
||||
if (!_initialized) Initialize();
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public object ConvertSourceToInter(IPublishedElement owner, object source, bool preview)
|
||||
public object? ConvertSourceToInter(IPublishedElement owner, object? source, bool preview)
|
||||
{
|
||||
if (!_initialized) Initialize();
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public object ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
|
||||
public object? ConvertInterToObject(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview)
|
||||
{
|
||||
if (!_initialized) Initialize();
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
|
||||
public object? ConvertInterToXPath(IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview)
|
||||
{
|
||||
if (!_initialized) Initialize();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
/// </summary>
|
||||
public class PublishedValueFallback : IPublishedValueFallback
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly ILocalizationService? _localizationService;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
@@ -197,7 +197,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
|
||||
var visited = new HashSet<int>();
|
||||
|
||||
var language = culture is not null ? _localizationService.GetLanguageByIsoCode(culture) : null;
|
||||
var language = culture is not null ? _localizationService?.GetLanguageByIsoCode(culture) : null;
|
||||
if (language == null) return false;
|
||||
|
||||
while (true)
|
||||
@@ -208,7 +208,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
if (visited.Contains(language2Id)) return false;
|
||||
visited.Add(language2Id);
|
||||
|
||||
var language2 = _localizationService.GetLanguageById(language2Id);
|
||||
var language2 = _localizationService?.GetLanguageById(language2Id);
|
||||
if (language2 == null) return false;
|
||||
var culture2 = language2.IsoCode;
|
||||
|
||||
@@ -231,7 +231,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
|
||||
var visited = new HashSet<int>();
|
||||
|
||||
var language = culture is not null ? _localizationService.GetLanguageByIsoCode(culture) : null;
|
||||
var language = culture is not null ? _localizationService?.GetLanguageByIsoCode(culture) : null;
|
||||
if (language == null) return false;
|
||||
|
||||
while (true)
|
||||
@@ -242,7 +242,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
if (visited.Contains(language2Id)) return false;
|
||||
visited.Add(language2Id);
|
||||
|
||||
var language2 = _localizationService.GetLanguageById(language2Id);
|
||||
var language2 = _localizationService?.GetLanguageById(language2Id);
|
||||
if (language2 == null) return false;
|
||||
var culture2 = language2.IsoCode;
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
// TODO: _localizationService.GetXxx() is expensive, it deep clones objects
|
||||
// we want _localizationService.GetReadOnlyXxx() returning IReadOnlyLanguage which cannot be saved back = no need to clone
|
||||
|
||||
var language = culture is not null ? _localizationService.GetLanguageByIsoCode(culture) : null;
|
||||
var language = culture is not null ? _localizationService?.GetLanguageByIsoCode(culture) : null;
|
||||
if (language == null) return false;
|
||||
|
||||
while (true)
|
||||
@@ -279,7 +279,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
if (visited.Contains(language2Id)) return false;
|
||||
visited.Add(language2Id);
|
||||
|
||||
var language2 = _localizationService.GetLanguageById(language2Id);
|
||||
var language2 = _localizationService?.GetLanguageById(language2Id);
|
||||
if (language2 == null) return false;
|
||||
var culture2 = language2.IsoCode;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
public class RawValueProperty : PublishedPropertyBase
|
||||
{
|
||||
private readonly object _sourceValue; //the value in the db
|
||||
private readonly Lazy<object> _objectValue;
|
||||
private readonly Lazy<object?> _objectValue;
|
||||
private readonly Lazy<object?> _xpathValue;
|
||||
|
||||
// RawValueProperty does not (yet?) support variants,
|
||||
@@ -46,9 +46,9 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
|
||||
|
||||
_sourceValue = sourceValue;
|
||||
|
||||
var interValue = new Lazy<object>(() => PropertyType.ConvertSourceToInter(content, _sourceValue, isPreviewing));
|
||||
_objectValue = new Lazy<object>(() => PropertyType.ConvertInterToObject(content, PropertyCacheLevel.Unknown, interValue.Value, isPreviewing));
|
||||
_xpathValue = new Lazy<object?>(() => PropertyType.ConvertInterToXPath(content, PropertyCacheLevel.Unknown, interValue.Value, isPreviewing));
|
||||
var interValue = new Lazy<object?>(() => PropertyType.ConvertSourceToInter(content, _sourceValue, isPreviewing));
|
||||
_objectValue = new Lazy<object?>(() => PropertyType.ConvertInterToObject(content, PropertyCacheLevel.Unknown, interValue?.Value, isPreviewing));
|
||||
_xpathValue = new Lazy<object?>(() => PropertyType.ConvertInterToXPath(content, PropertyCacheLevel.Unknown, interValue?.Value, isPreviewing));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user