Please help me to look at the following code:
-------------start----------
using System;
using System.Collections.Generic;
public class GenType
{
}
public class GenericType1<Twhere T : new()
{
public static T Instance
{
get
{
return new T();
}
}
protected static string SECTION_ID;
}
public class GenericType2<T>
: GenericType1<Twhere T : new()
{
public static T Load()
{
return Instance;
}
}
public sealed class Alpha
: GenericType2<GenType>
{
static Alpha()
{
Console.WriteLine("static ctor called.");
SECTION_ID = "Alpha";
}
}
public class Test
{
public static void Main()
{
GenType o = Alpha.Load();
}
}
-------------end----------
When I run the compiled code, I don't see "static ctor called." in
output (I am not sure why not).
I intend to implement most of the code in base generic class, only
pass some values (e.g. SECTION_ID) to base class from children class
(e.g. Alpha). Instance and Load() have to be static, do you guys have
any solution?