# Inherit from class with inaccessible abstract members and all constructors inaccessible

The class System.Globalization.EastAsianLunisolarCalendar of the mscorlib.dll assembly is non-nested public but its sole instance constructor is internal and it also declares some internal abstract members.

The problem: Write a C# class in your own assembly (code must compile with usual C# compiler) where a class derives from (inherits) the System.Globalization.EastAsianLunisolarCalendar of the BCL.

Your class must have System.Globalization.EastAsianLunisolarCalendar as its direct base class. It is not allowed to have a third class in "between" your class and that class in the inheritance hierarchy.

(Advanced stuff like dynamic assemblies or runtime IL emission is not needed.)

(Stated as a C# problem. Discussions on whether the equivalent problem can be solved in other object-oriented languages too, will also be considered interesting.)

It is not required that the class you write is usable in any way ;-)

• Did not have enough reputation to create tags encapsulation, inheritance, access-level. Nov 28 '13 at 11:34
• You should come up with an objective winning criteria and post as a code challenge Nov 28 '13 at 16:16
• @Cruncher Put in code-challenge category. Not sure about winning criterion but I guess the first post to give a valid solution wins. Nov 28 '13 at 17:55
• -1: no objective winning criterion and changed question fundamentally after a valid answer was given. Nov 29 '13 at 7:28
• Looks like "first valid answer wins". Nov 29 '13 at 8:30

Well, I have either to call a base constructor (which is not accessible) or an other constructor in the same class.

public abstract class Class1 : System.Globalization.EastAsianLunisolarCalendar {
private Class1() : this(1) {}
private Class1(int i) : this() {}
}


So let's call the constructors recursive. Not very useful, but who cares?

• Yes, this was the answer I had in mind. Too bad my original phrasing didn't exclude w0lf's solution, as he was first. I still award the "accepted" check mark to this answer. Nov 29 '13 at 8:30
• Afaik, you could even intercept the instance with a destructor... Nov 16 '14 at 18:23
• Will the instance ever be eligible for garbage collection? Do you terminate the thread running in an infinite loop (jumping between the two constructors)? Possibly another way to get an instance is System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(Class1)). Nov 16 '14 at 18:53
• codeblog.jonskeet.uk/2014/10/23/… Nov 16 '14 at 20:35
• Interesting post. If this cyclic constructor chain hack was new to Jon Skeet, he should have been reading more of your answers at Programming Puzzles & Code Golf Stack Exchange ;-) Nov 17 '14 at 6:37

One way to do it is to inherit a subclass of System.Globalization.EastAsianLunisolarCalendar:

public class MySubclass : System.Globalization.JapaneseLunisolarCalendar
{
public static void Test()
{
var instance = new MySubclass();

Console.WriteLine(instance is System.Globalization.EastAsianLunisolarCalendar);
// this prints "True"
}
}

• Damn, will have to upvote this because my problem text didn't exclude this solution. However, the intention was to require EastAsianLunisolarCalendar to be the direct base class. Will update question. Sorry I won't award this question a winner. Nov 29 '13 at 6:50