Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Expose GetInputType as a protected member of InputTagHelper. #5104

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
}
}

/// <summary>
/// Gets an &lt;input&gt; element's "type" attribute value based on the given <paramref name="modelExplorer"/>
/// or <see cref="InputType"/>.
/// </summary>
/// <param name="modelExplorer">The <see cref="ModelExplorer"/> to use.</param>
/// <param name="inputTypeHint">When this method returns, contains the string, often the name of a
/// <see cref="ModelMetadata.ModelType"/> base class, used to determine this method's return value.</param>
/// <returns>An &lt;input&gt; element's "type" attribute value.</returns>
protected string GetInputType(ModelExplorer modelExplorer, out string inputTypeHint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future, please do not move methods around while making other changes. It makes it harder to see what's really changing. We also aren't that persnickety about order in existing classes and someone could do a pass reordering class members on some future Engineering Day.

{
foreach (var hint in GetInputTypeHints(modelExplorer))
{
string inputType;
if (_defaultInputTypes.TryGetValue(hint, out inputType))
{
inputTypeHint = hint;
return inputType;
}
}

inputTypeHint = InputType.Text.ToString().ToLowerInvariant();
return inputTypeHint;
}

private void GenerateCheckBox(ModelExplorer modelExplorer, TagHelperOutput output)
{
if (typeof(bool) != modelExplorer.ModelType)
Expand Down Expand Up @@ -371,22 +395,6 @@ private string GetFormat(ModelExplorer modelExplorer, string inputTypeHint, stri
return format;
}

private string GetInputType(ModelExplorer modelExplorer, out string inputTypeHint)
{
foreach (var hint in GetInputTypeHints(modelExplorer))
{
string inputType;
if (_defaultInputTypes.TryGetValue(hint, out inputType))
{
inputTypeHint = hint;
return inputType;
}
}

inputTypeHint = InputType.Text.ToString().ToLowerInvariant();
return inputTypeHint;
}

// A variant of TemplateRenderer.GetViewNames(). Main change relates to bool? handling.
private static IEnumerable<string> GetInputTypeHints(ModelExplorer modelExplorer)
{
Expand Down