Iterate ASP.NET MVC views to find all views supporting a specific model type
Based on my findings the compiled views are not included in the assembly, so it's not going to be a walk in the park reflection.
In my opinion your best bet is going to be to list the .cshtml
razor views and then use the BuildManager
class to compile the type, which will allow you to get the Model property type.
Here is an example of looking for all Razor views that have a @Model type of LoginViewModel:
var dir = Directory.GetFiles(string.Format("{0}/Views", HostingEnvironment.ApplicationPhysicalPath),
"*.cshtml", SearchOption.AllDirectories);
foreach (var file in dir)
{
var relativePath = file.Replace(HostingEnvironment.ApplicationPhysicalPath, String.Empty);
Type type = BuildManager.GetCompiledType(relativePath);
var modelProperty = type.GetProperties().FirstOrDefault(p => p.Name == "Model");
if (modelProperty != null && modelProperty.PropertyType == typeof(LoginViewModel))
{
// You got the correct type
}
}