private void BindCollection(PropertyInfo prop, object model) { var value = prop.GetValue(model); var collectionGeneric = prop.PropertyType.GetGenericArguments().FirstOrDefault(); var listProperties = FWReflectionHelper.GetProperties(collectionGeneric, BindingFlags.Public | BindingFlags.Instance).Where(f => f.IsDefined(typeof(FWDataBindAttribute))); // Creates the class represent var collectionModel = Serialize(Activator.CreateInstance(collectionGeneric), collectionGeneric, _context, true); var propertiesNames = listProperties.Select(f => f.Name); var customString = GetCustomBindings(_context, collectionGeneric.Name); _innerProperties.Append($"fw.{collectionGeneric.Name} = function(parent,{string.Join(",", propertiesNames)}) {{ var self=this; {collectionModel._modelData} {collectionModel._datasourceData} {customString} }};"); // Adds the existing values var array = new List <string>(); if (value is IEnumerable list) { foreach (var item in list) { var itemValues = listProperties.Select(f => PropertyValue(f.GetValue(item), f.PropertyType)); array.Add($"new fw.{collectionGeneric.Name}(this,{string.Join(",", itemValues)})"); } } _modelData.Append($"self.{prop.Name}=ko.observableArray([{string.Join(",", array)}]);"); }
private void Loop(object model, Type modelType) { var properties = FWReflectionHelper.GetProperties(modelType, BindingFlags.Public | BindingFlags.Instance); foreach (var prop in properties) { // Checks if the property has the FWDataBind attribute. if (prop.IsDefined(typeof(FWDataBindAttribute))) { Databind(prop, model); } } }