Add nullability to web.common

This commit is contained in:
Nikolaj Geisle
2022-03-29 13:44:21 +02:00
parent 86ae730b1e
commit b52c4e50cf
151 changed files with 731 additions and 675 deletions

View File

@@ -122,8 +122,12 @@ namespace Umbraco.Extensions
pluginFolder,
umbracoPluginSettings);
IWebHostEnvironment webHostEnvironment = app.ApplicationServices.GetService<IWebHostEnvironment>();
webHostEnvironment.WebRootFileProvider = webHostEnvironment.WebRootFileProvider.ConcatComposite(new PrependBasePathFileProvider(Constants.SystemDirectories.AppPlugins, pluginFileProvider));
IWebHostEnvironment? webHostEnvironment = app.ApplicationServices.GetService<IWebHostEnvironment>();
if (webHostEnvironment is not null)
{
webHostEnvironment.WebRootFileProvider = webHostEnvironment.WebRootFileProvider.ConcatComposite(new PrependBasePathFileProvider(Constants.SystemDirectories.AppPlugins, pluginFileProvider));
}
}
return app;

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Extensions
public const string DefaultFolder = "blocklist/";
public const string DefaultTemplate = "default";
public static IHtmlContent GetBlockListHtml(this IHtmlHelper html, BlockListModel model, string template = DefaultTemplate)
public static IHtmlContent GetBlockListHtml(this IHtmlHelper html, BlockListModel? model, string template = DefaultTemplate)
{
if (model?.Count == 0) return new HtmlString(string.Empty);

View File

@@ -26,7 +26,7 @@ namespace Umbraco.Extensions
/// <param name="cacheKey">used to cache the partial view, this key could change if it is cached by page or by member</param>
/// <param name="viewData"></param>
/// <returns></returns>
public static IHtmlContent CachedPartialView(
public static IHtmlContent? CachedPartialView(
this AppCaches appCaches,
IHostingEnvironment hostingEnvironment,
IUmbracoContext umbracoContext,
@@ -35,7 +35,7 @@ namespace Umbraco.Extensions
object model,
TimeSpan cacheTimeout,
string cacheKey,
ViewDataDictionary viewData = null
ViewDataDictionary? viewData = null
)
{
//disable cached partials in debug mode: http://issues.umbraco.org/issue/U4-5940

View File

@@ -24,7 +24,7 @@ namespace Umbraco.Extensions
if (convention.Metadata.OfType<ISuppressMatchingMetadata>().FirstOrDefault()?.SuppressMatching != true)
{
// Get the controller action descriptor
ControllerActionDescriptor actionDescriptor = convention.Metadata.OfType<ControllerActionDescriptor>().FirstOrDefault();
ControllerActionDescriptor? actionDescriptor = convention.Metadata.OfType<ControllerActionDescriptor>().FirstOrDefault();
if (actionDescriptor != null)
{
// This is more or less like the IApplicationModelProvider, it allows us to add filters, etc... to the ControllerActionDescriptor

View File

@@ -19,7 +19,7 @@ namespace Umbraco.Extensions
string prefixPathSegment,
string defaultAction = "Index",
bool includeControllerNameInRoute = true,
object constraints = null)
object? constraints = null)
{
var controllerName = ControllerExtensions.GetControllerName(controllerType);
@@ -75,7 +75,7 @@ namespace Umbraco.Extensions
string prefixPathSegment,
string defaultAction = "Index",
bool includeControllerNameInRoute = true,
object constraints = null)
object? constraints = null)
where T : ControllerBase
=> endpoints.MapUmbracoRoute(typeof(T), rootSegment, areaName, prefixPathSegment, defaultAction, includeControllerNameInRoute, constraints);
@@ -89,7 +89,7 @@ namespace Umbraco.Extensions
string areaName,
bool isBackOffice,
string defaultAction = "Index",
object constraints = null)
object? constraints = null)
where T : ControllerBase
=> endpoints.MapUmbracoApiRoute(typeof(T), rootSegment, areaName, isBackOffice, defaultAction, constraints);
@@ -103,7 +103,7 @@ namespace Umbraco.Extensions
string areaName,
bool isBackOffice,
string defaultAction = "Index",
object constraints = null)
object? constraints = null)
{
string prefixPathSegment = isBackOffice
? areaName.IsNullOrWhiteSpace()
@@ -130,7 +130,7 @@ namespace Umbraco.Extensions
string areaName,
string defaultAction = "Index",
bool includeControllerNameInRoute = true,
object constraints = null)
object? constraints = null)
{
// If there is an area name it's a plugin controller, and we should use the area name instead of surface
string prefixPathSegment = areaName.IsNullOrWhiteSpace() ? "Surface" : areaName;

View File

@@ -68,7 +68,7 @@ namespace Umbraco.Extensions
/// <param name="items"></param>
/// <param name="key"></param>
/// <returns></returns>
public static T GetValue<T>(this FormCollection items, string key)
public static T? GetValue<T>(this FormCollection items, string key)
{
if (items.TryGetValue(key, out var val) == false || string.IsNullOrEmpty(val))
{
@@ -97,7 +97,7 @@ namespace Umbraco.Extensions
var converted = val.TryConvertTo<T>();
return converted.Success
? converted.Result
? converted.Result!
: throw new InvalidOperationException($"The required query string parameter {key} cannot be converted to type {typeof(T)}");
}
}

View File

@@ -26,7 +26,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
string cropAlias,
UrlMode urlMode = UrlMode.Default) =>
@@ -41,7 +41,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(this MediaWithCrops mediaWithCrops, string cropAlias, UrlMode urlMode = UrlMode.Default)
public static string? GetCropUrl(this MediaWithCrops mediaWithCrops, string cropAlias, UrlMode urlMode = UrlMode.Default)
=> ImageCropperTemplateCoreExtensions.GetCropUrl(mediaWithCrops, cropAlias, ImageUrlGenerator, PublishedValueFallback, PublishedUrlProvider, urlMode);
/// <summary>
@@ -54,7 +54,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The image crop URL.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
ImageCropperValue imageCropperValue,
string cropAlias,
@@ -71,7 +71,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
string propertyAlias,
string cropAlias,
@@ -88,7 +88,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(this MediaWithCrops mediaWithCrops, string propertyAlias, string cropAlias, UrlMode urlMode = UrlMode.Default)
public static string? GetCropUrl(this MediaWithCrops mediaWithCrops, string propertyAlias, string cropAlias, UrlMode urlMode = UrlMode.Default)
=> ImageCropperTemplateCoreExtensions.GetCropUrl(mediaWithCrops, propertyAlias, cropAlias, ImageUrlGenerator, PublishedValueFallback, PublishedUrlProvider, urlMode);
/// <summary>
@@ -113,19 +113,19 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
int? width = null,
int? height = null,
string propertyAlias = Cms.Core.Constants.Conventions.Media.File,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
bool cacheBuster = true,
string furtherOptions = null,
string? furtherOptions = null,
UrlMode urlMode = UrlMode.Default)
=> mediaItem.GetCropUrl(
ImageUrlGenerator,
@@ -167,19 +167,19 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this MediaWithCrops mediaWithCrops,
int? width = null,
int? height = null,
string propertyAlias = Cms.Core.Constants.Conventions.Media.File,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
bool cacheBuster = true,
string furtherOptions = null,
string? furtherOptions = null,
UrlMode urlMode = UrlMode.Default)
=> mediaWithCrops.GetCropUrl(
ImageUrlGenerator,
@@ -220,19 +220,19 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this string imageUrl,
int? width = null,
int? height = null,
string imageCropperValue = null,
string cropAlias = null,
string? imageCropperValue = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
string cacheBusterValue = null,
string furtherOptions = null)
string? cacheBusterValue = null,
string? furtherOptions = null)
=> imageUrl.GetCropUrl(
ImageUrlGenerator,
width,
@@ -269,19 +269,19 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this string imageUrl,
ImageCropperValue cropDataSet,
int? width = null,
int? height = null,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
string cacheBusterValue = null,
string furtherOptions = null)
string? cacheBusterValue = null,
string? furtherOptions = null)
=> imageUrl.GetCropUrl(
ImageUrlGenerator,
cropDataSet,
@@ -301,6 +301,6 @@ namespace Umbraco.Extensions
public static string GetLocalCropUrl(
this MediaWithCrops mediaWithCrops,
string alias,
string cacheBusterValue = null) => mediaWithCrops.LocalCrops.Src + mediaWithCrops.LocalCrops.GetCropUrl(alias, ImageUrlGenerator, cacheBusterValue: cacheBusterValue);
string? cacheBusterValue = null) => mediaWithCrops.LocalCrops.Src + mediaWithCrops.LocalCrops.GetCropUrl(alias, ImageUrlGenerator, cacheBusterValue: cacheBusterValue);
}
}

