F
Fred Mellender
I would like to make a library (dll) that contains a number of classes and
interfaces for use by other implementers. One of the interfaces I want to
define is:
public interface Foo
{
Bar MakeABar();
}
It seems that C# compiler requires that I define Bar in the library,
complaining:
"The type or namespace name 'Bar' could not be found (are you missing a
using directive or an assembly reference?)"
But I want users of my library to define their own Bar, and to implement
MakeABar in any of their classes that inherit from my interface via their
own Bar. Indeed, I want them to be able to define different implementations
of Bar in different projects, and to use my library in each.
C++ has the construct:
Class Bar;
Which lets you mention the type Bar without defining it. It even lets me
define MakeABar as
Bar MakeABar()
{
return null;
}
without having to define the class Bar. I could put some sort of dummy Bar
class in my library and have users inherit from it but that does not work
for my purposes since I do not want the users to have to downcast in order
to use the object returned from MakeABar.
To be honest upcoming "generics" will (?) solve my specific problem, but I
wonder if the C# designers might consider a construct like "Class Bar;" with
a usage similar to that in C++. If not, why not?
interfaces for use by other implementers. One of the interfaces I want to
define is:
public interface Foo
{
Bar MakeABar();
}
It seems that C# compiler requires that I define Bar in the library,
complaining:
"The type or namespace name 'Bar' could not be found (are you missing a
using directive or an assembly reference?)"
But I want users of my library to define their own Bar, and to implement
MakeABar in any of their classes that inherit from my interface via their
own Bar. Indeed, I want them to be able to define different implementations
of Bar in different projects, and to use my library in each.
C++ has the construct:
Class Bar;
Which lets you mention the type Bar without defining it. It even lets me
define MakeABar as
Bar MakeABar()
{
return null;
}
without having to define the class Bar. I could put some sort of dummy Bar
class in my library and have users inherit from it but that does not work
for my purposes since I do not want the users to have to downcast in order
to use the object returned from MakeABar.
To be honest upcoming "generics" will (?) solve my specific problem, but I
wonder if the C# designers might consider a construct like "Class Bar;" with
a usage similar to that in C++. If not, why not?