forked from mvccontrib/MvcContrib-2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed internal classes for better understanability
- Loading branch information
1 parent
151ff55
commit 03cd232
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/MVCContrib/UI/InputBuilder/InputSpecification/ViewModelFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Reflection; | ||
using System.Web.Mvc; | ||
using MvcContrib.UI.InputBuilder.Conventions; | ||
using MvcContrib.UI.InputBuilder.Views; | ||
|
||
namespace MvcContrib.UI.InputBuilder.InputSpecification | ||
{ | ||
public class ViewModelFactory<T> where T : class | ||
{ | ||
private readonly IModelPropertyConventions _conventions; | ||
private readonly HtmlHelper<T> _htmlHelper; | ||
|
||
public ViewModelFactory(HtmlHelper<T> htmlHelper, IModelPropertyConventions conventions) | ||
{ | ||
_htmlHelper = htmlHelper; | ||
_conventions = conventions; | ||
} | ||
|
||
public PropertyViewModel Create(PropertyInfo propertyInfo) | ||
{ | ||
object value = _conventions.ValueFromModelPropertyConvention(propertyInfo, _htmlHelper.ViewData.Model); | ||
PropertyViewModel model = _conventions.ModelPropertyBuilder(propertyInfo, value); | ||
|
||
model.PropertyIsRequired = _conventions.PropertyIsRequiredConvention(propertyInfo); | ||
model.PartialName = _conventions.PartialNameConvention(propertyInfo); | ||
model.Name = _conventions.PropertyNameConvention(propertyInfo); | ||
model.Label = _conventions.LabelForPropertyConvention(propertyInfo); | ||
model.Example = _conventions.ExampleForPropertyConvention(propertyInfo); | ||
model.HasValidationMessages = _conventions.ModelIsInvalidConvention(propertyInfo, _htmlHelper); | ||
model.Type = _conventions.PropertyTypeConvention(propertyInfo); | ||
model.Layout = _conventions.Layout(model.PartialName); | ||
|
||
return model; | ||
} | ||
|
||
public TypeViewModel Create() | ||
{ | ||
TypeViewModel model = new ModelType<T> {Value = _htmlHelper.ViewData.Model}; | ||
model.PartialName = _conventions.PartialNameForTypeConvention(typeof(T)); | ||
model.Label = _conventions.LabelForTypeConvention(typeof(T)); | ||
model.Type = typeof(T); // _conventions.PropertyTypeConvention(propertyInfo); | ||
model.Layout = _conventions.Layout(model.PartialName); | ||
return model; | ||
} | ||
} | ||
} |