Exemplo n.º 1
0
        /// <summary>
        /// Attempts to find the ModelTemplateAttribute for a ModelTemplate
        /// </summary>
        public static ModelTemplateAttribute GetAttribute(ICobaltElement template)
        {
            //model templates should have a path attribute
            ModelTemplateAttribute attribute = template.GetType()
                .GetCustomAttributes(typeof(ModelTemplateAttribute), true)
                .FirstOrDefault() as ModelTemplateAttribute;

            //if this is missing, notify the caller
            if (attribute == null) {
                throw new GenericCobaltException("Models that use IModelTemplate must also declare a ModelTemplateAttribute for the class.");
            }

            //otherwise, load the content
            return attribute;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns a CobaltElement as a View
 /// </summary>
 public static ActionResult Template(this Controller controller, ICobaltElement template)
 {
     return controller.Element(template.AsElement());
 }