I think you are better off extracting the common methods and interfaces and putting them in a separate class library.
However, it is possible to do it without writing a new class library by inventing an interface for class C and putting it in project 1:
public interface IClassC
{
void Method1();
void Method2();
}
Then inside project 1, you can use dependency injection to pass it to the ClassA
constructor:
public class ClassA
{
readonly IClassC _methodsFromClassC;
public ClassA(IClassC methodsFromClassC)
{
_methodsFromClassC = methodsFromClassC;
}
public void SomeMethod()
{
_methodsFromClassC.Method1();
_methodsFromClassC.Method2();
}
}
Then in project 2 you would need to implement that interface using the static ClassC
:
public static class ClassC
{
public static void Method1()
{
Console.WriteLine("ClassC.Method1()");
}
public static void Method2()
{
Console.WriteLine("ClassC.Method2()");
}
}
public class ClassCImpl : IClassC
{
public void Method1()
{
ClassC.Method1();
}
public void Method2()
{
ClassC.Method2();
}
}
Then when you create an instance of ClassA
you would have to pass an instance of ClassCImpl
:
var classA = new ClassA(new ClassCImpl());
However, to reiterate: You should really be creating a separate class library to hold the shared interfaces and classes.