Results 1 to 8 of 8

Thread: [RESOLVED] [1.0/1.1] Referencing other classes

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Resolved [RESOLVED] [1.0/1.1] Referencing other classes

    In VB 6.0 I was able to access a common class module in several of my projects. I never compiled this module as a DLL since I did not want to distribute a DLL along with the program.

    I am trying to do the same thing in C#. I have a class module that I would like to add common methods to and then be able to access those methods from various classes. So from the project, I selected Add --> Add an existing item and selected the common class file. The class was added and I continued to work. Want I neglected to notice was that VS 2003, COPIED the class file into my project. This defeated the purpose of me having a common class.

    Are you not allowed to reference class files like I did in VB 6.0?

    I hope that made sense.
    Steve
    This space for rent...

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [1.0/1.1] Referencing other classes

    I don't see the problem here.
    see, even if you add the class to the project it doesn't mean it'll be accessible from outside the project, (mark it internal instead of public for that).
    VS will Not compile a DLL file for the each class you have
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: [1.0/1.1] Referencing other classes

    Also, each file that is created in C# is a class file (I think it's the same in VB.Net, only the extensions are different).
    I guess, you want to group the common utility methods into one class file and then make a DLL of that. That you can achieve by having a separate project(DLL) for all such class files and then you can refer to that project and all its methods in your current project(UI). But if you are going to have only 1 class file for such methods then from maintainability point of view ComputerJy's suggestion is a better solution.
    Hope I'm making sense.

  4. #4

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Re: [1.0/1.1] Referencing other classes

    I think I am missing something here. Let me try this another way. Normally what I could do is create a DLL with all of the methods I need and then reference that DLL from within Mainprogone.cs and Mainprogtwo.cs shown in option one.

    Option One
    Commondll.proj
    **String.cs

    Projectone.proj
    **Mainprogone.cs

    Projecttwo.proj
    **Mainprogtwo.cs

    What I was hoping to do through was avoid creating the DLL and instead add the file String.cs to each of my projects. Whatever change I made to String.cs will take affect in both projects, as shown in option two.

    Option Two
    Projectone.proj
    **Mainprogone.cs
    **String.cs

    Projecttwo.proj
    **Mainprogtwo.cs
    **String.cs

    Is this possible?
    This space for rent...

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [1.0/1.1] Referencing other classes

    you can use "Pre-build event command line" to launch a ".bat" file that copies the file to the other project
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  6. #6

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Re: [1.0/1.1] Referencing other classes

    Thank you for the reply back. OK the short answer is that you can’t easily do this. Do you know a reason why Microsoft elected not to allow referencing of .cs files between projects?

    I guess I will build a common DLL now.
    This space for rent...

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [1.0/1.1] Referencing other classes

    Because they're sticking to OOPer concepts, and so the assemblies need to be compiled before they can be used. Hence, the requirement that your code be included, rather than 'sit' separately. With .NET, a lot of VB6 concepts go out the 19th floor window.

  8. #8

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Re: [1.0/1.1] Referencing other classes

    Thanks I can't say I like the idea. I can't see why an assembly can't be compiled using a .cs file from another project. Obviously I don't have a clue.
    This space for rent...

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