1 namespace System.Web.Mvc {
2 using System.Collections.Generic;
4 public class TemplateInfo {
5 private string _htmlFieldPrefix;
6 private object _formattedModelValue;
7 private HashSet<object> _visitedObjects;
9 public object FormattedModelValue {
11 return _formattedModelValue ?? String.Empty;
14 _formattedModelValue = value;
18 public string HtmlFieldPrefix {
20 return _htmlFieldPrefix ?? String.Empty;
23 _htmlFieldPrefix = value;
27 public int TemplateDepth {
29 return VisitedObjects.Count;
33 // DDB #224750 - Keep a collection of visited objects to prevent infinite recursion
34 internal HashSet<object> VisitedObjects {
36 if (_visitedObjects == null) {
37 _visitedObjects = new HashSet<object>();
39 return _visitedObjects;
42 _visitedObjects = value;
46 public string GetFullHtmlFieldId(string partialFieldName) {
47 return HtmlHelper.GenerateIdFromName(GetFullHtmlFieldName(partialFieldName));
50 public string GetFullHtmlFieldName(string partialFieldName) {
51 // This uses "combine and trim" because either or both of these values might be empty
52 return (HtmlFieldPrefix + "." + (partialFieldName ?? String.Empty)).Trim('.');
55 public bool Visited(ModelMetadata metadata) {
56 return VisitedObjects.Contains(metadata.Model ?? metadata.ModelType);