Skip to content

Commit

Permalink
Updates for supporting nullable ref types (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdorman committed Jan 31, 2021
1 parent d6f702c commit a43857d
Show file tree
Hide file tree
Showing 25 changed files with 707 additions and 1,095 deletions.
2 changes: 1 addition & 1 deletion src/Cadru.AspNetCore.Mvc.TagHelpers/AnchorIconTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public AnchorIconTagHelper(IHtmlGenerator generator) : base(generator)
/// The CSS classes for the icon element.
/// </summary>
[HtmlAttributeName(IconAttributeName)]
public string IconCss { get; set; }
public string? IconCss { get; set; }

/// <inheritdoc/>
public override void Process(TagHelperContext context, TagHelperOutput output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public BootstrapNavLinkTagHelper(IHtmlGenerator generator) : base(generator)
/// The CSS classes for the icon element.
/// </summary>
[HtmlAttributeName(IconAttributeName)]
public string IconCss { get; set; }
public string? IconCss { get; set; }

/// <inheritdoc/>
public async override void Process(TagHelperContext context, TagHelperOutput output)
Expand Down Expand Up @@ -86,11 +86,11 @@ public async override void Process(TagHelperContext context, TagHelperOutput out

if (this.ShouldBeActive())
{
this.MakeActive(output);
MakeActive(output);
}
}

private void MakeActive(TagHelperOutput output)
private static void MakeActive(TagHelperOutput output)
{
if (output.Attributes.TryGetAttribute("class", out var classAttribute))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public BreadcrumbItemTagHelper(IHtmlGenerator generator, HtmlEncoder htmlEncoder
/// </summary>
[HtmlAttributeNotBound]
[ViewContext]
public ViewContext ViewContext { get; set; }
public ViewContext? ViewContext { get; set; }

/// <summary>
/// Gets the <see cref="IHtmlGenerator"/> used to generate the
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions src/Cadru.AspNetCore.Mvc.TagHelpers/InputPlaceholderTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,31 @@ public InputPlaceholderTagHelper(IHtmlGenerator generator) : base(generator)
/// An expression to be evaluated against the current model.
/// </summary>
[HtmlAttributeName(PlaceholderAttributeName)]
public ModelExpression Placeholder { get; set; }
public ModelExpression? Placeholder { get; set; }

/// <inheritdoc/>
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);

var placeholder = this.GetPlaceholder(this.Placeholder.ModelExplorer);
if (!output.Attributes.TryGetAttribute("placeholder", out _))
if (this.Placeholder != null)
{
output.Attributes.Add(new TagHelperAttribute("placeholder", placeholder));
var placeholder = this.GetPlaceholder();
if (!output.Attributes.TryGetAttribute("placeholder", out _))
{
output.Attributes.Add(new TagHelperAttribute("placeholder", placeholder));
}
}
}

private string GetPlaceholder(ModelExplorer modelExplorer)
private string? GetPlaceholder()
{
string placeholder;
placeholder = modelExplorer.Metadata.Placeholder;
var modelExplorer = this.Placeholder?.ModelExplorer;
var placeholder = modelExplorer?.Metadata.Placeholder;

if (String.IsNullOrWhiteSpace(placeholder))
{
placeholder = modelExplorer.Metadata.GetDisplayName();
placeholder = modelExplorer?.Metadata.GetDisplayName();
}

return placeholder;
Expand Down
11 changes: 6 additions & 5 deletions src/Cadru.AspNetCore.Mvc/Razor/LayoutViewLocationExpander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext conte
throw new ArgumentNullException(nameof(viewLocations));
}

context.Values.TryGetValue(ValueKey, out var value);

if (!String.IsNullOrEmpty(value))
if (context.Values.TryGetValue(ValueKey, out var value))
{
return viewLocations;
if (!String.IsNullOrEmpty(value))
{
}
}

return this.ExpandViewLocationsCore(viewLocations, value);

return viewLocations;
}

/// <inheritdoc/>
Expand Down
15 changes: 10 additions & 5 deletions src/Cadru.AspNetCore.Mvc/Rendering/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,17 @@ public static IEnumerable<SelectListItem> GetEnumSelectList(this IHtmlHelper htm
foreach (var name in Enum.GetNames(underlyingType))
{
var field = underlyingType.GetField(name);
if (HasUiHint(field, uiHint))
if (field != null)
{
var displayName = GetDisplayName(field);
var value = ((Enum)field.GetValue(obj: null)).ToString("d");

displayNamesAndValues.Add(new KeyValuePair<string, string>(displayName, value));
if (HasUiHint(field, uiHint))
{
var displayName = GetDisplayName(field);
var value = field.GetValue(obj: null);
if (value != null)
{
displayNamesAndValues.Add(new KeyValuePair<string, string>(displayName, ((Enum)value).ToString()));
}
}
}
}

Expand Down
Loading

0 comments on commit a43857d

Please sign in to comment.