/// <summary> /// Given a regex match for a data object, create a new <see cref="XDataObject" /> instance /// for the text matched. /// </summary> /// <param name="groups">The match groups for the matched regex expression</param> /// <returns>A new <see cref="XDataObject" /> instance based on the given regex match</returns> private XDataObject ExtractDataObject(GroupCollection groups) { string type = groups["type"].Value; string name = groups["name"].Value; string body = groups["body"].Value; string uuid; XDataObject dataObject; if (type == "template") { dataObject = CreateTemplateObject(name, ref body, out uuid); } else { uuid = ExtractUuid(ref body); dataObject = new XDataObject(type, name, body, this); } RegisterObject(uuid, dataObject); return(dataObject); }
/// <summary> /// Registers a given object in the factory's object cache /// </summary> /// <param name="uuid">The object's UUID, if present, null otherwise.</param> /// <param name="dataObject">The data object itself.</param> /// <remarks>The object's name will be used as the object key if no UUID is present. /// Note: the object dictionary will only ever contain the object /// most recently seen with a given name and/or UUID. Ideally, /// a .x file will not use the same name for two different objects, /// and the specification is not clear on whether that's legal and /// if so, how to resolve duplicates (especially when it's possible /// to infer the correct object based on the expected type of object). /// In this implementation, however, no attempt is made to resolve /// duplicates intelligently; this may lead to the failure to populate /// some particular piece of the object tree, when a most recent /// object of a given name or UUID is not of the expected type.</remarks> private void RegisterObject(string uuid, XDataObject dataObject) { if (uuid != null) { #if DEBUG if (objectDictionary.ContainsKey(uuid)) { Debug.WriteLine(string.Format("Key {0} already present", uuid)); } #endif objectDictionary[uuid] = dataObject; } if (!string.IsNullOrEmpty(dataObject.Name)) { #if DEBUG if (objectDictionary.ContainsKey(dataObject.Name)) { Debug.WriteLine(string.Format("Key {0} already present", dataObject.Name)); } #endif objectDictionary[dataObject.Name] = dataObject; } }