예제 #1
0
        /// <summary>
        /// Add an object to the cache, according to its type.
        /// </summary>
        /// <param name="oSubj"></param>
        /// <returns></returns>
        public virtual bool Add(Object oSubj)
        {
            Type     subjtype = oSubj.GetType();
            TypeList list     = GetTypeList(subjtype);

            if (null == list)
            {
                list          = new TypeList();
                list.TypeName = subjtype.AssemblyQualifiedName;
                Contents.Add(list);
            }
            list.Instances.Add(oSubj);
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Makes a copy of the RepositoryCache. Objects inside the cache are not copied, only the cache's TypeLists.
        /// Thus, modifying an object in the original RepositoryCache will affect the object in the copy.
        /// </summary>
        /// <returns></returns>
        public virtual RepositoryCache Copy()
        {
            RepositoryCache outCache = new RepositoryCache();

            foreach (TypeList list in Contents)
            {
                TypeList newList = new TypeList();
                newList.TypeName = list.TypeName;
                foreach (object item in list.Instances)
                {
                    newList.Instances.Add(item);
                }
            }

            return(outCache);
        }
예제 #3
0
        /// <summary>
        /// Does the repository contain the specified object?
        /// </summary>
        /// <param name="oSubj"></param>
        /// <returns></returns>
        public virtual bool Contains(Object oSubj)
        {
            Type     subjtype = oSubj.GetType();
            TypeList list     = GetTypeList(subjtype);

            if (null == list)
            {
                return(false);
            }
            foreach (Object curobj in list.Instances)
            {
                if (curobj.Equals(oSubj))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #4
0
        public virtual List <T> GetInstances <T>()
        {
            TypeList tl = GetTypeList(typeof(T));

            if (tl == null)
            {
                return(new List <T>());
            }

            List <T> outList = tl.Instances.Cast <T>().ToList();

            if (outList == null)
            {
                return(new List <T>());
            }

            return(outList);
        }
예제 #5
0
        /// <summary>
        /// Get all instances of a type known to the repository.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual List <Object> GetInstances(Type oType)
        {
            List <Object> deflist = new List <Object>();

            try
            {
                TypeList tl = GetTypeList(oType);
                if (null == tl)
                {
                    return(deflist);
                }
                deflist = tl.Instances;
                return(deflist);
            }
            catch (Exception exc)
            {
                String fn = MethodBase.GetCurrentMethod().Name;
                Util.HandleExc(this, fn, exc);
                return(deflist);
            }
        }
예제 #6
0
        /// <summary>
        /// Remove a single object, regardless of type.
        /// </summary>
        /// <param name="oSubj"></param>
        /// <returns></returns>
        public virtual bool Remove(Object oSubj)
        {
            string fn = "RepositoryCache.Remove()";

            try
            {
                Type     subjtype = oSubj.GetType();
                TypeList list     = GetTypeList(subjtype);
                if (null == list)
                {
                    Util.HandleAppErr(this, fn, "Instance " + oSubj.ToString() + " not found");
                    return(false);
                }
                list.Instances.Remove(oSubj);
                return(true);
            }
            catch (Exception exc)
            {
                Util.HandleExc(this, fn, exc);
                return(false);
            }
        }