There are two ways you can do this.
(1) Compile both source files into the same binary output file.
or
(2) Reference the binary file that contains the code you need to use when
building.
Note that both of these require you to do something to the input for the
compiler.
If you are using Visual Studio .NET, here's how it will look:
(1) Make sure the two source files are in the same project. That is all.
(2) Make sure the calling project has a reference to the code being called.
Use the 'Add References' feature. In Solution Explorer, right-click on the
References item for the project that's going to call the function and select
Add References. Add a reference to the component that contains the code you
wish to call. If the component is a different project in the same solution,
add it as a 'Project' reference. Otherwise, Browse... for the DLL.
If you are using the compiler from the command line, here's how it will
look:
(1) csc SourceFile1.cs SourceFile2.cs
or
(2) csc /r:ExternalCompo nent.dll SourceFile1.cs
That "/r" switch is what a 'reference' in VS.NET means. It says "The code
I'm compiling now makes use of classes defined in this external DLL here".
Regardless of which of these two techniques you use, the source code will
look the same. You can either use the fully qualified name, e.g.
ABELSoft.Report ing.User.Facade .ReportRenderer .PrintDestinati on.PrintDestina tionPrinter,
or you can add a 'using' statement to the top of the file:
using ABELSoft.Report ing.User.Facade ;
and then just refer to it as
ReportRenderer. PrintDestinatio n.PrintDestinat ionPrint.
Note that the 'using' statement does not render the steps mentioned earlier
optional. You still need to do either (1) or (2). The 'using' statement is
*never* interpreted by the C# compiler as an instruction to go and look for
some external file. It simply tells it that you plan not to bother using
the full namespace every time.
By the way, in C#, it's not normal to do this:
public enum PrintDestinatio n
{
PrintDestinatio nPrinter,
PrintDestinatio nScreen,
PrintDestinatio nFile
}
This looks like something a C++ developer would do. In C# we normally do
this:
public enum PrintDestinatio n
{
Printer,
Screen,
File
}
That would be a bad idea in C++ of course because in C++, enumeration entry
names are scoped by namespace. But in C#, you never ever see the name of
an enumeration entry used in isolation. It is *required* to be referred to
via its containing enum name. So it would always be
PrintDestinatio n.Printer, etc. Given this fact, putting the enum name in
the enum member is always redundant.
--
Ian Griffiths -
http://www.interact-sw.co.uk/iangblog/
<Dj******@ABELS oft.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
I need to call(reference) class member
"PrintDestinati on.PrintDestina tionPrinter" from another file. How do I
do it, I tried
"ReportRenderer .PrintDestinati on.PrintDestina tionPrinter" but it
doesn't work. Please help!
here is my class:
*************** *************** ***********
using System;
using CrystalDecision s.CrystalReport s.Engine;
using CrystalDecision s.Shared;
using System.Data;
using ABELSoft.Report ing.User.Facade ;
namespace ABELSoft.Report ing.User.Facade
{
/// <summary>
/// Summary description for ReportRenderer.
/// </summary>
public class ReportRenderer
{
private CrystalDecision s.CrystalReport s.Engine.Report Document
m_ReportDocumen t;
private string m_sReportName;
private PrintDestinatio n m_PrintDestinat ion;
private string m_sDestinationN ame;
private DataSet m_ReportData;
public void RenderReport()
{
switch( m_PrintDestinat ion )
{
case PrintDestinatio n.PrintDestinat ionScreen:
{
ReportPreviewFa c Preview = new ReportPreviewFa c();
Preview.ReportS ource = m_ReportDocumen t;
Preview.ShowDia log();
break;
}
case PrintDestinatio n.PrintDestinat ionPrinter:
{
m_ReportDocumen t.PrintToPrinte r( 1, false, 0, 0 );
break;
}
case PrintDestinatio n.PrintDestinat ionFile:
{
m_ReportDocumen t.Export();
break;
}
}
}
public enum PrintDestinatio n
{
PrintDestinatio nPrinter,
PrintDestinatio nScreen,
PrintDestinatio nFile
}
#endregion public routines
}
}