[Mono-list] Implementing mix-ins...
Freeman Pascal
pascal@pascal.org
Tue, 17 Dec 2002 16:51:20 -0600
I suspect this is way off topic. If someone could
point me to a better forum I would appreciate it.
I'm interested in implementing true mix-ins in C#.
I know this can be done using interfaces, but
interfaces force the author to provide an
implementation for the interface within the class.
This forces the implementation to be specific to
the class implementing the interface and does not
allow a generic solution.
A broader solution would be to write the class to
be derived from an abstract class that provides
a general solution to implementing the interface,
but with a single inheritance model this can be
problematic at times.
Is it possible to use attributes in C#/VB.NET to
have code inserted or associated at compile time
with a class in such a way as it appears to have
been originally written within the context of the
using class?
module FooBarBaz
{
public class Foo
{
public String A
{
get { return _a; }
set { _a = value; }
}
private string _a = "Bilbo";
}
[MixIn (Foo)]
public class Bar
{
public void test ()
{
Console.Out.WriteLine (A); // prints "Bilbo"
}
}
[MixIn (Foo)]
public class Baz
{
public Baz ()
{
A = "Fordo";
}
public void test ()
{
Console.Out.WriteLine (A); // prints "Frodo"
}
}
}
I hope I have explained enough to get my idea across.
-Freeman