Ejemplo n.º 1
0
        /// <summary>
        /// Returns the Resource Type that is associated with the specified file, based on its extension.
        /// </summary>
        /// <param name="filePath">Path to the file of whichs Resource Type will be returned</param>
        /// <returns>The Resource Type of the specified file</returns>
        public static Type GetTypeByFileName(string filePath)
        {
            // Early-out if we don't have a valid resource path
            if (string.IsNullOrEmpty(filePath) || Resource.IsDefaultContentPath(filePath))
            {
                return(null);
            }

            // Determine the (double) extension of the resource path
            filePath = PathOp.GetFileNameWithoutExtension(filePath);
            string[] token = filePath.Split('.');
            if (token.Length < 2)
            {
                return(null);
            }

            // Extract the type extension and match it with the available resource types
            string   typeName     = token[token.Length - 1];
            TypeInfo matchingInfo = CoheeApp.GetAvailCoheeTypes(typeof(Resource)).FirstOrDefault(t => t.Name == typeName);

            if (matchingInfo == null)
            {
                return(null);
            }

            // Return the result
            return(matchingInfo.AsType());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gathers all currently available <see cref="Component"/> types and stores them inside
 /// the provided collection. This will iterate over all relevant core and core plugin types
 /// that are currently known, but since users can load plugins at any time, this list
 /// should never assumed to be final.
 /// </summary>
 /// <param name="typeSet"></param>
 private static void GatherComponentTypes(HashSet <Type> typeSet)
 {
     foreach (TypeInfo typeInfo in CoheeApp.GetAvailCoheeTypes(typeof(Component)))
     {
         if (typeInfo.IsAbstract)
         {
             continue;
         }
         typeSet.Add(typeInfo.AsType());
     }
 }