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)
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)