private static TData GetEntityData <TData>(object entity, System.Type entityType, Action <TData, string, object> action) where TData : class, new() { TData result; if (entity == null) { result = default(TData); } else { TData tData = System.Activator.CreateInstance <TData>(); EntityClassAttribute entityClassAttribute = JavaScriptSerializer.GetEntityClassAttribute(entityType); System.Reflection.PropertyInfo[] properties = entityType.GetProperties(); System.Reflection.PropertyInfo[] array = properties; for (int i = 0; i < array.Length; i++) { System.Reflection.PropertyInfo propertyInfo = array[i]; string propertyKey = JavaScriptSerializer.GetPropertyKey(propertyInfo, entityClassAttribute); object value = propertyInfo.GetValue(entity, null); if (value == null) { action(tData, propertyKey, value); } else { System.Type propertyType = propertyInfo.PropertyType; if (propertyType.IsGenericType) { if (EntityFactory.IsIList(propertyType)) { System.Type type = propertyType.GetGenericArguments()[0]; if (type.IsClass) { System.Collections.IList entites = value as System.Collections.IList; System.Collections.Generic.IList <TData> entityDatas = EntityFactory.GetEntityDatas <TData>(entites, type, action); action(tData, propertyKey, entityDatas); } } } else if (!EntityFactory.IsPrimitiveType(propertyInfo.PropertyType)) { action(tData, propertyKey, EntityFactory.GetEntityData <TData>(value, propertyInfo.PropertyType, action)); } else { action(tData, propertyKey, value); } } } result = tData; } return(result); }
public static TData GetEntityData <TEntity, TData>(TEntity entity, Action <TData, string, object> action) where TEntity : class where TData : class, new() { TData result; if (entity == null) { result = default(TData); } else { result = EntityFactory.GetEntityData <TData>(entity, entity.GetType(), action); } return(result); }
private static System.Collections.Generic.IList <TData> GetEntityDatas <TData>(System.Collections.IEnumerable entites, System.Type entityType, Action <TData, string, object> action) where TData : class, new() { System.Collections.Generic.IList <TData> result; if (entites == null) { result = null; } else { System.Collections.Generic.IList <TData> list = new System.Collections.Generic.List <TData>(); foreach (object current in entites) { TData entityData = EntityFactory.GetEntityData <TData>(current, entityType, action); list.Add(entityData); } result = list; } return(result); }