Example #1
0
 public static System.Collections.Generic.IList <TData> GetEntityDatas <TEntity, TData>(System.Collections.Generic.IList <TEntity> entites, Action <TData, string, object> action)
     where TEntity : class
     where TData : class, new()
 {
     System.Collections.Generic.IList <TData> result;
     if (entites == null)
     {
         result = null;
     }
     else
     {
         result = EntityFactory.GetEntityDatas <TData>(entites, typeof(TEntity), action);
     }
     return(result);
 }
Example #2
0
        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);
        }