Results 1 to 3 of 3

Thread: snipping code and creating an additional file??

  1. #1

    Thread Starter
    Addicted Member aa9gg's Avatar
    Join Date
    Apr 2009
    Location
    Chicagoland
    Posts
    184

    snipping code and creating an additional file??

    Some of my functions the form are getting long and I want to be able to snip those routines and place them into a new file, and add it to my project. How do I do it and still have reference to all my objects/variables on the form they just came off of. Seems like it would be easy to do , but I can't figure it out.

    thanks.....
    FCC Section 97.313(a) “At all times, an amateur station must use the minimum transmitter power necessary to carry out the desired communications.”

    I'd rather run a "Killer-Watt" than a KiloWatt - QRP Rules!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: snipping code and creating an additional file??

    Firstly, if your methods are getting long then the solution is not to remove them to another file. The solution is to refactor the code into multiple shorter methods. Any method that gets longer than about 20 lines should already have had that done. Always observe the Single Responsibility Principle.

    That said, you can easily separate the code for a single class into multiple files using partial classes. On the case of forms, that's already done, with the designer code in one file and the user code in another. You can declare the same class in multiple files simply by putting the Partial keyword in the declaration of at least one of them. They are then treated as a single file, with the code in each file having the same access to members declared in the other files as those declared in the same file.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: snipping code and creating an additional file??

    While I haven't tested this theory, my guess with regards to the Partial keyword is that is must be used on either just one part or all of them, rather than two or more but not all. That's easy enough to test though, i.e. create three parts and declare two partial and see if that works. I'd tend to put Partial on all parts though, for clarity.

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
  •  



Click Here to Expand Forum to Full Width