From 6000efa109de55bac2055fd3bba39de3a7a248dd Mon Sep 17 00:00:00 2001 From: Jamie Pollock Date: Mon, 22 Jan 2024 11:00:26 -0500 Subject: [PATCH] feat (Links): adds further null checks and docs Updates all methods to accept a nullable source. This is handled within the methods now. Updates all the docs to note this will be an empty collection or default if the source parameter is null. --- .../Links/MapperContextLinkExtensions.cs | 30 +++++++++++++++---- .../Links/MapperContextLinksExtensions.cs | 19 +++++++++--- .../Links/UmbracoMapperLinkExtensions.cs | 30 +++++++++++++++---- .../Links/UmbracoMapperLinksExtensions.cs | 19 +++++++++--- 4 files changed, 78 insertions(+), 20 deletions(-) diff --git a/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinkExtensions.cs b/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinkExtensions.cs index 710ed29..b4d0b47 100644 --- a/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinkExtensions.cs +++ b/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinkExtensions.cs @@ -16,7 +16,10 @@ public static class MapperContextLinkExtensions /// The type of the link. /// The current mapper context. /// The block to map. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static TLink? MapLink(this MapperContext mapperContext, IBlockReference? block) where TLink : class, ILink { if (block is null) @@ -32,7 +35,10 @@ public static class MapperContextLinkExtensions /// /// The current mapper context. /// The block to map. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static ILink? MapLink(this MapperContext mapperContext, IBlockReference? block) { return mapperContext.MapLink(block); @@ -44,7 +50,10 @@ public static class MapperContextLinkExtensions /// The type of the link. /// The current mapper context. /// The element to map. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static TLink? MapLink(this MapperContext mapperContext, IPublishedElement? element) where TLink : class, ILink { if (element is null) @@ -60,7 +69,10 @@ public static class MapperContextLinkExtensions /// /// The current mapper context. /// The element to map. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static ILink? MapLink(this MapperContext mapperContext, IPublishedElement? element) { return mapperContext.MapLink(element); @@ -72,7 +84,10 @@ public static class MapperContextLinkExtensions /// The type of the link. /// The current mapper context. /// The list to map. - /// A if successful. + /// + /// A if successful. + /// This method will return if or its first item are . + /// public static TLink? MapLink(this MapperContext mapperContext, BlockListModel? list) where TLink : class, ILink { if (list is null) @@ -88,7 +103,10 @@ public static class MapperContextLinkExtensions /// /// The current mapper context. /// The list to map. - /// A if successful. + /// + /// A if successful. + /// This method will return if or its first item are . + /// public static ILink? MapLink(this MapperContext mapperContext, BlockListModel? list) { return mapperContext.MapLink(list); diff --git a/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinksExtensions.cs b/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinksExtensions.cs index c120434..a4d7b77 100644 --- a/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinksExtensions.cs +++ b/src/Rhythm.Drop.Umbraco.Mapping/Links/MapperContextLinksExtensions.cs @@ -15,9 +15,17 @@ public static class MapperContextLinksExtensions /// The type of the link. /// The current mapper context. /// The list to map. - /// An array of . - public static TLink[] MapLinks(this MapperContext mapperContext, BlockListModel list) where TLink : class, ILink + /// + /// An array of . + /// This method will return an empty collection if is . + /// + public static TLink[] MapLinks(this MapperContext mapperContext, BlockListModel? list) where TLink : class, ILink { + if (list is null) + { + return []; + } + var links = new List(); foreach (var block in list) { @@ -38,8 +46,11 @@ public static TLink[] MapLinks(this MapperContext mapperContext, BlockLis /// /// The current mapper context. /// The list to map. - /// An array of . - public static ILink[] MapLinks(this MapperContext mapperContext, BlockListModel list) + /// + /// An array of . + /// This method will return an empty collection if is . + /// + public static ILink[] MapLinks(this MapperContext mapperContext, BlockListModel? list) { return mapperContext.MapLinks(list); } diff --git a/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinkExtensions.cs b/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinkExtensions.cs index 71dcb49..597831e 100644 --- a/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinkExtensions.cs +++ b/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinkExtensions.cs @@ -19,7 +19,10 @@ public static class UmbracoMapperLinkExtensions /// The current umbraco mapper. /// The block to map. /// The optional configure mapper context action. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static TLink? MapLink(this IUmbracoMapper mapper, IBlockReference? block, Action? configureContext = default) where TLink : class, ILink { if (block is null) @@ -36,7 +39,10 @@ public static class UmbracoMapperLinkExtensions /// The current umbraco mapper. /// The block to map. /// The optional configure mapper context action. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static ILink? MapLink(this IUmbracoMapper mapper, IBlockReference? block, Action? configureContext = default) { return mapper.MapLink(block, configureContext); @@ -49,7 +55,10 @@ public static class UmbracoMapperLinkExtensions /// The current umbraco mapper. /// The element to map. /// The optional configure mapper context action. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static TLink? MapLink(this IUmbracoMapper mapper, IPublishedElement? element, Action? configureContext = default) where TLink : class, ILink { if (element is null) @@ -66,7 +75,10 @@ public static class UmbracoMapperLinkExtensions /// The current umbraco mapper. /// The element to map. /// The optional configure mapper context action. - /// A if successful. + /// + /// A if successful. + /// This method will return if is . + /// public static ILink? MapLink(this IUmbracoMapper mapper, IPublishedElement? element, Action? configureContext = default) { return mapper.MapLink(element, configureContext); @@ -79,7 +91,10 @@ public static class UmbracoMapperLinkExtensions /// The current umbraco mapper. /// The list to map. /// The optional configure mapper context action. - /// A if successful. + /// + /// A if successful. + /// This method will return if or its first item are . + /// public static TLink? MapLink(this IUmbracoMapper mapper, BlockListModel? list, Action? configureContext = default) where TLink : class, ILink { if (list is null) @@ -96,7 +111,10 @@ public static class UmbracoMapperLinkExtensions /// The current umbraco mapper. /// The list to map. /// The optional configure mapper context action. - /// A if successful. + /// + /// A if successful. + /// This method will return if or its first item are . + /// public static ILink? MapLink(this IUmbracoMapper mapper, BlockListModel? list, Action? configureContext = default) { return mapper.MapLink(list, configureContext); diff --git a/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinksExtensions.cs b/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinksExtensions.cs index 43ea434..cb0de43 100644 --- a/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinksExtensions.cs +++ b/src/Rhythm.Drop.Umbraco.Mapping/Links/UmbracoMapperLinksExtensions.cs @@ -18,9 +18,17 @@ public static class UmbracoMapperLinksExtensions /// The current umbraco mapper. /// The list to map. /// The optional configure mapper context action. - /// An array of . - public static TLink[] MapLinks(this IUmbracoMapper mapper, BlockListModel list, Action? configureContext = default) where TLink : class, ILink + /// + /// An array of . + /// This method will return an empty collection if is . + /// + public static TLink[] MapLinks(this IUmbracoMapper mapper, BlockListModel? list, Action? configureContext = default) where TLink : class, ILink { + if (list is null) + { + return []; + } + var links = new List(); foreach (var block in list) { @@ -42,8 +50,11 @@ public static TLink[] MapLinks(this IUmbracoMapper mapper, BlockListModel /// The current umbraco mapper. /// The list to map. /// The optional configure mapper context action. - /// An array of . - public static ILink[] MapLinks(this IUmbracoMapper mapper, BlockListModel list, Action? configureContext = default) + /// + /// An array of . + /// This method will return an empty collection if is . + /// + public static ILink[] MapLinks(this IUmbracoMapper mapper, BlockListModel? list, Action? configureContext = default) { return mapper.MapLinks(list, configureContext); }