Complicated Project NEED HELP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Complicated Project NEED HELP

  1. #1
    Join Date
    Jun 2010
    Posts
    23

    Complicated Project NEED HELP

    For this project i need to have the ability to analyze a file containing a number of .NET(3.5) class's from source code.. identify every class and then output each seperate class into their own text file

    i.e(this is what the file is like, contains a number of class's in it, one after another))
    [class 1 attributes]
    class 1
    {code}

    [class 2 attributes]
    class 2
    {code}

    What do you think would be the best way to do this?

    What i was thinking of doing is somehow using regex's to identify [attributes] and the beginning of class's and then save the text(code) in between each.



    I know how to read text from a file, use regex's and save text to a file, the only problem i have is somehow identifying and saving the text(code) for each class.

    Would it be better to analyse the text line by line?

    Any help in getting me started would be greatly appreciated and once i start develoiping code i will definitley post it up here for review!

  2. #2
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,851

    Re: Complicated Project NEED HELP

    I think I would just do it line by line. If there is any chance of a class within a class then I would set up a counter to keep track of which class I am in.

    I would key on the phrases that begin a class and the end class statements.

    Seems pretty simple.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jun 2010
    Posts
    23

    Re: Complicated Project NEED HELP

    now what do you mean when you say key phrases that being and end class?

    Each class will mostly begin with "public partial class"
    and will end with the usual bracket "}"


    You mean trying to capture the text between A and B?

    A
    7g65u
    ybu6un
    76nbu56be
    hu
    B

  4. #4
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,851

    Re: Complicated Project NEED HELP

    I mean read each line,
    Test the line, Is it the first line of a new class? Is it the last line?
    When I posted I thought I was in the VB.net forum which would be a bit more simple as each class ends with End Class.

    Still is doable with a C# class just need to keep track of the braces. I would likely use an int var and increment for each { decrement for each } when value is 0 that would be the end of the class.

    A little more difficult in this case but still not that bad, provided the code being parsed is properly written.
    Always use [code][/code] tags when posting code.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,420

    Re: Complicated Project NEED HELP

    If you have all the source files for the project, you may consider compiling the source files and then use reflection to extract the classes and their associated methods, properties and attributes.

  6. #6
    Join Date
    Jun 2010
    Posts
    23

    Re: Complicated Project NEED HELP

    Ok, i could easily put in place the brack "[]" counter.

    The only thing is once i find the beginning of a class...how would i start storing the text that is between the beginning of the class and the ending bracket? "]"?

    Would i just start storing the class in another once once i find the beginning of a class and then just stop storing the text once i find the end?

  7. #7
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,851

    Re: Complicated Project NEED HELP

    Pretty much,
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Jun 2010
    Posts
    23

    Re: Complicated Project NEED HELP

    Ok Thanks

    Once i start coding it hopefully itll work and ill let ya guys kno

  9. #9
    Join Date
    Jun 2010
    Posts
    23

    Re: Complicated Project NEED HELP

    How would i get the code to store the text for every line between the beginning and end.

    I kno the code to "mark" the beginning and "end" of a class but how would i get it to continuously store the text into another array until the end of the class?


    string[] lines = File.ReadAllLines(@"c:\Ucore.cs");

    foreach (string line in lines)
    {
    MatchCollection url = regex.Matches(line);
    textBox1.Text = line;

    if (line.Contains("["))
    {
    righter = righter + 1;
    store.Add(line);
    //SOMEHOW STORE ALL THE TEXT IN CLASS

    }
    else if (line.Contains("]") )
    {
    lefter = lefter + 1;
    SOMEHOW STOP STORING TEXT
    }


    This is what i have to mark the beginning and end of a class...
    How would i get the code to continuously store code until it reaches the end of the class? I know this is probably wrong because it would only store the text in the array everytime "[" appears in a line, but how would i go about storing it anyway?

    Also is it possible to "close" an array so it would stop storing the text?
    andddddd(sorry for all the questions guys).....how would i have the loop to continue this cycle of storing text until it reaches the end of the file?

  10. #10
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,851

    Re: Complicated Project NEED HELP

    I would assume that you could add it to a stream as you go, I am sure you could write it to a file as you go. Your goal was to create a seperate file for each class wasn't it? If so then it would make sense to just write it on the fly.
    Always use [code][/code] tags when posting code.

  11. #11
    Join Date
    Jun 2010
    Posts
    23

    Re: Complicated Project NEED HELP

    Yes it was...so each time it reaches the end of a class it would jsut create the file and start over again?

    But If i have it in a while loop, wouldnt it break the loop completely?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center