Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templates of generic controllers are now pre-compiled #78

Merged
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
26 changes: 19 additions & 7 deletions src/Spark.Web.Mvc/SparkViewFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,22 @@ public IList<SparkViewDescriptor> CreateDescriptors(SparkBatchEntry entry)
{
var descriptors = new List<SparkViewDescriptor>();

var controllerName = RemoveSuffix(entry.ControllerType.Name, "Controller");
string controllerName = null;

if (entry.ControllerType.ContainsGenericParameters)
{
// generic controller have a backtick suffix in their (name e.g. "SomeController`2")
var indexOfBacktick = entry.ControllerType.Name.IndexOf("Controller`", StringComparison.Ordinal);
if (indexOfBacktick > -1)
{
// removing it otherwise locating the view templates will fail
controllerName = entry.ControllerType.Name.Substring(0, indexOfBacktick);
}
}
else
{
controllerName = RemoveSuffix(entry.ControllerType.Name, "Controller");
}

var viewNames = new List<string>();

Expand Down Expand Up @@ -375,12 +390,9 @@ private static bool TestMatch(string potentialMatch, string pattern)

private static string RemoveSuffix(string value, string suffix)
{
if (value.EndsWith(suffix, StringComparison.InvariantCultureIgnoreCase))
{
return value.Substring(0, value.Length - suffix.Length);
}

return value;
return value.EndsWith(suffix, StringComparison.InvariantCultureIgnoreCase)
? value.Substring(0, value.Length - suffix.Length)
: value;
}

#region IViewEngine Members
Expand Down
Loading