/// <summary> /// Cache all quantities with their Dimensions. /// </summary> static QuantityDimension() { Assembly CurrentAssembly = Assembly.GetExecutingAssembly(); Type[] types = CurrentAssembly.GetTypes(); var QuantityTypes = from QuantityType in types where QuantityType.IsSubclassOf(typeof(BaseQuantity)) select QuantityType; CurrentQuantityTypes.AddRange(QuantityTypes); //storing the quantity types with thier dimensions foreach (Type QuantityType in CurrentQuantityTypes) { //cach the quantities that is not abstract types if (QuantityType.IsAbstract == false && QuantityType != typeof(DerivedQuantity <>)) { //make sure not to include Dimensionless quantities due to they are F0L0T0 if (QuantityType.BaseType.Name != typeof(DimensionlessQuantity <>).Name) { //store dimension as key and Quantity Type . //create AnyQuantity<Object> Object container used just for instantiation AnyQuantity <Object> Quantity = (AnyQuantity <Object>)Activator.CreateInstance(QuantityType.MakeGenericType(typeof(object))); //store the Dimension and the corresponding Type; CurrentQuantitiesDictionary.Add(Quantity.Dimension, QuantityType); //store quantity type as key and corresponding dimension as value. CurrentDimensionsDictionary.Add(QuantityType, Quantity.Dimension); //store the quantity name and type with insensitive names CurrentQuantitiesNamesDictionary.Add(QuantityType.Name.Substring(0, QuantityType.Name.Length - 2), QuantityType); } } } }