Exemplo n.º 1
0
        public static KOModel ToKO(this IEnumerable <object> list, string name)
        {
            var model = new KOModel();

            model.AddArray(name, list.Select(item => ToKO((object)item)).ToList(), true);
            return(model);
        }
Exemplo n.º 2
0
 public static KOModel ToKO(this object item)
 {
     var model = new KOModel();
     var propertyInfos = item.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
     foreach (var property in propertyInfos)
     {
         if (!property.GetCustomAttributes(typeof (KOIgnoreAttribute)).Any())
         {
             var observable = !property.GetCustomAttributes(typeof (KONotObservableAttribute)).Any();
             AddToKOModel(item, property, model, observable);
         }
     }
     return model;
 }
Exemplo n.º 3
0
 private static void AddToKOModel(object item, PropertyInfo property, KOModel model, bool observable)
 {
     if (IsSimpleType(property.PropertyType))
     {
         AddAttribute(item, property, model, observable);
     }
     else if (IsList(property.PropertyType))
     {
         AddArray(item, property, model, observable);
     }
     else
     {
         AddObject(item, property, model, observable);
     }
 }
Exemplo n.º 4
0
        private static void AddArray(object item, PropertyInfo property, KOModel model, bool observable)
        {
            var listType = GetListType(property.PropertyType);

            if (IsSimpleType(listType))
            {
                dynamic list = property.GetValue(item) ?? new List <object>();
                model.AddArray(ToJavascriptName(property), list, observable);
            }
            else
            {
                var list = property.GetValue(item) as IEnumerable <object> ?? new List <object>();
                model.AddArray(ToJavascriptName(property), list.Select(x => x.ToKO()), observable);
            }
        }
Exemplo n.º 5
0
 private static void AddToKOModel(object item, PropertyInfo property, KOModel model, bool observable)
 {
     if (IsSimpleType(property.PropertyType))
     {
         AddAttribute(item, property, model, observable);
     }
     else if (IsList(property.PropertyType))
     {
         AddArray(item, property, model, observable);
     }
     else
     {
         AddObject(item, property, model, observable);
     }
 }
Exemplo n.º 6
0
        public static KOModel ToKO(this object item)
        {
            var model         = new KOModel();
            var propertyInfos = item.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in propertyInfos)
            {
                if (!property.GetCustomAttributes(typeof(KOIgnoreAttribute)).Any())
                {
                    var observable = !property.GetCustomAttributes(typeof(KONotObservableAttribute)).Any();
                    AddToKOModel(item, property, model, observable);
                }
            }
            return(model);
        }
Exemplo n.º 7
0
 private static void AddObject(object item, PropertyInfo property, KOModel model, bool observable)
 {
     model.AddObject(ToJavascriptName(property), property.GetValue(item).ToKO(), observable);
 }
Exemplo n.º 8
0
 public static KOModel ToKO(this IEnumerable<object> list, string name)
 {
     var model = new KOModel();
     model.AddArray(name, list.Select(item => ToKO((object) item)).ToList(), true);
     return model;
 }
Exemplo n.º 9
0
Arquivo: KOModel.cs Projeto: jni-/ToKO
 public void AddObject(string name, KOModel model, bool observable)
 {
     Objects.Add(name, new KOValue <KOModel>(model, observable));
 }
Exemplo n.º 10
0
 private static void AddObject(object item, PropertyInfo property, KOModel model, bool observable)
 {
     model.AddObject(ToJavascriptName(property), property.GetValue(item).ToKO(), observable);
 }
Exemplo n.º 11
0
Arquivo: KOModel.cs Projeto: jni-/ToKO
 public void AddObject(string name, KOModel model, bool observable)
 {
     Objects.Add(name, new KOValue<KOModel>(model, observable));
 }
Exemplo n.º 12
-1
 private static void AddArray(object item, PropertyInfo property, KOModel model, bool observable)
 {
     var listType = GetListType(property.PropertyType);
     if (IsSimpleType(listType))
     {
         dynamic list = property.GetValue(item) ?? new List<object>();
         model.AddArray(ToJavascriptName(property), list, observable);
     }
     else
     {
         var list = property.GetValue(item) as IEnumerable<object> ?? new List<object>();
         model.AddArray(ToJavascriptName(property), list.Select(x => x.ToKO()), observable);
     }
 }