Started using nullable reference types..

This commit is contained in:
Bjarke Berg
2021-12-16 13:44:20 +01:00
parent 11eaf176a9
commit 2ec92057c5
192 changed files with 752 additions and 723 deletions

View File

@@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Models
/// <param name="parent">Parent <see cref="IContent"/> object</param>
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="culture">An optional culture.</param>
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
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="userId">The identifier of the user creating the Content object</param>
/// <param name="culture">An optional culture.</param>
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
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="properties">Collection of properties</param>
/// <param name="culture">An optional culture.</param>
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
/// <param name="parentId">Id of the Parent content</param>
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="culture">An optional culture.</param>
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
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="userId">The identifier of the user creating the Content object</param>
/// <param name="culture">An optional culture.</param>
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
/// <param name="contentType">ContentType for the current Content object</param>
/// <param name="properties">Collection of properties</param>
/// <param name="culture">An optional culture.</param>
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));

View File

@@ -43,7 +43,7 @@ namespace Umbraco.Cms.Core.Models
/// <summary>
/// Initializes a new instance of the <see cref="ContentBase"/> class.
/// </summary>
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
/// <summary>
/// Initializes a new instance of the <see cref="ContentBase"/> class.
/// </summary>
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);
/// <inheritdoc />
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
}
/// <inheritdoc />
public TValue GetValue<TValue>(string propertyTypeAlias, string culture = null, string segment = null, bool published = false)
public TValue GetValue<TValue>(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
}
/// <inheritdoc />
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}\".");

View File

@@ -19,7 +19,7 @@ namespace Umbraco.Extensions
/// <param name="urlSegmentProviders"></param>
/// <param name="culture">The culture.</param>
/// <returns>The URL segment.</returns>
public static string GetUrlSegment(this IContentBase content, IShortStringHelper shortStringHelper, IEnumerable<IUrlSegmentProvider> urlSegmentProviders, string culture = null)
public static string GetUrlSegment(this IContentBase content, IShortStringHelper shortStringHelper, IEnumerable<IUrlSegmentProvider> 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;
}

View File

@@ -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; }
/// <summary>
/// Flags the property to denote that it can contain sensitive data
@@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
/// </remarks>
[DataMember(Name = "culture")]
[ReadOnly(true)]
public string Culture { get; set; }
public string? Culture { get; set; }
/// <summary>
/// The segment of the property
@@ -62,12 +62,12 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
/// </remarks>
[DataMember(Name = "segment")]
[ReadOnly(true)]
public string Segment { get; set; }
public string? Segment { get; set; }
/// <summary>
/// Used internally during model mapping
/// </summary>
[IgnoreDataMember]
public IDataEditor PropertyEditor { get; set; }
public IDataEditor? PropertyEditor { get; set; }
}
}

View File

@@ -18,6 +18,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
/// the content app should be displayed or not, and return either a <see cref="ContentApp"/>
/// instance, or null.</para>
/// </remarks>
ContentApp GetContentAppFor(object source, IEnumerable<IReadOnlyUserGroup> userGroups);
ContentApp? GetContentAppFor(object source, IEnumerable<IReadOnlyUserGroup> userGroups);
}
}

View File

@@ -22,7 +22,7 @@ namespace Umbraco.Extensions
/// <param name="merge">A value indicating whether to merge the tags with existing tags instead of replacing them.</param>
/// <param name="culture">A culture, for multi-lingual properties.</param>
/// <param name="propertyEditors"></param>
public static void AssignTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable<string> tags, bool merge = false, string culture = null)
public static void AssignTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable<string> tags, bool merge = false, string? culture = null)
{
content.GetTagProperty(propertyTypeAlias).AssignTags(propertyEditors, dataTypeService, serializer, tags, merge, culture);
}
@@ -36,7 +36,7 @@ namespace Umbraco.Extensions
/// <param name="tags">The tags.</param>
/// <param name="culture">A culture, for multi-lingual properties.</param>
/// <param name="propertyEditors"></param>
public static void RemoveTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable<string> tags, string culture = null)
public static void RemoveTags(this IContentBase content, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string propertyTypeAlias, IEnumerable<string> tags, string? culture = null)
{
content.GetTagProperty(propertyTypeAlias).RemoveTags(propertyEditors, dataTypeService, serializer, tags, culture);
}

View File

@@ -112,19 +112,19 @@ namespace Umbraco.Cms.Core.Models
/// Gets the value of a Property
/// </summary>
/// <remarks>Values 'null' and 'empty' are equivalent for culture and segment.</remarks>
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);
/// <summary>
/// Gets the typed value of a Property
/// </summary>
/// <remarks>Values 'null' and 'empty' are equivalent for culture and segment.</remarks>
TValue GetValue<TValue>(string propertyTypeAlias, string culture = null, string segment = null, bool published = false);
TValue GetValue<TValue>(string propertyTypeAlias, string? culture = null, string? segment = null, bool published = false);
/// <summary>
/// Sets the (edited) value of a Property
/// </summary>
/// <remarks>Values 'null' and 'empty' are equivalent for culture and segment.</remarks>
void SetValue(string propertyTypeAlias, object value, string culture = null, string segment = null);
void SetValue(string propertyTypeAlias, object value, string? culture = null, string? segment = null);
}
}

View File

@@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Models
/// <summary>
/// Converts a property value to a value for the editor.
/// </summary>
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...

View File

@@ -25,12 +25,12 @@ namespace Umbraco.Cms.Core.Models
/// <summary>
/// Gets the value.
/// </summary>
object GetValue(string culture = null, string segment = null, bool published = false);
object GetValue(string? culture = null, string? segment = null, bool published = false);
/// <summary>
/// Sets a value.
/// </summary>
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 = "*");

