Sharing Code files

G

Guest

How do I share code across files in C#, without including a reference to a
class library.

Here's what I want to do. I have a device I want to talk to. It's a
machine in a factory. It can talk on a serial port, or over ethernet.
Either way it's talking, it sends the same data. So, I encapsulate the data
structure in a class, and I stick the class in a .cs file.

Now, I want to create three projects, and they all will deal with the same
data structure. I create a solution with three projects. One is a windows
project for a device that will talk to one device over a serial port. One is
a windows project that talks to multiple devices over ethernet. One is a
pocket PC application that talks to one device on a serial port.

My thought was that I could add the class file to each of the three
projects, and then in each of the projects the file would end up getting
compiled and included in each of the three projects, and I could use the
class. Imagine my surprise when I added the file, and it made a copy,
putting it into the directory for the project. Since there are three copies,
now when I make changes to the class, I can't make them in one spot.

This is something pretty common in C, where I have a directory of commonly
used functions, and a make file that points to the directory where they
reside. Alternatively in C, I have sometimes used #include directives, and
just included the class definition. Never liked that solution much, but it
worked.

Can I add an existing class to a project without making a copy? Can I share
code between two projects, without sharing a class library, with its dll
(which couldn't work anyway, because I have Pocket PC and regular Windows
projects in the same solution)
 
M

Mehdi

Can I add an existing class to a project without making a copy? Can I share
code between two projects, without sharing a class library, with its dll
(which couldn't work anyway, because I have Pocket PC and regular Windows
projects in the same solution)

Why wouldn't the DLL work? Anyway, you can share a file across multiple
projects if you really want to (although this might cause confusion among
maintainers of your program): when you choose to add an existing file to
your project, in the open file dialog, click on the small arrow beside the
open button and choose Link File instead of Open.
 
G

Guest

Mehdi said:
Why wouldn't the DLL work? Anyway, you can share a file across multiple
projects if you really want to (although this might cause confusion among
maintainers of your program): when you choose to add an existing file to
your project, in the open file dialog, click on the small arrow beside the
open button and choose Link File instead of Open.

Thanks. That should solve the problem.

The DLL won't work because the code has to be shared between Pocket PC and
Windows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top