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 TEntity GetEntity <TEntity, TData>(TData data, Func <TData, string, object> func)
            where TEntity : class, new()
            where TData : class
        {
            TEntity result;

            if (data == null)
            {
                result = default(TEntity);
            }
            else
            {
                result = (TEntity)((object)EntityFactory.GetEntity <TData>(data, typeof(TEntity), func));
            }
            return(result);
        }
Ejemplo n.º 3
0
 private static System.Collections.IList GetEntities <TData>(System.Collections.IEnumerable datas, System.Type type, Func <TData, string, object> func) where TData : class
 {
     System.Collections.IList result;
     if (datas == null)
     {
         result = null;
     }
     else
     {
         System.Type typeFromHandle = typeof(System.Collections.Generic.List <>);
         System.Type type2          = typeFromHandle.MakeGenericType(new System.Type[]
         {
             type
         });
         System.Collections.IList list = System.Activator.CreateInstance(type2) as System.Collections.IList;
         foreach (object current in datas)
         {
             list.Add(EntityFactory.GetEntity <TData>(current as TData, type, func));
         }
         result = list;
     }
     return(result);
 }
Ejemplo n.º 4
0
 public T ToEntity <T>() where T : class, new()
 {
     return(EntityFactory.GetEntity <T, IHashMap>(this, (IHashMap ho, string key) => ho.GetValue <object>(key)));
 }