Ejemplo n.º 1
0
        public virtual T GetValue <T>()
        {
            if (ViewContext.ViewData.Model == null)
            {
                return(default(T));
            }

            var val = Accessor.GetValue(ViewContext.ViewData.Model);

            if (TagConventions.IsAssignable <T>(this))
            {
                return((T)val);
            }

            if (typeof(T) == typeof(string))
            {
                return((T)(val != null ? (object)val.ToString() : (object)string.Empty));
            }

            try
            {
                return((T)Convert.ChangeType(val, typeof(T)));
            }
            catch (Exception ex)
            {
                throw new InvalidCastException(string.Format("Cannot convert '{0}' to '{1}'", (val == null ? "null" : val.GetType().ToString()), typeof(T)), ex);
            }
        }
Ejemplo n.º 2
0
 public void Modify(Action <HtmlTag, RequestData, TAttribute> modifier)
 {
     Modifiers.Add(new Modifier(Condition, (tag, req) =>
     {
         var attribute = (TAttribute)TagConventions.GetPropertyInfo(req.Accessor).GetCustomAttributes(typeof(TAttribute), true).First();
         modifier(tag, req, attribute);
     }));
 }
Ejemplo n.º 3
0
 public void BuildBy(Func <RequestData, TAttribute, IConventionPipeline, HtmlTag> builder)
 {
     Builders.Add(new Builder(Condition, (req, pipe) =>
     {
         var attribute = (TAttribute)TagConventions.GetPropertyInfo(req.Accessor).GetCustomAttributes(typeof(TAttribute), true).First();
         return(builder(req, attribute, pipe));
     }));
 }