I'm trying to build a class library which has a class called du sätter bara en referens till projektet där den andra klassen finns > du sätter bara en referens till projektet där den andra klassen finnsHow to use class library when anthor class is used
AvestaPlantFunc.
In this project building a class libray exist a class called
AvestaPlantFunc. In this class is there a method called IsBottomMixValid.
Code not relevant for the question has been removed.
This method IsBottomMixValid has one parameter and the type for this
parameter is MeltPracDataGmix meaning passing class reference
MeltPracDataGmix.
Now to my question the definition for class MeltPracDataGmix does not exist
in the same project as
the class AvestaPlantFunc. Class MeltPracDataGmix exist in another project
that build the exe file.
When a class has a reference to another class as in my example is it
nesessary that the full definition to class MeltPracDataGmix is existing in
the same project.
I assume if this was C++ it would be enough to include the class declaration
which is the header file and not the implementation.
But in C# we don't have any header files. So how do I do here?
What is the solution to this problem when the class need another class.
using System;
using MeltPracData;
namespace Common
{
public class AvestaPlantFunc
{
public bool IsBottomMixValid(MeltPracDataGmix mix)
{
//here is there some code
}
}
}
//TonySv: How to use class library when anthor class is used
Sv:How to use class library when anthor class is used
Translated to something like:
You add a reference to the project where you have your class.
If I understodd you correct, the class "MeltPracDataGmix" is found in your exe? If that's the case you have a few choices:
a) Move the class to a classlibrary that's _not_ depending on the classlib you have right now (or move your class to your current classlib?)
b) Use reflection (rellay ugly code, and bad performance, and trouble...)
c) Use interfaces. Create an interface containing the methods/properties you need from that class. Define the interface in your classlib. Then, let your class implement this interface (you need a reference from you exe to the classlib you have.) Your method then takes this interface as a parameter instead of the whole class.
I suggest method c) or a)