예제 #1
0
        /**********************************************************************************/

        public CrateManifestType GetManifestType <T>()
        {
            CrateManifestType manifestType;

            ManifestTypeCache.TryResolveManifest(typeof(T), out manifestType);
            return(manifestType);
        }
예제 #2
0
        /**********************************************************************************/

        private static CrateManifestType GetManifest(object content)
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(content, out manifestType))
            {
                throw new ArgumentException("Content is not marked with CrateManifestAttribute", "content");
            }

            return(manifestType);
        }
예제 #3
0
        /**********************************************************************************/
        /// <summary>
        /// Check if the crate's manifest type is compatible with given Manifest
        /// </summary>
        /// <typeparam name="T">Type of mainifest</typeparam>
        /// <returns></returns>
        public bool IsOfType <T>()
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(typeof(T), out manifestType))
            {
                return(false);
            }

            return(ManifestType == manifestType);
        }
예제 #4
0
        /**********************************************************************************/

        public CrateManifestType GetManifestType(Type type)
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(type, out manifestType))
            {
                throw new ArgumentException("Type is not marked with CrateManifestAttribute or ManifestType is not set");
            }

            return(manifestType);
        }
예제 #5
0
        /**********************************************************************************/
        /// <summary>
        /// Remove all crates with the content of given type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static int Remove <T>(this ICrateStorage storage)
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(typeof(T), out manifestType))
            {
                return(0);
            }

            return(storage.Remove(x => x.ManifestType == manifestType));
        }
예제 #6
0
        /**********************************************************************************/

        public void RegisterManifest(Type type)
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(type, out manifestType))
            {
                throw new ArgumentException("Type is not marked with CrateManifestAttribute or ManifestType is not set");
            }

            lock (_typeMapping)
            {
                _typeMapping[manifestType] = type;
            }
        }
예제 #7
0
        /**********************************************************************************/
        /// <summary>
        /// Returns all crates that complies with the predicate and with content of the give type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static IEnumerable <Crate <T> > CratesOfType <T>(this ICrateStorage storage, Predicate <Crate> predicate)
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(typeof(T), out manifestType))
            {
                yield break;
            }

            foreach (var crate in storage)
            {
                if (crate.ManifestType == manifestType && (predicate == null || predicate(crate)))
                {
                    yield return(new Crate <T>(crate));
                }
            }
        }
예제 #8
0
        /**********************************************************************************/
        /// <summary>
        /// Find content of given type among all crates that complies with the predicate
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="crateContent"></param>
        /// <returns></returns>
        public static bool TryGetValue <T>(this ICrateStorage storage, Predicate <Crate> predicate, out T crateContent)
        {
            CrateManifestType manifestType;

            if (!ManifestTypeCache.TryResolveManifest(typeof(T), out manifestType))
            {
                crateContent = default(T);
                return(false);
            }

            foreach (var crate in storage)
            {
                if (crate.ManifestType == manifestType && predicate(crate))
                {
                    crateContent = crate.Get <T>();
                    return(true);
                }
            }

            crateContent = default(T);
            return(false);
        }
예제 #9
0
        /**********************************************************************************/

        public bool TryGetManifestType(Type type, out CrateManifestType manifestType)
        {
            return(ManifestTypeCache.TryResolveManifest(type, out manifestType));
        }
예제 #10
0
 public bool TryResolveManifestType(string manifestTypeName, out CrateManifestType manifestType)
 {
     return(ManifestTypeCache.TryResolveManifest(manifestTypeName, out manifestType));
 }