Пример #1
0
        /// <summary>
        /// Returns the Resource file extension for a specific Resource Type.
        /// </summary>
        /// <param name="resType">The Resource Type to return the file extension from.</param>
        /// <returns>The specified Resource Type's file extension.</returns>
        //public static string GetFileExtByType(Type resType)
        //{
        //    if (resType == null || resType == typeof(Resource))
        //        return FileExt;
        //    else
        //        return "." + resType.Name + FileExt;
        //}
        /// <summary>
        /// Returns the Resource file extension for a specific Resource Type.
        /// </summary>
        /// <param name="resType">The Resource Type to return the file extension from.</param>
        /// <returns>The specified Resource Type's file extension.</returns>
        //public static string GetFileExtByType<T>() where T : Resource
        //{
        //    if (typeof(T) == typeof(Resource))
        //        return FileExt;
        //    else
        //        return "." + typeof(T).Name + FileExt;
        //}
        /// <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) || ContentProvider.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 =
                DualityApp.GetAvailDualityTypes(typeof(Resource))
                .FirstOrDefault(t => t.Name == typeName);

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

            // Return the result
            return(matchingInfo.AsType());
        }
Пример #2
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)
 {
     if (string.IsNullOrEmpty(filePath) || ContentProvider.IsDefaultContentPath(filePath))
     {
         return(null);
     }
     filePath = System.IO.Path.GetFileNameWithoutExtension(filePath);
     string[] token = filePath.Split('.');
     if (token.Length < 2)
     {
         return(null);
     }
     return(DualityApp.GetAvailDualityTypes(typeof(Resource)).FirstOrDefault(t => t.Name == token[token.Length - 1]));
 }