static void Load() { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenBioChem.Resources.Elements.Elements.csv"); StreamReader reader = new StreamReader(stream); string[] lines = reader.ReadToEnd().Split('\n'); // Clears existed data elementsBySymbol = new Dictionary<string, Element>(120); elements = null; // (Skip title line #0) for (int i = 1; i < lines.Length; i++) { string[] splitted = lines[i].Split(';'); if (splitted.Length < 9) continue; // Skip empty/incorrect lines Element element = new Element( splitted[1], // Symbol splitted[2], // Name ParseInt(splitted[0]), // Number ParseInt(splitted[7]), // Group ParseInt(splitted[8]), // Period ParseDouble(splitted[5]), // Van der Waals radius ParseDouble(splitted[3]), // Empirical radius ParseDouble(splitted[4]), // Calculated radius ParseDouble(splitted[6]) // Covalent radius ); elementsBySymbol.Add(element.Symbol, element); } // Set all elements array elements = elementsBySymbol.Values.ToArray(); }
/// <summary> /// Get material for element /// </summary> /// <param name="element">Element</param> /// <returns>Material</returns> public Material this[Element element] { get { return materials[element]; } }
static byte IndexOfElement(Element element) { for (int i = 0; i < Element.Elements.Length; i++) { if (Element.Elements[i] == element) return (byte)i; } return 0; }