Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / December 2004

Tip: Looking for answers? Try searching our database.

how to count documents code lines?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
xqsnake - 04 Dec 2004 19:55 GMT
hellou it's me again ;-)

i want to count number of lines in all solution textdocs (*.cs) (how to
check if doc is a Code file?)

...
applicationObject = (_DTE)application;//works fine
...
private int GetLinesNum() {
 int lines = 0;
 foreach (Project project in applicationObject.Solution.Projects) {
   foreach (ProjectItem projectitem in project.ProjectItems) {
     Document document = projectitem.Document;//not working!!
     if (document != null) {
       TextDocument textdoc = (TextDocument)document.Object("TextDocument");
       if (textdoc != null) {
         string name = document.FullName;
         name = name.ToLower();
         if (name.EndsWith(".cs")) {
           TextPoint end = textdoc.EndPoint;
            lines += end.Line;//can be done better??
         }
      }
    }
 }
 return lines;
}

and i always get null in document, even for Form1.cs which i can edit
what's wrong with this code?
when i do the same with
foreach (Document document in applicationObject.Documents) {
 TextDocument textdoc = (TextDocument)document.Object("TextDocument");
 ...
}
it works fine but all docs must be opened! i prefer the first way ;)
thx for help
//SNAKE
Carlos J. Quintero [.NET MVP] - 10 Dec 2004 08:58 GMT
You need to open each project item (window = ProjectItem.Open(...)) and
close it after counting its lines (window.Close). Note that opening  a
project item does not imply making its window visible (you need an extra
step to make it visible: window.Visible = true).

BTW, if your goal is to count lines of your own projects rather than
building an add-in, my add-in (below) has a nice Statistics feature.

Signature

Carlos J. Quintero

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com

> hellou it's me again ;-)
>
[quoted text clipped - 35 lines]
> thx for help
> //SNAKE

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.