Skip to content

Commit cb6843c

Browse files
author
Warren Buckley
committed
Other Nullable fixes
1 parent 136a4ed commit cb6843c

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

Our.Umbraco.TagHelpers/Composing/PackageManifestComposer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TagHelperManifestFilter : IManifestFilter
1717
{
1818
public void Filter(List<PackageManifest> manifests)
1919
{
20-
var version = typeof(TagHelperManifestFilter).Assembly.GetName().Version.ToString();
20+
var version = typeof(TagHelperManifestFilter).Assembly.GetName()?.Version?.ToString() ?? "Unknown";
2121

2222
manifests.Add(new PackageManifest
2323
{

Our.Umbraco.TagHelpers/DictionaryTagHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public DictionaryTagHelper(ILocalizationService localizationService)
2323
/// The dictionary key to translate
2424
/// </summary>
2525
[HtmlAttributeName("key")]
26-
public string Key { get; set; }
26+
public string? Key { get; set; }
2727

2828
/// <summary>
2929
/// An optional attribute to set a fallback language to use
3030
/// If the current language does not contain a translation for the key
3131
/// </summary>
3232
[HtmlAttributeName("fallback-lang")]
33-
public string FallbackLang { get; set; }
33+
public string? FallbackLang { get; set; }
3434

3535
public override void Process(TagHelperContext context, TagHelperOutput output)
3636
{

Our.Umbraco.TagHelpers/MacroTagHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ public class MacroTagHelper : TagHelper
2121
/// The alias of the Macro to execute
2222
/// </summary>
2323
[HtmlAttributeName("alias")]
24-
public string MacroAlias { get; set; }
24+
public string? MacroAlias { get; set; }
2525

2626
/// <summary>
2727
/// An optional attribute to set the context of the Content that the Macro will use
2828
/// Without it set it will use the current page
2929
/// </summary>
3030
[HtmlAttributeName("content")]
31-
public IPublishedContent ContentNode { get; set; }
31+
public IPublishedContent? ContentNode { get; set; }
3232

3333
/// <summary>
3434
/// An optional list of attributes that will map to Macro Parameters
3535
/// bind:myMacroParam="" bind:startNodeId="" etc...
3636
/// </summary>
3737
[HtmlAttributeName(DictionaryAttributePrefix = "bind:")]
38-
public IDictionary<string, string> MacroParameters { get; set; } = new Dictionary<string, string>();
38+
public IDictionary<string, string>? MacroParameters { get; set; } = new Dictionary<string, string>();
3939

4040
public MacroTagHelper(IUmbracoComponentRenderer umbracoComponentRenderer, IUmbracoContextAccessor umbracoContextAccessor)
4141
{
@@ -59,7 +59,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
5959
// TagHelpers dont seem to like HTMLAttributes as <string, object> dictionary
6060
// Hence us trying to convert it here
6161
IDictionary<string, object> macroParams = new Dictionary<string, object>();
62-
if (MacroParameters.Any())
62+
if (MacroParameters != null && MacroParameters.Any())
6363
{
6464
macroParams = MacroParameters.ToDictionary(p => p.Key, p => (object)p.Value);
6565
}

Our.Umbraco.TagHelpers/MemberTagHelper.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public class MemberTagHelper : TagHelper
2323
/// * = All authenticated users
2424
/// </summary>
2525
[HtmlAttributeName("our-member-exclude")]
26-
public string ExcludeRoles { get; set; }
26+
public string? ExcludeRoles { get; set; }
2727

2828
/// <summary>
2929
/// A comma separated list of Member Groups to include
3030
/// ? = All anonymous users
3131
/// * = All authenticated users
3232
/// </summary>
3333
[HtmlAttributeName("our-member-include")]
34-
public string IncludeRoles { get; set; }
34+
public string? IncludeRoles { get; set; }
3535

3636
public MemberTagHelper(IMemberManager memberManager)
3737
{
@@ -62,29 +62,30 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
6262
}
6363
}
6464

65-
private bool IsUserInRole(string roleString, List<string> currentMemberRoles)
65+
private bool IsUserInRole(string? roleString, List<string> currentMemberRoles)
6666
{
6767
// roles is a CSV of member groups they need to have access to
68-
var roles = roleString.Split(',').Select(x => x.Trim());
69-
foreach (var role in roles)
70-
{
71-
// Role ? == all anonymous users (User not logged in)
72-
if (role == "?" && _memberManager.IsLoggedIn() == false)
68+
var roles = roleString?.Split(',').Select(x => x.Trim());
69+
if (roles != null)
70+
foreach (var role in roles)
7371
{
74-
return true;
75-
}
72+
// Role ? == all anonymous users (User not logged in)
73+
if (role == "?" && _memberManager.IsLoggedIn() == false)
74+
{
75+
return true;
76+
}
7677

77-
// Role * == all authenticated users
78-
if (role == "*" && _memberManager.IsLoggedIn())
79-
{
80-
return true;
81-
}
78+
// Role * == all authenticated users
79+
if (role == "*" && _memberManager.IsLoggedIn())
80+
{
81+
return true;
82+
}
8283

83-
if (currentMemberRoles.InvariantContains(role))
84-
{
85-
return true;
84+
if (currentMemberRoles.InvariantContains(role))
85+
{
86+
return true;
87+
}
8688
}
87-
}
8889

8990
return false;
9091
}

Our.Umbraco.TagHelpers/OurFallbackTagHelper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class OurFallbackTagHelper : TagHelper
1717
/// Would just be Header
1818
/// </summary>
1919
[HtmlAttributeName("property")]
20-
public ModelExpression ModelProperty { get; set; }
20+
public ModelExpression? ModelProperty { get; set; }
2121

2222
[HtmlAttributeName("mode")]
2323
public Fallback Mode { get; set; }
@@ -26,17 +26,17 @@ public class OurFallbackTagHelper : TagHelper
2626
/// If using the fallback mode as Language then you can specify the culture to fallback to
2727
/// </summary>
2828
[HtmlAttributeName("culture")]
29-
public string CultureCode { get; set; } = null;
29+
public string? CultureCode { get; set; } = null;
3030

3131
[HtmlAttributeNotBound]
3232
[ViewContext]
33-
public ViewContext ViewContext { get; set; }
33+
public ViewContext? ViewContext { get; set; }
3434

3535
public override void Process(TagHelperContext context, TagHelperOutput output)
3636
{
3737
// Check to see that the Model Property is NOT a complex type or a collection of things
38-
var isComplexType = ModelProperty.ModelExplorer.Metadata.IsComplexType;
39-
var isEnumerableType = ModelProperty.ModelExplorer.Metadata.IsEnumerableType;
38+
var isComplexType = ModelProperty != null && ModelProperty.ModelExplorer.Metadata.IsComplexType;
39+
var isEnumerableType = ModelProperty != null && ModelProperty.ModelExplorer.Metadata.IsEnumerableType;
4040

4141
// Only can support simpler things such as strings (as if collection)
4242
// We have no way of knowing how they want to iterate and display that HTML etc
@@ -47,7 +47,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
4747
}
4848

4949
// Attempt to fetch/cast the Model as IPublishedContent
50-
var contentNode = ViewContext.ViewData.Model as IPublishedContent;
50+
var contentNode = ViewContext?.ViewData.Model as IPublishedContent;
5151
if(contentNode == null)
5252
{
5353
output.SuppressOutput();
@@ -57,7 +57,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
5757
output.TagName = ""; // Remove the outer <our-fallback>
5858

5959
// Get the Model property with fallback mode
60-
var result = contentNode.Value(ModelProperty.Name, fallback: Mode, culture: CultureCode);
60+
var result = contentNode.Value(ModelProperty?.Name, fallback: Mode, culture: CultureCode);
6161

6262
// If we have a value that can be
6363
if (string.IsNullOrWhiteSpace($"{result}") == false)

Our.Umbraco.TagHelpers/Services/BackofficeUserAccessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public ClaimsIdentity BackofficeUser
3636
return new ClaimsIdentity();
3737

3838
CookieAuthenticationOptions cookieOptions = _cookieOptionsSnapshot.Get(global::Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
39-
string backOfficeCookie = httpContext.Request.Cookies[cookieOptions.Cookie.Name!];
39+
string? backOfficeCookie = httpContext.Request.Cookies[cookieOptions.Cookie.Name!];
4040

4141
if (string.IsNullOrEmpty(backOfficeCookie))
4242
return new ClaimsIdentity();
4343

44-
AuthenticationTicket unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
44+
AuthenticationTicket? unprotected = cookieOptions.TicketDataFormat.Unprotect(backOfficeCookie!);
4545
ClaimsIdentity backOfficeIdentity = unprotected!.Principal.GetUmbracoIdentity();
4646

4747
return backOfficeIdentity;

Our.Umbraco.TagHelpers/SurfaceControllerFormTagHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ namespace Our.Umbraco.TagHelpers
1616
public class SurfaceControllerFormTagHelper : TagHelper
1717
{
1818
private readonly IDataProtectionProvider _dataProtectionProvider;
19-
private IDictionary<string, string> _routeValues;
19+
private IDictionary<string, string>? _routeValues;
2020

2121
/// <summary>
2222
/// The name of the action method.
2323
/// </summary>
2424
[HtmlAttributeName("our-action")]
25-
public string ControllerAction { get; set; }
25+
public string? ControllerAction { get; set; }
2626

2727
/// <summary>
2828
/// The name of the Umbraco controller minus the 'Controller' suffix.
2929
/// </summary>
3030
[HtmlAttributeName("our-controller")]
31-
public string ControllerName { get; set; }
31+
public string? ControllerName { get; set; }
3232

3333
/// <summary>
3434
/// The name of the area.
@@ -40,7 +40,7 @@ public class SurfaceControllerFormTagHelper : TagHelper
4040
/// Additional parameters for the route.
4141
/// </summary>
4242
[HtmlAttributeName("our-route-vals", DictionaryAttributePrefix = "our-route-val")]
43-
public IDictionary<string, string> RouteValues
43+
public IDictionary<string, string>? RouteValues
4444
{
4545
get
4646
{
@@ -62,7 +62,7 @@ public IDictionary<string, string> RouteValues
6262
/// </summary>
6363
[HtmlAttributeNotBound]
6464
[ViewContext]
65-
public ViewContext ViewContext { get; set; }
65+
public ViewContext? ViewContext { get; set; }
6666

6767
public SurfaceControllerFormTagHelper(IDataProtectionProvider dataProtectionProvider)
6868
{

0 commit comments

Comments
 (0)