Ejemplo n.º 1
0
        private static object GetEntity <TData>(TData data, System.Type entityType, Func <TData, string, object> func) where TData : class
        {
            object result;

            if (data == null)
            {
                result = null;
            }
            else
            {
                EntityClassAttribute             entityClassAttribute = JavaScriptSerializer.GetEntityClassAttribute(entityType);
                System.Reflection.PropertyInfo[] properties           = entityType.GetProperties();
                object obj = System.Activator.CreateInstance(entityType);
                System.Reflection.PropertyInfo[] array = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    System.Reflection.PropertyInfo propertyInfo = array[i];
                    System.Reflection.MethodInfo   setMethod    = propertyInfo.GetSetMethod();
                    if (!(setMethod == null))
                    {
                        string      propertyKey  = JavaScriptSerializer.GetPropertyKey(propertyInfo, entityClassAttribute);
                        System.Type propertyType = propertyInfo.PropertyType;
                        object      value        = EntityFactory.GetValue(func(data, propertyKey), propertyType);
                        if (value != null)
                        {
                            if (propertyType.IsGenericType)
                            {
                                if (EntityFactory.IsIList(propertyType))
                                {
                                    System.Type type = propertyType.GetGenericArguments()[0];
                                    propertyInfo.SetValue(obj, EntityFactory.GetEntities <TData>(value as System.Collections.IEnumerable, type, func), null);
                                }
                            }
                            else if (!EntityFactory.IsPrimitiveType(propertyType))
                            {
                                propertyInfo.SetValue(obj, EntityFactory.GetEntity <TData>(value as TData, propertyType, func), null);
                            }
                            else
                            {
                                setMethod.Invoke(obj, new object[]
                                {
                                    value
                                });
                            }
                        }
                    }
                }
                result = obj;
            }
            return(result);
        }
Ejemplo n.º 2
0
 public static System.Collections.Generic.IList <TEntity> GetEntities <TEntity, TData>(System.Collections.IEnumerable datas, Func <TData, string, object> func)
     where TEntity : class, new()
     where TData : class
 {
     System.Collections.Generic.IList <TEntity> result;
     if (datas == null)
     {
         result = null;
     }
     else
     {
         result = (EntityFactory.GetEntities <TData>(datas, typeof(TEntity), func) as System.Collections.Generic.IList <TEntity>);
     }
     return(result);
 }