Example #1
0
        /// <summary>
        /// Initializes a new instance of the CodeFile class.
        /// </summary>
        /// <param name="path">
        /// The path to the code file.
        /// </param>
        /// <param name="project">
        /// The project that contains this file.
        /// </param>
        /// <param name="parser">
        /// The parser that created this file object.
        /// </param>
        /// <param name="configurations">
        /// The list of configurations for the file.
        /// </param>
        public CodeFile(string path, CodeProject project, SourceParser parser, IEnumerable <Configuration> configurations)
            : base(project, parser, configurations)
        {
            Param.RequireNotNull(path, "path");
            Param.RequireNotNull(project, "project");
            Param.RequireNotNull(parser, "parser");
            Param.Ignore(configurations);

            // If this is not a full path, then we need to add the current directory.
            if (!path.StartsWith(@"\\", StringComparison.Ordinal) && path.Length >= 2 && path[1] != ':')
            {
                path = System.IO.Path.GetFullPath(path);
            }

            // BugFix 6777 - Update the path field after correcting the local path variable
            this.path   = path;
            this.name   = System.IO.Path.GetFileName(path);
            this.folder = StyleCopCore.CleanPath(System.IO.Path.GetDirectoryName(path));

            // Strip out the file extension.
            this.fileType = System.IO.Path.GetExtension(this.name).ToUpperInvariant();
            if (this.fileType.Length > 0)
            {
                this.fileType = this.fileType.Substring(1);
            }
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the CodeProject class.
        /// </summary>
        /// <param name="key">
        /// The unique key for the project.
        /// </param>
        /// <param name="location">
        /// The location where the project is contained.
        /// </param>
        /// <param name="configuration">
        /// The active configuration.
        /// </param>
        public CodeProject(int key, string location, Configuration configuration)
        {
            Param.Ignore(key);
            Param.Ignore(location);
            Param.RequireNotNull(configuration, "configuration");

            this.key           = key;
            this.configuration = configuration;

            if (location != null)
            {
                // Trim the path and convert it to lowercase characters
                // so that we can do string matches and find other files and
                // projects under the same location.
                this.location = StyleCopCore.CleanPath(location);
            }
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the CodeFile class.
        /// </summary>
        /// <param name="path">The path to the code file.</param>
        /// <param name="project">The project that contains this file.</param>
        /// <param name="parser">The parser that created this file object.</param>
        /// <param name="configurations">The list of configurations for the file.</param>
        public CodeFile(string path, CodeProject project, SourceParser parser, IEnumerable <Configuration> configurations)
            : base(project, parser, configurations)
        {
            Param.RequireNotNull(path, "path");
            Param.RequireNotNull(project, "project");
            Param.RequireNotNull(parser, "parser");
            Param.Ignore(configurations);

            this.path = path;

            // If this is not a full path, then we need to add the current directory.
            if (!path.StartsWith(@"\\", StringComparison.Ordinal) && path.Length >= 2 && path[1] != ':')
            {
                // Get the current directory. Remove the trailing slash if it exists.
                string directory = Directory.GetCurrentDirectory();
                if (directory.EndsWith(@"\", StringComparison.Ordinal))
                {
                    directory = directory.Substring(0, directory.Length - 1);
                }

                // Check whether the path starts with a single slash or not.
                if (path.StartsWith(@"\", StringComparison.Ordinal))
                {
                    // Prepend the drive letter.
                    string newPath = directory.Substring(0, 2) + path;
                    path = newPath;
                }
                else
                {
                    // Prepend the current directory.
                    string newPath = directory + @"\" + path;
                    path = newPath;
                }
            }

            // Strip out the name of the file.
            int index = path.LastIndexOf(@"\", StringComparison.Ordinal);

            if (-1 == index)
            {
                this.name = this.path;
            }
            else
            {
                this.name   = path.Substring(index + 1, path.Length - index - 1);
                this.folder = path.Substring(0, index);

                if (this.folder != null)
                {
                    // Trim the path and convert it to lowercase characters
                    // so that we can do string matches and find other files and
                    // projects under the same path.
                    this.folder = StyleCopCore.CleanPath(this.folder);
                }
            }

            // Strip out the file extension.
            index = this.name.LastIndexOf(".", StringComparison.Ordinal);
            if (-1 == index)
            {
                this.fileType = string.Empty;
            }
            else
            {
                this.fileType = this.name.Substring(index + 1, this.name.Length - index - 1).ToUpperInvariant();
            }
        }