View File

@@ -241,7 +241,7 @@ namespace Umbraco.Cms.Core.Models
/// <summary>
/// Gets the value.
/// </summary>
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
/// <summary>
/// Sets a value.
/// </summary>
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();

View File

@@ -44,7 +44,7 @@ namespace Umbraco.Extensions
/// <param name="culture">A culture, for multi-lingual properties.</param>
/// <param name="propertyEditors"></param>
/// <param name="dataTypeService"></param>
public static void AssignTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable<string> tags, bool merge = false, string culture = null)
public static void AssignTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable<string> tags, bool merge = false, string? culture = null)
{
if (property == null) throw new ArgumentNullException(nameof(property));
@@ -100,7 +100,7 @@ namespace Umbraco.Extensions
/// <param name="culture">A culture, for multi-lingual properties.</param>
/// <param name="propertyEditors"></param>
/// <param name="dataTypeService"></param>
public static void RemoveTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable<string> tags, string culture = null)
public static void RemoveTags(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, IEnumerable<string> 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<string> GetTagsValue(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IJsonSerializer serializer, string culture = null)
public static IEnumerable<string> 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<string> GetTagsValue(this IProperty property, TagsStorageType storageType, IJsonSerializer serializer, char delimiter, string culture = null)
private static IEnumerable<string> GetTagsValue(this IProperty property, TagsStorageType storageType, IJsonSerializer serializer, char delimiter, string? culture = null)
{
if (property == null) throw new ArgumentNullException(nameof(property));

View File

@@ -23,7 +23,7 @@
/// <para>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).</para>
/// </remarks>
bool HasValue(string culture = null, string segment = null);
bool HasValue(string? culture = null, string? segment = null);
/// <summary>
/// Gets the source value of the property.
@@ -37,7 +37,7 @@
/// <para>If you're using that value, you're probably wrong, unless you're doing some internal
/// Umbraco stuff.</para>
/// </remarks>
object GetSourceValue(string culture = null, string segment = null);
object GetSourceValue(string? culture = null, string? segment = null);
/// <summary>
/// Gets the object value of the property.
@@ -47,7 +47,7 @@
/// <para>It can be null, or any type of CLR object.</para>
/// <para>It has been fully prepared and processed by the appropriate converter.</para>
/// </remarks>
object GetValue(string culture = null, string segment = null);
object GetValue(string? culture = null, string? segment = null);
/// <summary>
/// Gets the XPath value of the property.
@@ -57,6 +57,6 @@
/// <para>It must be either null, or a string, or an XPathNavigator.</para>
/// <para>It has been fully prepared and processed by the appropriate converter.</para>
/// </remarks>
object GetXPathValue(string culture = null, string segment = null);
object GetXPathValue(string? culture = null, string? segment = null);
}
}

View File

@@ -25,7 +25,7 @@
/// so the variant context should be used to contextualize them (see our default implementation in
/// the web project.</para>
/// </remarks>
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);
/// <summary>
/// Tries to get a fallback value for a property.
@@ -45,7 +45,7 @@
/// <para>At property level, property.GetValue() does *not* implement fallback, and one has to
/// get property.Value() or property.Value{T}() to trigger fallback.</para>
/// </remarks>
bool TryGetValue<T>(IPublishedProperty property, string culture, string segment, Fallback fallback, T defaultValue, out T value);
bool TryGetValue<T>(IPublishedProperty property, string? culture, string? segment, Fallback fallback, T? defaultValue, out T value);
/// <summary>
/// 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.</para>
/// <para>It can only fallback at element level (no recurse).</para>
/// </remarks>
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);
/// <summary>
/// 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.</para>
/// <para>It can only fallback at element level (no recurse).</para>
/// </remarks>
bool TryGetValue<T>(IPublishedElement content, string alias, string culture, string segment, Fallback fallback, T defaultValue, out T value);
bool TryGetValue<T>(IPublishedElement content, string alias, string? culture, string? segment, Fallback fallback, T? defaultValue, out T value);
/// <summary>
/// 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".</para>
/// </remarks>
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);
/// <summary>
/// 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".</para>
/// </remarks>
bool TryGetValue<T>(IPublishedContent content, string alias, string culture, string segment, Fallback fallback, T defaultValue, out T value, out IPublishedProperty noValueProperty);
bool TryGetValue<T>(IPublishedContent content, string alias, string? culture, string? segment, Fallback fallback, T defaultValue, out T value, out IPublishedProperty noValueProperty);
}
}

View File

@@ -55,15 +55,15 @@ namespace Umbraco.Cms.Core.Models.PublishedContent
public string Alias => PropertyType.Alias;
/// <inheritdoc />
public abstract bool HasValue(string culture = null, string segment = null);
public abstract bool HasValue(string culture = null, string? segment = null);
/// <inheritdoc />
public abstract object GetSourceValue(string culture = null, string segment = null);
public abstract object GetSourceValue(string culture = null, string? segment = null);
/// <inheritdoc />
public abstract object GetValue(string culture = null, string segment = null);
public abstract object GetValue(string culture = null, string? segment = null);
/// <inheritdoc />
public abstract object GetXPathValue(string culture = null, string segment = null);
public abstract object GetXPathValue(string culture = null, string? segment = null);
}
}

View File

@@ -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)

View File

@@ -8,7 +8,7 @@
/// <summary>
/// Initializes a new instance of the <see cref="VariationContext"/> class.
/// </summary>
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