View File

@@ -50,7 +50,7 @@ namespace Umbraco.Extensions
private static IPublishedValueFallback PublishedValueFallback { get; } =
StaticServiceProvider.Instance.GetRequiredService<IPublishedValueFallback>();
private static IPublishedSnapshot PublishedSnapshot
private static IPublishedSnapshot? PublishedSnapshot
{
get
{
@@ -75,7 +75,7 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="content">The internal published content.</param>
/// <returns>The strongly typed published content model.</returns>
public static IPublishedContent CreateModel(
public static IPublishedContent? CreateModel(
this IPublishedContent content)
=> content.CreateModel(PublishedModelFactory);
@@ -84,9 +84,9 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="content">The content item.</param>
/// <param name="culture">The specific culture to get the name for. If null is used the current culture is used (Default is null).</param>
public static string Name(
public static string? Name(
this IPublishedContent content,
string culture = null)
string? culture = null)
=> content.Name(VariationContextAccessor, culture);
/// <summary>
@@ -94,9 +94,9 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="content">The content item.</param>
/// <param name="culture">The specific culture to get the URL segment for. If null is used the current culture is used (Default is null).</param>
public static string UrlSegment(
public static string? UrlSegment(
this IPublishedContent content,
string culture = null)
string? culture = null)
=> content.UrlSegment(VariationContextAccessor, culture);
/// <summary>
@@ -106,7 +106,7 @@ namespace Umbraco.Extensions
/// <param name="culture">The specific culture to get the name for. If null is used the current culture is used (Default is null).</param>
public static DateTime CultureDate(
this IPublishedContent content,
string culture = null)
string? culture = null)
=> content.CultureDate(VariationContextAccessor, culture);
/// <summary>
@@ -159,8 +159,8 @@ namespace Umbraco.Extensions
public static bool HasValue(
this IPublishedContent content,
string alias,
string culture = null,
string segment = null,
string? culture = null,
string? segment = null,
Fallback fallback = default)
=>
content.HasValue(PublishedValueFallback, alias, culture, segment, fallback);
@@ -175,7 +175,7 @@ namespace Umbraco.Extensions
/// <param name="fallback">Optional fallback strategy.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>The value of the content's property identified by the alias, if it exists, otherwise a default value.</returns>
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);
/// <summary>
@@ -189,7 +189,7 @@ namespace Umbraco.Extensions
/// <param name="fallback">Optional fallback strategy.</param>
/// <param name="defaultValue">The default value.</param>
/// <returns>The value of the content's property identified by the alias, converted to the specified type.</returns>
public static T Value<T>(this IPublishedContent content, string alias, string? culture = null, string? segment = null, Fallback fallback = default, T defaultValue = default)
public static T? Value<T>(this IPublishedContent content, string alias, string? culture = null, string? segment = null, Fallback fallback = default, T? defaultValue = default)
=> content.Value<T>(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
/// <summary>
@@ -218,7 +218,7 @@ namespace Umbraco.Extensions
/// </remarks>
public static IEnumerable<T> DescendantsOrSelf<T>(
this IEnumerable<IPublishedContent> parentNodes,
string culture = null)
string? culture = null)
where T : class, IPublishedContent
=> parentNodes.DescendantsOrSelf<T>(VariationContextAccessor, culture);
@@ -240,7 +240,7 @@ namespace Umbraco.Extensions
where T : class, IPublishedContent
=> content.Descendants<T>(VariationContextAccessor, level, culture);
public static IEnumerable<IPublishedContent> DescendantsOrSelf(this IPublishedContent content, string culture = null)
public static IEnumerable<IPublishedContent> DescendantsOrSelf(this IPublishedContent content, string? culture = null)
=> content.DescendantsOrSelf(VariationContextAccessor, culture);
@@ -258,39 +258,39 @@ namespace Umbraco.Extensions
where T : class, IPublishedContent
=> content.DescendantsOrSelf<T>(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<T>(this IPublishedContent content, string? culture = null)
public static T? Descendant<T>(this IPublishedContent content, string? culture = null)
where T : class, IPublishedContent
=> content.Descendant<T>(VariationContextAccessor, culture);
public static T Descendant<T>(this IPublishedContent content, int level, string? culture = null)
public static T? Descendant<T>(this IPublishedContent content, int level, string? culture = null)
where T : class, IPublishedContent
=> content.Descendant<T>(VariationContextAccessor, level, culture);
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<T>(this IPublishedContent content, string? culture = null)
public static T? DescendantOrSelf<T>(this IPublishedContent content, string? culture = null)
where T : class, IPublishedContent
=> content.DescendantOrSelf<T>(VariationContextAccessor, culture);
public static T DescendantOrSelf<T>(this IPublishedContent content, int level, string? culture = null)
public static T? DescendantOrSelf<T>(this IPublishedContent content, int level, string? culture = null)
where T : class, IPublishedContent
=> content.DescendantOrSelf<T>(VariationContextAccessor, level, culture);
@@ -317,7 +317,7 @@ namespace Umbraco.Extensions
/// However, if an empty string is specified only invariant children are returned.
/// </para>
/// </remarks>
public static IEnumerable<IPublishedContent> Children(this IPublishedContent content, string? culture = null)
public static IEnumerable<IPublishedContent>? Children(this IPublishedContent content, string? culture = null)
=> content.Children(VariationContextAccessor, culture);
/// <summary>
@@ -330,7 +330,7 @@ namespace Umbraco.Extensions
/// <remarks>
/// <para>Children are sorted by their sortOrder.</para>
/// </remarks>
public static IEnumerable<IPublishedContent> Children(this IPublishedContent content, Func<IPublishedContent, bool> predicate, string? culture = null)
public static IEnumerable<IPublishedContent>? Children(this IPublishedContent content, Func<IPublishedContent, bool> predicate, string? culture = null)
=> content.Children(VariationContextAccessor, predicate, culture);
/// <summary>
@@ -340,7 +340,7 @@ namespace Umbraco.Extensions
/// <param name="culture">The specific culture to filter for. If null is used the current culture is used. (Default is null)</param>
/// <param name="contentTypeAlias">The content type alias.</param>
/// <returns>The children of the content, of any of the specified types.</returns>
public static IEnumerable<IPublishedContent> ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null)
public static IEnumerable<IPublishedContent>? ChildrenOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null)
=> content.ChildrenOfType(VariationContextAccessor, contentTypeAlias, culture);
/// <summary>
@@ -353,31 +353,31 @@ namespace Umbraco.Extensions
/// <remarks>
/// <para>Children are sorted by their sortOrder.</para>
/// </remarks>
public static IEnumerable<T> Children<T>(this IPublishedContent content, string? culture = null)
public static IEnumerable<T>? Children<T>(this IPublishedContent content, string? culture = null)
where T : class, IPublishedContent
=> content.Children<T>(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);
/// <summary>
/// Gets the first child of the content, of a given content type.
/// </summary>
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<IPublishedContent, bool> predicate, string? culture = null)
public static IPublishedContent? FirstChild(this IPublishedContent content, Func<IPublishedContent, bool> 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<T>(this IPublishedContent content, string? culture = null)
public static T? FirstChild<T>(this IPublishedContent content, string? culture = null)
where T : class, IPublishedContent
=> content.FirstChild<T>(VariationContextAccessor, culture);
public static T FirstChild<T>(this IPublishedContent content, Func<T, bool> predicate, string? culture = null)
public static T? FirstChild<T>(this IPublishedContent content, Func<T, bool> predicate, string? culture = null)
where T : class, IPublishedContent
=> content.FirstChild<T>(VariationContextAccessor, predicate, culture);
@@ -390,7 +390,7 @@ namespace Umbraco.Extensions
/// <remarks>
/// <para>Note that in V7 this method also return the content node self.</para>
/// </remarks>
public static IEnumerable<IPublishedContent> Siblings(this IPublishedContent content, string? culture = null)
public static IEnumerable<IPublishedContent>? Siblings(this IPublishedContent content, string? culture = null)
=> content.Siblings(PublishedSnapshot, VariationContextAccessor, culture);
/// <summary>
@@ -403,7 +403,7 @@ namespace Umbraco.Extensions
/// <remarks>
/// <para>Note that in V7 this method also return the content node self.</para>
/// </remarks>
public static IEnumerable<IPublishedContent> SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null)
public static IEnumerable<IPublishedContent>? SiblingsOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null)
=> content.SiblingsOfType(PublishedSnapshot, VariationContextAccessor, contentTypeAlias, culture);
/// <summary>
@@ -416,7 +416,7 @@ namespace Umbraco.Extensions
/// <remarks>
/// <para>Note that in V7 this method also return the content node self.</para>
/// </remarks>
public static IEnumerable<T> Siblings<T>(this IPublishedContent content, string? culture = null)
public static IEnumerable<T>? Siblings<T>(this IPublishedContent content, string? culture = null)
where T : class, IPublishedContent
=> content.Siblings<T>(PublishedSnapshot, VariationContextAccessor, culture);
@@ -426,7 +426,7 @@ namespace Umbraco.Extensions
/// <param name="content">The content.</param>
/// <param name="culture">The specific culture to filter for. If null is used the current culture is used. (Default is null)</param>
/// <returns>The siblings of the content including the node itself.</returns>
public static IEnumerable<IPublishedContent> SiblingsAndSelf(this IPublishedContent content, string? culture = null)
public static IEnumerable<IPublishedContent>? SiblingsAndSelf(this IPublishedContent content, string? culture = null)
=> content.SiblingsAndSelf(PublishedSnapshot, VariationContextAccessor, culture);
/// <summary>
@@ -436,7 +436,7 @@ namespace Umbraco.Extensions
/// <param name="culture">The specific culture to filter for. If null is used the current culture is used. (Default is null)</param>
/// <param name="contentTypeAlias">The content type alias.</param>
/// <returns>The siblings of the content including the node itself, of the given content type.</returns>
public static IEnumerable<IPublishedContent> SiblingsAndSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null)
public static IEnumerable<IPublishedContent>? SiblingsAndSelfOfType(this IPublishedContent content, string contentTypeAlias, string? culture = null)
=> content.SiblingsAndSelfOfType(PublishedSnapshot, VariationContextAccessor, contentTypeAlias, culture);
/// <summary>
@@ -446,7 +446,7 @@ namespace Umbraco.Extensions
/// <param name="content">The content.</param>
/// <param name="culture">The specific culture to filter for. If null is used the current culture is used. (Default is null)</param>
/// <returns>The siblings of the content including the node itself, of the given content type.</returns>
public static IEnumerable<T> SiblingsAndSelf<T>(this IPublishedContent content, string? culture = null)
public static IEnumerable<T>? SiblingsAndSelf<T>(this IPublishedContent content, string? culture = null)
where T : class, IPublishedContent
=> content.SiblingsAndSelf<T>(PublishedSnapshot, VariationContextAccessor, culture);
@@ -496,7 +496,7 @@ namespace Umbraco.Extensions
/// </remarks>
public static string MediaUrl(
this IPublishedContent content,
string culture = null,
string? culture = null,
UrlMode mode = UrlMode.Default,
string propertyAlias = Constants.Conventions.Media.File)
=> content.MediaUrl(PublishedUrlProvider, culture, mode, propertyAlias);
@@ -505,14 +505,14 @@ namespace Umbraco.Extensions
/// Gets the name of the content item creator.
/// </summary>
/// <param name="content">The content item.</param>
public static string CreatorName(this IPublishedContent content) =>
public static string? CreatorName(this IPublishedContent content) =>
content.CreatorName(UserService);
/// <summary>
/// Gets the name of the content item writer.
/// </summary>
/// <param name="content">The content item.</param>
public static string WriterName(this IPublishedContent content) =>
public static string? WriterName(this IPublishedContent content) =>
content.WriterName(UserService);
/// <summary>
@@ -526,23 +526,23 @@ namespace Umbraco.Extensions
/// one document per culture), and domains, withing the context of a current Uri, assign
/// a culture to that document.</para>
/// </remarks>
public static string GetCultureFromDomains(
public static string? GetCultureFromDomains(
this IPublishedContent content,
Uri current = null)
Uri? current = null)
=> content.GetCultureFromDomains(UmbracoContextAccessor, SiteDomainHelper, current);
public static IEnumerable<PublishedSearchResult> SearchDescendants(
this IPublishedContent content,
string term,
string indexName = null)
string? indexName = null)
=> content.SearchDescendants(ExamineManager, UmbracoContextAccessor, term, indexName);
public static IEnumerable<PublishedSearchResult> SearchChildren(
this IPublishedContent content,
string term,
string indexName = null)
string? indexName = null)
=> content.SearchChildren(ExamineManager, UmbracoContextAccessor, term, indexName);

