Пример #1
0
        private int IndexOf <T>(IModelProperty fieldProp, object model, T item)
        {
            int    index = -1;
            object value = fieldProp.Get(model);

            if (value is IEnumerable <T> )
            {
                IEnumerable <T> list = (IEnumerable <T>)value;
                index = IndexOf(list, item);
            }
            else
            {
                throw new FormatException(String.Format("Generic type of property type {0} does not match generic type of item {1}", value.GetType().Name, typeof(T).Name));
            }
            return(index);
        }
Пример #2
0
        private HtmlString SiteEditable <TProp>(IViewModel model, IFieldSet fields, IModelProperty fieldProp, int index)
        {
            string markup    = string.Empty;
            object value     = null;
            string propValue = string.Empty;

            try
            {
                var field = GetField(fields, fieldProp);
                markup    = IsSiteEditEnabled(model) ? GenerateSiteEditTag(field, index) : string.Empty;
                value     = fieldProp.Get(model);
                propValue = value == null ? string.Empty : value.ToString();
            }
            catch (NullReferenceException)
            {
                return(null);
            }
            return(new HtmlString(markup + propValue));
        }