You should make A's ctor protected and B's ctor private and instead provide
a static factory method in class B like that:
public static A GetObject() { /*code here*/ }
Yes, that would be a possible solution in some cases. But my application
compiles new classes at startup that are used to extend the functionality
of existing classes. It's a kind of scripting scheme. Instead of specifying
a interface betwen script and code, I've decided to put the script in the
code.
So there might or might not be any descendants to class A, or there might
be a whole inheritance chain.
When multiple scripts have been added that extends a single class...
A
B:A
C:A
D:A
E:A
....the code is restructured to form an inheriance chain...
A
B:A
C:B
D:C
E
....and in this case a instance of E will be provided when the app wants to
construct an object of the type A.
So the actual type of the object is not known at (application-)compile
time, only the base type is known.
I've already implemented this, but I would like a nicer construction than
the current...
ScriptingEngine.GetScriptedObject
(Type type, Type[] argTypes, object[] args)
So, what I'm looking for is the transparency, syntactic sugar turning the
above code into...
new A(a,b,c,...)
/Hugo