/// <summary> /// Add a code object with the specified name to the dictionary. /// </summary> /// <param name="name">The name of the object.</param> /// <param name="namedCodeObject">The named code object.</param> public void Add(string name, INamedCodeObject namedCodeObject) { // Protect against null names - shouldn't occur, but might in rare cases for code with parsing errors if (name != null) { INamedCodeObject existingObj; if (_dictionary.TryGetValue(name, out existingObj)) { // If we had a name collision, add to any existing group, or create a new one if (existingObj is NamedCodeObjectGroup) { ((NamedCodeObjectGroup)existingObj).Add(namedCodeObject); } else { _dictionary.Remove(name); _dictionary.Add(name, new NamedCodeObjectGroup { existingObj, namedCodeObject }); } } else { _dictionary.Add(name, namedCodeObject); } } }
/// <summary> /// Add a source object or group to a target object or group, converting the target into a group if necessary. /// </summary> /// <param name="target">The target object or group.</param> /// <param name="source">The source object or group.</param> public static void Add(ref INamedCodeObject target, INamedCodeObject source) { if (target == null) { if (source is NamedCodeObjectGroup) { target = new NamedCodeObjectGroup(source); } else { target = source; } } else if (source != null) { if (!(target is NamedCodeObjectGroup)) { target = new NamedCodeObjectGroup(target); } ((NamedCodeObjectGroup)target).Add(source); } }
/// <summary> /// Remove the object with the specified name from the dictionary. /// </summary> /// <param name="name">The name of the object.</param> /// <param name="namedCodeObject">The named code object.</param> public void Remove(string name, INamedCodeObject namedCodeObject) { INamedCodeObject existingObj; if (_dictionary.TryGetValue(name, out existingObj)) { if (existingObj is NamedCodeObjectGroup) { // If there's a group with the given name, remove the object from the group NamedCodeObjectGroup group = (NamedCodeObjectGroup)existingObj; group.Remove(namedCodeObject); if (group.Count == 1) { // If only one object is left in the group, replace the group with the object _dictionary.Remove(name); _dictionary.Add(name, namedCodeObject); } } else { _dictionary.Remove(name); } } }
/// <summary> /// Add the specified <see cref="INamedCodeObject"/> to the group. /// </summary> public void Add(INamedCodeObject namedCodeObject) { _list.Add(namedCodeObject); }
protected SymbolicRef(INamedCodeObject namedCodeObject, bool isFirstOnLine) { _reference = namedCodeObject; IsFirstOnLine = isFirstOnLine; }