I use the type of safe enum type described here. I need to enclose one secure key in another. The child property (static object) is NULL when the parent constructor is created. It seems that the child constructor is not being called, and I am getting some errors. (Parent and child confuse me, but he explains the hierarchy)
Here is an example (I use netMF):
public class MyDeviceSetting
{
public readonly string Name;
public MyUnit SettingUnit;
public readonly MyUnit.UnitPurpose UnitPurpose;
#region MY STATIC SETTINGS
public static MyDeviceSetting TempUnits = new MyDeviceSetting("TempUnits", MyUnit.mm);
public static MyDeviceSetting BLAH = new MyDeviceSetting("BLAH", MyUnit.inch);
#endregion
private MyDeviceSetting(string name, MyUnit defaultUnit)
{
Name = name;
SettingUnit = defaultUnit;
UnitPurpose = SettingUnit.Purpose;
}
}
public sealed class MyUnit
{
private static int Count = 0;
public readonly int UnitID;
public readonly int TestID;
public enum UnitPurpose
{
DISTANCE,
SPEED,
TEMPERATURE,
TIME,
CLOCK,
NO_UNITS
}
public readonly string DisplayName;
public readonly string Abbreviation;
public readonly string Name;
public readonly UnitPurpose Purpose;
#region My Units
public static readonly MyUnit mm = new MyUnit("Milimeters", "mm", "mm", UnitPurpose.DISTANCE, 1);
public static readonly MyUnit inch = new MyUnit("inch", "inch", "in", UnitPurpose.DISTANCE, 2);
#endregion
private MyUnit(string name,
string displayName,
string abbreviation,
UnitPurpose unitPurpose,
int unitID)
{
Name = name;
DisplayName = displayName;
Abbreviation = abbreviation;
Purpose = unitPurpose;
UnitID = unitID;
TestID = Count;
Count++;
}
}
How can I guarantee that childit is not null? Is there any work? Edit: This post guarantees that this should work, but in my case it does not work.
