Ejemplo n.º 1
0
        /// <summary>
        /// Splits <paramref name="path"/> based on the last directory
        /// separator, return a string array of length 2. The first element
        /// is the left portion, the directory, and the second element
        /// is the right portion, the file name. The directory separator is
        /// stripped from the second element, so the second element never begins with a directory
        /// separator. <paramref name="ensureDirectoryElementEndingSlash"/> controls
        /// whether or not the first element retains a trailing directory separator.
        /// The return result is never null, and the elements
        /// are never null, so one of the elements may be an empty string.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="ensureDirectoryElementEndingSlash">if set to <c>true</c> [ensure directory element ending slash].</param>
        /// <returns></returns>
        public static string[] SplitFileIntoDirectoryAndName(string path, bool ensureDirectoryElementEndingSlash)
        {
            string[] result = StringUtilities.SplitAround(path, path.LastIndexOfAny(TrackbackChars));

            if (ensureDirectoryElementEndingSlash)
            {
                result[0] += Path.DirectorySeparatorChar;
            }

            return(result);
        }
        /// <summary>
        /// Finds the method.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <param name="methodName">Fully qualified name of the method.</param>
        /// <returns></returns>
        public static MethodInfo FindMethod(Assembly assembly, string methodName)
        {
            string[] pieces = StringUtilities.SplitAround(methodName, methodName.LastIndexOf('.'));

            Type type = assembly.GetType(pieces[0], false, true);

            if (type != null)
            {
                return(type.GetMethod(pieces[1]));
            }

            return(null);
        }