Example #1
0
        public List <T> GetEntities <T>() where T : EntityBase
        {
            Type type = typeof(T);
            ObjectDescription objDescr = ClassFactory.GetObjectDescription(type, this);

            if (!objDescr.IsAggregated)
            {
                ILoader  loader = GetLoader(type);
                List <T> list   = Caches.GetEntities <T>();
                if ((list == null || list.Count == 0) && !_loadedTypes.Contains(type))
                {
                    {
                        if (objDescr.IsVirtual)
                        {
                            List <EntityBase> l =
                                (List <EntityBase>)
                                type.GetMethod(objDescr.GetAllMethodName,
                                               BindingFlags.Static).Invoke(null, new object[] { this });
                            list = l.ConvertAll <T>(
                                delegate(EntityBase e)
                            {
                                return(e as T);
                            }
                                );
                        }
                        else
                        {
                            list = loader.LoadAll <T>();
                        }
                        _loadedTypes.Add(type);
                    }
                }
                if (list == null || list.Count == 0)
                {
                    list = new List <T>();
                }
                return(list);
            }
            else
            {
                AgregatedClassAttribute aggr =
                    objDescr.GetAttribute <AgregatedClassAttribute>();
                List <T> l = new List <T>();
                foreach (Type t in aggr.ChildTypes)
                {
                    List <EntityBase> templist = GetEntities(t);
                    if (templist != null && templist.Count > 0)
                    {
                        foreach (T ee in templist)
                        {
                            l.Add(ee);
                        }
                    }
                }
                return(l);
            }
        }
Example #2
0
 public List <EntityBase> GetEntities(Type type)
 {
     if (!ClassFactory.GetObjectDescription(type, this).IsAggregated)
     {
         ILoader           loader = GetLoader(type);
         List <EntityBase> list   = Caches.GetEntities(loader.ReflectedType);
         if ((list == null || list.Count == 0) && !_loadedTypes.Contains(type))
         {
             {
                 if (ClassFactory.GetObjectDescription(type, this).IsVirtual)
                 {
                     list =
                         (List <EntityBase>)
                         type.GetMethod(ClassFactory.GetObjectDescription(type, this).GetAllMethodName,
                                        BindingFlags.Static).Invoke(null, new object[] { this });
                 }
                 else
                 {
                     list = loader.LoadAll();
                 }
                 _loadedTypes.Add(type);
             }
         }
         if (list == null || list.Count == 0)
         {
             list = new List <EntityBase>();
         }
         return(list);
     }
     else
     {
         AgregatedClassAttribute aggr =
             ClassFactory.GetObjectDescription(type, this).GetAttribute <AgregatedClassAttribute>();
         List <EntityBase> l = new List <EntityBase>();
         foreach (Type t in aggr.ChildTypes)
         {
             List <EntityBase> templist = GetEntities(t);
             if (templist != null && templist.Count > 0)
             {
                 l.AddRange(templist);
             }
         }
         return(l);
     }
 }