internal static object GetNodeData(Node node, Type type) { try { if (type == typeof(string) && node.Value == MultiLineStringNode.Terminator && node.ChildLines.Count > 0) { return(BaseTypes.ParseSpecialStringCase(node)); } if (BaseTypes.IsBaseType(type)) { return(BaseTypes.ParseBaseType(node.Value, type)); } var collection = CollectionTypes.TryGetCollection(node, type); if (collection != null) { return(collection); } if (!String.IsNullOrEmpty(node.Value)) { return(ComplexTypeShortcuts.GetFromShortcut(node.Value, type)); } return(ComplexTypes.RetrieveComplexType(node, type)); } catch (Exception e) { throw new Exception($"Error getting data of type {type} from node: {e.Message}"); } }
/// <summary> Interpret this file as a dictionary. Top-level keys in the file are interpreted as keys in the dictionary. </summary> /// <remarks> TKey must be a Base Type </remarks> public Dictionary <TKey, TValue> GetAsDictionary <TKey, TValue>() { if (!BaseTypes.IsBaseType(typeof(TKey))) { throw new Exception("When using GetAsDictionary, TKey must be a base type"); } var keys = GetTopLevelKeys(); var dictionary = new Dictionary <TKey, TValue>(capacity: keys.Length); foreach (var keyText in keys) { TKey key = BaseTypes.ParseBaseType <TKey>(keyText); TValue value = NodeManager.GetNodeData <TValue>(TopLevelNodes[keyText]); dictionary.Add(key, value); } return(dictionary); }