/**********************************************************************************/

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

            ManifestTypeCache.TryResolveManifest(typeof(T), out manifestType);
            return(manifestType);
        }
示例#2
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);
        }
示例#3
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);
        }
        /**********************************************************************************/
        /// <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));
        }
示例#5
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);
        }
示例#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;
            }
        }
        /**********************************************************************************/
        /// <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));
                }
            }
        }
        /**********************************************************************************/
        /// <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));
 }