View File

@@ -27,11 +27,11 @@ namespace Umbraco.Extensions
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
/// <para>The alias is case-insensitive.</para>
/// </remarks>
public static object Value(
public static object? Value(
this IPublishedElement content,
string alias,
string culture = null,
string segment = null,
string? culture = null,
string? segment = null,
Fallback fallback = default,
object? defaultValue = default)
=> content.Value(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
@@ -53,13 +53,13 @@ namespace Umbraco.Extensions
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
/// <para>The alias is case-insensitive.</para>
/// </remarks>
public static T Value<T>(
public static T? Value<T>(
this IPublishedElement content,
string alias,
string culture = null,
string segment = null,
string? culture = null,
string? segment = null,
Fallback fallback = default,
T defaultValue = default)
T? defaultValue = default)
=> content.Value<T>(PublishedValueFallback, alias, culture, segment, fallback, defaultValue);
/// <summary>
@@ -75,7 +75,7 @@ namespace Umbraco.Extensions
/// <summary>
/// Gets the value of a property.
/// </summary>
public static TValue ValueFor<TModel, TValue>(this TModel model, Expression<Func<TModel, TValue>> property, string? culture = null, string? segment = null, Fallback fallback = default, TValue defaultValue = default)
public static TValue? ValueFor<TModel, TValue>(this TModel model, Expression<Func<TModel, TValue>> property, string? culture = null, string? segment = null, Fallback fallback = default, TValue? defaultValue = default)
where TModel : IPublishedElement =>
model.ValueFor(PublishedValueFallback, property, culture, segment, fallback);
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Extensions
/// <summary>
/// Try to get the basic auth username and password from the http context.
/// </summary>
public static bool TryGetBasicAuthCredentials(this HttpContext httpContext, out string username, out string password)
public static bool TryGetBasicAuthCredentials(this HttpContext httpContext, out string? username, out string? password)
{
username = null;
password = null;
@@ -70,9 +70,12 @@ namespace Umbraco.Extensions
return value ?? request.Query[key];
}
public static void SetPrincipalForRequest(this HttpContext context, ClaimsPrincipal principal)
public static void SetPrincipalForRequest(this HttpContext context, ClaimsPrincipal? principal)
{
context.User = principal;
if (principal is not null)
{
context.User = principal;
}
}
@@ -94,7 +97,7 @@ namespace Umbraco.Extensions
/// <returns>
/// Returns the current back office identity if an admin is authenticated otherwise null
/// </returns>
public static ClaimsIdentity GetCurrentIdentity(this HttpContext http)
public static ClaimsIdentity? GetCurrentIdentity(this HttpContext http)
{
if (http == null) throw new ArgumentNullException(nameof(http));
if (http.User == null) return null; //there's no user at all so no identity

View File

@@ -29,8 +29,8 @@ namespace Umbraco.Extensions
public static bool IsBackOfficeRequest(this HttpRequest request)
{
PathString absPath = request.Path;
UmbracoRequestPaths umbReqPaths = request.HttpContext.RequestServices.GetService<UmbracoRequestPaths>();
return umbReqPaths.IsBackOfficeRequest(absPath);
UmbracoRequestPaths? umbReqPaths = request.HttpContext.RequestServices.GetService<UmbracoRequestPaths>();
return umbReqPaths?.IsBackOfficeRequest(absPath) ?? false;
}
/// <summary>
@@ -39,11 +39,11 @@ namespace Umbraco.Extensions
public static bool IsClientSideRequest(this HttpRequest request)
{
PathString absPath = request.Path;
UmbracoRequestPaths umbReqPaths = request.HttpContext.RequestServices.GetService<UmbracoRequestPaths>();
return umbReqPaths.IsClientSideRequest(absPath);
UmbracoRequestPaths? umbReqPaths = request.HttpContext.RequestServices.GetService<UmbracoRequestPaths>();
return umbReqPaths?.IsClientSideRequest(absPath) ?? false;
}
public static string ClientCulture(this HttpRequest request)
public static string? ClientCulture(this HttpRequest request)
=> request.Headers.TryGetValue("X-UMB-CULTURE", out var values) ? values[0] : null;
/// <summary>
@@ -56,10 +56,10 @@ namespace Umbraco.Extensions
public static bool IsLocal(this HttpRequest request)
{
var connection = request.HttpContext.Connection;
if (connection.RemoteIpAddress.IsSet())
if (connection.RemoteIpAddress?.IsSet() ?? false)
{
// We have a remote address set up
return connection.LocalIpAddress.IsSet()
return connection.LocalIpAddress?.IsSet() ?? false
// Is local is same as remote, then we are local
? connection.RemoteIpAddress.Equals(connection.LocalIpAddress)
// else we are remote if the remote IP address is not a loopback address
@@ -75,7 +75,7 @@ namespace Umbraco.Extensions
return address != null && address.ToString() != NullIpAddress;
}
public static string GetRawBodyString(this HttpRequest request, Encoding encoding = null)
public static string GetRawBodyString(this HttpRequest request, Encoding? encoding = null)
{
if (request.Body.CanSeek)
{
@@ -94,7 +94,7 @@ namespace Umbraco.Extensions
}
}
public static async Task<string> GetRawBodyStringAsync(this HttpRequest request, Encoding encoding = null)
public static async Task<string> GetRawBodyStringAsync(this HttpRequest request, Encoding? encoding = null)
{
if (!request.Body.CanSeek)
{
@@ -143,7 +143,7 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="request">The current request</param>
/// <returns>The extracted `ufprt` token.</returns>
public static string GetUfprt(this HttpRequest request)
public static string? GetUfprt(this HttpRequest request)
{
if (request.HasFormContentType && request.Form.TryGetValue("ufprt", out StringValues formVal) && formVal != StringValues.Empty)
{

View File

@@ -20,6 +20,7 @@ namespace Umbraco.Extensions
/// <returns>The current <see cref="IdentityBuilder"/> instance.</returns>
public static IdentityBuilder AddMemberManager<TInterface, TUserManager>(this IdentityBuilder identityBuilder)
where TUserManager : UserManager<MemberIdentityUser>, TInterface
where TInterface : notnull
{
identityBuilder.AddUserManager<TUserManager>();
// use a UniqueServiceDescriptor so we can check if it's already been added
@@ -31,6 +32,7 @@ namespace Umbraco.Extensions
public static IdentityBuilder AddRoleManager<TInterface, TRoleManager>(this IdentityBuilder identityBuilder)
where TRoleManager : RoleManager<UmbracoIdentityRole>, TInterface
where TInterface : notnull
{
identityBuilder.AddRoleManager<TRoleManager>();
identityBuilder.Services.AddScoped(typeof(TInterface), typeof(TRoleManager));

View File

@@ -24,7 +24,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
string cropAlias,
IImageUrlGenerator imageUrlGenerator,
@@ -44,7 +44,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this MediaWithCrops mediaWithCrops,
string cropAlias,
IImageUrlGenerator imageUrlGenerator,
@@ -65,7 +65,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The image crop URL.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
ImageCropperValue imageCropperValue,
string cropAlias,
@@ -87,7 +87,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
string propertyAlias,
string cropAlias,
@@ -109,7 +109,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(this MediaWithCrops mediaWithCrops,
public static string? GetCropUrl(this MediaWithCrops mediaWithCrops,
IPublishedValueFallback publishedValueFallback,
IPublishedUrlProvider publishedUrlProvider,
string propertyAlias,
@@ -142,7 +142,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this IPublishedContent mediaItem,
IImageUrlGenerator imageUrlGenerator,
IPublishedValueFallback publishedValueFallback,
@@ -150,14 +150,14 @@ namespace Umbraco.Extensions
int? width = null,
int? height = null,
string propertyAlias = Cms.Core.Constants.Conventions.Media.File,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
bool cacheBuster = true,
string furtherOptions = null,
string? furtherOptions = null,
UrlMode urlMode = UrlMode.Default) => mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, null, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, urlMode);
/// <summary>
@@ -185,7 +185,7 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this MediaWithCrops mediaWithCrops,
IImageUrlGenerator imageUrlGenerator,
IPublishedValueFallback publishedValueFallback,
@@ -193,14 +193,14 @@ namespace Umbraco.Extensions
int? width = null,
int? height = null,
string propertyAlias = Constants.Conventions.Media.File,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
bool cacheBuster = true,
string furtherOptions = null,
string? furtherOptions = null,
UrlMode urlMode = UrlMode.Default)
{
if (mediaWithCrops == null)
@@ -211,24 +211,24 @@ namespace Umbraco.Extensions
return mediaWithCrops.Content.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, mediaWithCrops.LocalCrops, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, urlMode);
}
private static string GetCropUrl(
private static string? GetCropUrl(
this IPublishedContent mediaItem,
IImageUrlGenerator imageUrlGenerator,
IPublishedValueFallback publishedValueFallback,
IPublishedUrlProvider publishedUrlProvider,
ImageCropperValue localCrops,
ImageCropperValue? localCrops,
bool localCropsOnly,
int? width = null,
int? height = null,
string propertyAlias = Constants.Conventions.Media.File,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
bool cacheBuster = true,
string furtherOptions = null,
string? furtherOptions = null,
UrlMode urlMode = UrlMode.Default)
{
if (mediaItem == null)
@@ -302,27 +302,27 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this string imageUrl,
IImageUrlGenerator imageUrlGenerator,
int? width = null,
int? height = null,
string imageCropperValue = null,
string cropAlias = null,
string? imageCropperValue = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
string cacheBusterValue = null,
string furtherOptions = null)
string? cacheBusterValue = null,
string? furtherOptions = null)
{
if (string.IsNullOrWhiteSpace(imageUrl))
{
return null;
}
ImageCropperValue cropDataSet = null;
ImageCropperValue? cropDataSet = null;
if (string.IsNullOrEmpty(imageCropperValue) == false && imageCropperValue.DetectIsJson() && (imageCropMode == ImageCropMode.Crop || imageCropMode == null))
{
cropDataSet = imageCropperValue.DeserializeImageCropperValue();
@@ -355,20 +355,20 @@ namespace Umbraco.Extensions
/// <returns>
/// The URL of the cropped image.
/// </returns>
public static string GetCropUrl(
public static string? GetCropUrl(
this string imageUrl,
IImageUrlGenerator imageUrlGenerator,
ImageCropperValue cropDataSet,
ImageCropperValue? cropDataSet,
int? width = null,
int? height = null,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
string cacheBusterValue = null,
string furtherOptions = null)
string? cacheBusterValue = null,
string? furtherOptions = null)
{
if (string.IsNullOrWhiteSpace(imageUrl))
{
@@ -378,7 +378,7 @@ namespace Umbraco.Extensions
ImageUrlGenerationOptions options;
if (cropDataSet != null && (imageCropMode == ImageCropMode.Crop || imageCropMode == null))
{
ImageCropperValue.ImageCropperCrop crop = cropDataSet.GetCrop(cropAlias);
ImageCropperValue.ImageCropperCrop? crop = cropDataSet.GetCrop(cropAlias);
// If a crop was specified, but not found, return null
if (crop == null && !string.IsNullOrWhiteSpace(cropAlias))

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Extensions
internal static ImageCropperValue DeserializeImageCropperValue(this string json)
{
ImageCropperValue imageCrops = null;
ImageCropperValue? imageCrops = null;
if (json.DetectIsJson())
{

View File

@@ -18,10 +18,10 @@ namespace Umbraco.Extensions
/// <summary>
/// Return the back office url if the back office is installed
/// </summary>
public static string GetBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment)
public static string? GetBackOfficeUrl(this LinkGenerator linkGenerator, IHostingEnvironment hostingEnvironment)
{
Type backOfficeControllerType;
Type? backOfficeControllerType;
try
{
backOfficeControllerType = Assembly.Load("Umbraco.Web.BackOffice")?.GetType("Umbraco.Web.BackOffice.Controllers.BackOfficeController");
@@ -42,19 +42,19 @@ namespace Umbraco.Extensions
/// Return the Url for a Web Api service
/// </summary>
/// <typeparam name="T">The <see cref="UmbracoApiControllerBase"/></typeparam>
public static string GetUmbracoApiService<T>(this LinkGenerator linkGenerator, string actionName, object id = null)
public static string? GetUmbracoApiService<T>(this LinkGenerator linkGenerator, string actionName, object? id = null)
where T : UmbracoApiControllerBase => linkGenerator.GetUmbracoControllerUrl(
actionName,
typeof(T),
new Dictionary<string, object>()
new Dictionary<string, object?>()
{
["id"] = id
});
public static string GetUmbracoApiService<T>(this LinkGenerator linkGenerator, string actionName, IDictionary<string, object> values)
public static string? GetUmbracoApiService<T>(this LinkGenerator linkGenerator, string actionName, IDictionary<string, object?>? values)
where T : UmbracoApiControllerBase => linkGenerator.GetUmbracoControllerUrl(actionName, typeof(T), values);
public static string GetUmbracoApiServiceBaseUrl<T>(this LinkGenerator linkGenerator, Expression<Func<T, object>> methodSelector)
public static string? GetUmbracoApiServiceBaseUrl<T>(this LinkGenerator linkGenerator, Expression<Func<T, object>> methodSelector)
where T : UmbracoApiControllerBase
{
var method = ExpressionHelper.GetMethodInfo(methodSelector);
@@ -62,13 +62,13 @@ namespace Umbraco.Extensions
{
throw new MissingMethodException("Could not find the method " + methodSelector + " on type " + typeof(T) + " or the result ");
}
return linkGenerator.GetUmbracoApiService<T>(method.Name).TrimEnd(method.Name);
return linkGenerator.GetUmbracoApiService<T>(method.Name)?.TrimEnd(method.Name);
}
/// <summary>
/// Return the Url for an Umbraco controller
/// </summary>
public static string GetUmbracoControllerUrl(this LinkGenerator linkGenerator, string actionName, string controllerName, string area, IDictionary<string, object> dict = null)
public static string? GetUmbracoControllerUrl(this LinkGenerator linkGenerator, string actionName, string controllerName, string? area, IDictionary<string, object?>? dict = null)
{
if (actionName == null)
{
@@ -92,16 +92,16 @@ namespace Umbraco.Extensions
if (dict is null)
{
dict = new Dictionary<string, object>();
dict = new Dictionary<string, object?>();
}
if (!area.IsNullOrWhiteSpace())
{
dict["area"] = area;
dict["area"] = area!;
}
IDictionary<string, object> values = dict.Aggregate(
new ExpandoObject() as IDictionary<string, object>,
IDictionary<string, object?> values = dict.Aggregate(
new ExpandoObject() as IDictionary<string, object?>,
(a, p) =>
{
a.Add(p.Key, p.Value);
@@ -114,7 +114,7 @@ namespace Umbraco.Extensions
/// <summary>
/// Return the Url for an Umbraco controller
/// </summary>
public static string GetUmbracoControllerUrl(this LinkGenerator linkGenerator, string actionName, Type controllerType, IDictionary<string, object> values = null)
public static string? GetUmbracoControllerUrl(this LinkGenerator linkGenerator, string actionName, Type controllerType, IDictionary<string, object?>? values = null)
{
if (actionName == null)
{
@@ -148,7 +148,7 @@ namespace Umbraco.Extensions
return linkGenerator.GetUmbracoControllerUrl(actionName, ControllerExtensions.GetControllerName(controllerType), area, values);
}
public static string GetUmbracoApiService<T>(this LinkGenerator linkGenerator, Expression<Func<T, object>> methodSelector)
public static string? GetUmbracoApiService<T>(this LinkGenerator linkGenerator, Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController
{
var method = ExpressionHelper.GetMethodInfo(methodSelector);
@@ -159,7 +159,7 @@ namespace Umbraco.Extensions
$"Could not find the method {methodSelector} on type {typeof(T)} or the result ");
}
if (methodParams.Any() == false)
if (methodParams?.Any() == false)
{
return linkGenerator.GetUmbracoApiService<T>(method.Name);
}

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Extensions
/// <param name="prefix"></param>
/// <returns></returns>
public static bool IsValid(this ModelStateDictionary state, string prefix) =>
state.Where(v => v.Key.StartsWith(prefix + ".")).All(v => !v.Value.Errors.Any());
state.Where(v => v.Key.StartsWith(prefix + ".")).All(v => !v.Value?.Errors.Any() ?? false);
public static IDictionary<string, object> ToErrorDictionary(this ModelStateDictionary modelState)
{
@@ -36,7 +36,7 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static JsonResult ToJsonErrors(this ModelStateDictionary state) =>
public static JsonResult? ToJsonErrors(this ModelStateDictionary state) =>
new JsonResult(new
{
success = state.IsValid.ToString().ToLower(),
@@ -48,7 +48,7 @@ namespace Umbraco.Extensions
name = e.Key,
errors = e.Value.Errors.Select(x => x.ErrorMessage)
.Concat(
e.Value.Errors.Where(x => x.Exception != null).Select(x => x.Exception.Message))
e.Value.Errors.Where(x => x.Exception != null).Select(x => x.Exception!.Message))
}
});
}

View File

@@ -21,14 +21,14 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="content">The content item.</param>
/// <param name="userService"></param>
public static string CreatorName(this IPublishedContent content, IUserService userService) => userService.GetProfileById(content.CreatorId)?.Name;
public static string? CreatorName(this IPublishedContent content, IUserService userService) => userService.GetProfileById(content.CreatorId)?.Name;
/// <summary>
/// Gets the name of the content item writer.
/// </summary>
/// <param name="content">The content item.</param>
/// <param name="userService"></param>
public static string WriterName(this IPublishedContent content, IUserService userService) => userService.GetProfileById(content.WriterId)?.Name;
public static string? WriterName(this IPublishedContent content, IUserService userService) => userService.GetProfileById(content.WriterId)?.Name;
#endregion
@@ -47,7 +47,7 @@ namespace Umbraco.Extensions
/// one document per culture), and domains, withing the context of a current Uri, assign
/// a culture to that document.</para>
/// </remarks>
public static string GetCultureFromDomains(this IPublishedContent content, IUmbracoContextAccessor umbracoContextAccessor, ISiteDomainMapper siteDomainHelper, Uri current = null)
public static string? GetCultureFromDomains(this IPublishedContent content, IUmbracoContextAccessor umbracoContextAccessor, ISiteDomainMapper siteDomainHelper, Uri? current = null)
{
var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext();
return DomainUtilities.GetCultureFromDomains(content.Id, content.Path, current, umbracoContext, siteDomainHelper);
@@ -57,7 +57,7 @@ namespace Umbraco.Extensions
#region Search
public static IEnumerable<PublishedSearchResult> SearchDescendants(this IPublishedContent content, IExamineManager examineManager, IUmbracoContextAccessor umbracoContextAccessor, string term, string indexName = null)
public static IEnumerable<PublishedSearchResult> SearchDescendants(this IPublishedContent content, IExamineManager examineManager, IUmbracoContextAccessor umbracoContextAccessor, string term, string ?indexName = null)
{
indexName = string.IsNullOrEmpty(indexName) ? Constants.UmbracoIndexes.ExternalIndexName : indexName;
if (!examineManager.TryGetIndex(indexName, out var index))
@@ -76,7 +76,7 @@ namespace Umbraco.Extensions
return query.Execute().ToPublishedSearchResults(umbracoContext.Content);
}
public static IEnumerable<PublishedSearchResult> SearchChildren(this IPublishedContent content, IExamineManager examineManager, IUmbracoContextAccessor umbracoContextAccessor, string term, string indexName = null)
public static IEnumerable<PublishedSearchResult> SearchChildren(this IPublishedContent content, IExamineManager examineManager, IUmbracoContextAccessor umbracoContextAccessor, string term, string? indexName = null)
{
indexName = string.IsNullOrEmpty(indexName) ? Constants.UmbracoIndexes.ExternalIndexName : indexName;
if (!examineManager.TryGetIndex(indexName, out var index))

View File

@@ -11,13 +11,13 @@ namespace Umbraco.Extensions
/// <summary>
/// Renders a section with default content if the section isn't defined
/// </summary>
public static HtmlString RenderSection(this RazorPage webPage, string name, HtmlString defaultContents)
public static HtmlString? RenderSection(this RazorPage webPage, string name, HtmlString defaultContents)
=> webPage.IsSectionDefined(name) ? webPage.RenderSection(name) : defaultContents;
/// <summary>
/// Renders a section with default content if the section isn't defined
/// </summary>
public static HtmlString RenderSection(this RazorPage webPage, string name, string defaultContents)
public static HtmlString? RenderSection(this RazorPage webPage, string name, string defaultContents)
=> webPage.IsSectionDefined(name) ? webPage.RenderSection(name) : new HtmlString(defaultContents);
}

View File

@@ -81,8 +81,8 @@ namespace Umbraco.Extensions
/// </remarks>
public static TypeLoader AddTypeLoader(
this IServiceCollection services,
Assembly entryAssembly,
IHostingEnvironment hostingEnvironment,
Assembly? entryAssembly,
IHostingEnvironment? hostingEnvironment,
ILoggerFactory loggerFactory,
AppCaches appCaches,
IConfiguration configuration,
@@ -115,7 +115,7 @@ namespace Umbraco.Extensions
typeFinder,
runtimeHash,
appCaches.RuntimeCache,
new DirectoryInfo(hostingEnvironment.LocalTempPath),
new DirectoryInfo(hostingEnvironment?.LocalTempPath ?? string.Empty),
loggerFactory.CreateLogger<TypeLoader>(),
profiler
);

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string GetBackOfficeUrl(this IUrlHelper url)
public static string? GetBackOfficeUrl(this IUrlHelper url)
{
var backOfficeControllerType = Type.GetType("Umbraco.Web.BackOffice.Controllers");
if (backOfficeControllerType == null) return "/"; // this would indicate that the installer is installed without the back office
@@ -43,13 +43,13 @@ namespace Umbraco.Extensions
/// <param name="actionName"></param>
/// <param name="id"></param>
/// <returns></returns>
public static string GetUmbracoApiService<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName, object id = null)
public static string? GetUmbracoApiService<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName, object? id = null)
where T : UmbracoApiController
{
return url.GetUmbracoApiService(umbracoApiControllerTypeCollection, actionName, typeof(T), id);
}
public static string GetUmbracoApiService<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, Expression<Func<T, object>> methodSelector)
public static string? GetUmbracoApiService<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController
{
var method = ExpressionHelper.GetMethodInfo(methodSelector);
@@ -59,11 +59,11 @@ namespace Umbraco.Extensions
throw new MissingMethodException("Could not find the method " + methodSelector + " on type " + typeof(T) + " or the result ");
}
if (methodParams.Any() == false)
if (methodParams?.Any() == false)
{
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, method.Name);
}
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, method.Name, methodParams.Values.First());
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, method.Name, methodParams?.Values.First());
}
/// <summary>
@@ -75,7 +75,7 @@ namespace Umbraco.Extensions
/// <param name="apiControllerType"></param>
/// <param name="id"></param>
/// <returns></returns>
public static string GetUmbracoApiService(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName, Type apiControllerType, object id = null)
public static string? GetUmbracoApiService(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName, Type apiControllerType, object? id = null)
{
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(actionName));
@@ -92,7 +92,7 @@ namespace Umbraco.Extensions
//set the area to the plugin area
area = metaData.AreaName;
}
return url.GetUmbracoApiService(actionName, ControllerExtensions.GetControllerName(apiControllerType), area, id);
return url.GetUmbracoApiService(actionName, ControllerExtensions.GetControllerName(apiControllerType), area!, id);
}
/// <summary>
@@ -103,7 +103,7 @@ namespace Umbraco.Extensions
/// <param name="controllerName"></param>
/// <param name="id"></param>
/// <returns></returns>
public static string GetUmbracoApiService(this IUrlHelper url, string actionName, string controllerName, object id = null)
public static string? GetUmbracoApiService(this IUrlHelper url, string actionName, string controllerName, object? id = null)
{
return url.GetUmbracoApiService(actionName, controllerName, "", id);
}
@@ -117,7 +117,7 @@ namespace Umbraco.Extensions
/// <param name="area"></param>
/// <param name="id"></param>
/// <returns></returns>
public static string GetUmbracoApiService(this IUrlHelper url, string actionName, string controllerName, string area, object id = null)
public static string? GetUmbracoApiService(this IUrlHelper url, string actionName, string controllerName, string area, object? id = null)
{
if (actionName == null) throw new ArgumentNullException(nameof(actionName));
if (string.IsNullOrWhiteSpace(actionName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(actionName));
@@ -156,13 +156,13 @@ namespace Umbraco.Extensions
/// <param name="umbracoApiControllerTypeCollection"></param>
/// <param name="actionName"></param>
/// <returns></returns>
public static string GetUmbracoApiServiceBaseUrl<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName)
public static string? GetUmbracoApiServiceBaseUrl<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, string actionName)
where T : UmbracoApiController
{
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, actionName).TrimEnd(actionName);
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, actionName)?.TrimEnd(actionName);
}
public static string GetUmbracoApiServiceBaseUrl<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, Expression<Func<T, object>> methodSelector)
public static string? GetUmbracoApiServiceBaseUrl<T>(this IUrlHelper url, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, Expression<Func<T, object>> methodSelector)
where T : UmbracoApiController
{
var method = ExpressionHelper.GetMethodInfo(methodSelector);
@@ -170,7 +170,7 @@ namespace Umbraco.Extensions
{
throw new MissingMethodException("Could not find the method " + methodSelector + " on type " + typeof(T) + " or the result ");
}
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, method.Name).TrimEnd(method.Name);
return url.GetUmbracoApiService<T>(umbracoApiControllerTypeCollection, method.Name)?.TrimEnd(method.Name);
}
/// <summary>
@@ -219,7 +219,7 @@ namespace Umbraco.Extensions
return CreateHtmlString(url, htmlEncode);
}
private static IHtmlContent CreateHtmlString(string url, bool htmlEncode) => htmlEncode ? new HtmlString(HttpUtility.HtmlEncode(url)) : new HtmlString(url);
private static IHtmlContent CreateHtmlString(string? url, bool htmlEncode) => htmlEncode ? new HtmlString(HttpUtility.HtmlEncode(url)) : new HtmlString(url);
public static IHtmlContent GetCropUrl(this IUrlHelper urlHelper, IPublishedContent mediaItem, string propertyAlias, string cropAlias, bool htmlEncode = true, UrlMode urlMode = UrlMode.Default)
{
@@ -237,14 +237,14 @@ namespace Umbraco.Extensions
int? width = null,
int? height = null,
string propertyAlias = Constants.Conventions.Media.File,
string cropAlias = null,
string? cropAlias = null,
int? quality = null,
ImageCropMode? imageCropMode = null,
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = false,
bool cacheBuster = true,
string furtherOptions = null,
string? furtherOptions = null,
bool htmlEncode = true,
UrlMode urlMode = UrlMode.Default)
{
@@ -269,14 +269,14 @@ namespace Umbraco.Extensions
ImageCropAnchor? imageCropAnchor = null,
bool preferFocalPoint = false,
bool useCropDimensions = true,
string cacheBusterValue = null,
string furtherOptions = null,
string? cacheBusterValue = null,
string? furtherOptions = null,
bool htmlEncode = true)
{
if (imageCropperValue == null) return HtmlString.Empty;
var imageUrl = imageCropperValue.Src;
var url = imageUrl.GetCropUrl(imageCropperValue, width, height, cropAlias, quality, imageCropMode,
var url = imageUrl?.GetCropUrl(imageCropperValue, width, height, cropAlias, quality, imageCropMode,
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions);
return CreateHtmlString(url, htmlEncode);
@@ -302,7 +302,7 @@ namespace Umbraco.Extensions
/// <param name="controllerName"></param>
/// <param name="additionalRouteVals"></param>
/// <returns></returns>
public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider,string action, string controllerName, object additionalRouteVals)
public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider,string action, string controllerName, object? additionalRouteVals)
{
return url.SurfaceAction(umbracoContext, dataProtectionProvider, action, controllerName, "", additionalRouteVals);
}
@@ -316,7 +316,7 @@ namespace Umbraco.Extensions
/// <param name="area"></param>
/// <param name="additionalRouteVals"></param>
/// <returns></returns>
public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider, string action, string controllerName, string area, object additionalRouteVals)
public static string SurfaceAction(this IUrlHelper url, IUmbracoContext umbracoContext, IDataProtectionProvider dataProtectionProvider, string action, string controllerName, string area, object? additionalRouteVals)
{
if (action == null) throw new ArgumentNullException(nameof(action));
if (string.IsNullOrEmpty(action)) throw new ArgumentException("Value can't be empty.", nameof(action));

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
@@ -59,7 +60,7 @@ namespace Umbraco.Extensions
try
{
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(System.Net.WebUtility.UrlDecode(cookieVal)));
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(System.Net.WebUtility.UrlDecode(cookieVal)!));
// deserialize to T and store in viewdata
viewData[cookieName] = serializer.Deserialize<T>(decoded);
return true;
@@ -70,9 +71,9 @@ namespace Umbraco.Extensions
}
}
public static string GetUmbracoPath(this ViewDataDictionary viewData)
public static string? GetUmbracoPath(this ViewDataDictionary viewData)
{
return (string)viewData[TokenUmbracoPath];
return (string?)viewData[TokenUmbracoPath];
}
public static void SetUmbracoPath(this ViewDataDictionary viewData, string value)
@@ -80,9 +81,9 @@ namespace Umbraco.Extensions
viewData[TokenUmbracoPath] = value;
}
public static string GetInstallApiBaseUrl(this ViewDataDictionary viewData)
public static string? GetInstallApiBaseUrl(this ViewDataDictionary viewData)
{
return (string)viewData[TokenInstallApiBaseUrl];
return (string?)viewData[TokenInstallApiBaseUrl];
}
public static void SetInstallApiBaseUrl(this ViewDataDictionary viewData, string value)
@@ -90,9 +91,9 @@ namespace Umbraco.Extensions
viewData[TokenInstallApiBaseUrl] = value;
}
public static string GetUmbracoBaseFolder(this ViewDataDictionary viewData)
public static string? GetUmbracoBaseFolder(this ViewDataDictionary viewData)
{
return (string)viewData[TokenUmbracoBaseFolder];
return (string?)viewData[TokenUmbracoBaseFolder];
}
public static void SetUmbracoBaseFolder(this ViewDataDictionary viewData, string value)
@@ -104,9 +105,9 @@ namespace Umbraco.Extensions
viewData[TokenUmbracoVersion] = version;
}
public static SemVersion GetUmbracoVersion(this ViewDataDictionary viewData)
public static SemVersion? GetUmbracoVersion(this ViewDataDictionary viewData)
{
return (SemVersion) viewData[TokenUmbracoVersion];
return (SemVersion?) viewData[TokenUmbracoVersion];
}
/// <summary>
@@ -114,9 +115,9 @@ namespace Umbraco.Extensions
/// </summary>
/// <param name="viewData"></param>
/// <returns></returns>
public static BackOfficeExternalLoginProviderErrors GetExternalSignInProviderErrors(this ViewDataDictionary viewData)
public static BackOfficeExternalLoginProviderErrors? GetExternalSignInProviderErrors(this ViewDataDictionary viewData)
{
return (BackOfficeExternalLoginProviderErrors)viewData[TokenExternalSignInError];
return (BackOfficeExternalLoginProviderErrors?)viewData[TokenExternalSignInError];
}
/// <summary>
@@ -129,9 +130,9 @@ namespace Umbraco.Extensions
viewData[TokenExternalSignInError] = errors;
}
public static string GetPasswordResetCode(this ViewDataDictionary viewData)
public static string? GetPasswordResetCode(this ViewDataDictionary viewData)
{
return (string)viewData[TokenPasswordResetCode];
return (string?)viewData[TokenPasswordResetCode];
}
public static void SetPasswordResetCode(this ViewDataDictionary viewData, string value)
@@ -144,7 +145,7 @@ namespace Umbraco.Extensions
viewData[TokenTwoFactorRequired] = providerNames;
}
public static bool TryGetTwoFactorProviderNames(this ViewDataDictionary viewData, out IEnumerable<string> providerNames)
public static bool TryGetTwoFactorProviderNames(this ViewDataDictionary viewData, [MaybeNullWhen(false)] out IEnumerable<string> providerNames)
{
providerNames = viewData[TokenTwoFactorRequired] as IEnumerable<string>;
return providerNames is not null;