/// <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 object target, object source) { if (target == null) { if (source is ICollection) { if (((ICollection)source).Count > 0) { target = new NamespaceTypeGroup(source); } } else { target = source; } } else if (source != null && !(source is ICollection && ((ICollection)source).Count == 0)) { if (!(target is NamespaceTypeGroup)) { target = new NamespaceTypeGroup(target); } ((NamespaceTypeGroup)target).Add(source); } }
private void GetOtherParts(object obj, List <TypeDecl> otherParts, List <string> parentTypes) { if (obj is TypeDecl) { GetOtherParts((TypeDecl)obj, otherParts, parentTypes); } else if (obj is NamespaceTypeGroup) { NamespaceTypeGroup group = (NamespaceTypeGroup)obj; // Lock the NamespaceTypeGroup while iterating it to prevent changes while parsing on other threads lock (group.SyncRoot) { foreach (object @object in group) { if (@object is TypeDecl) { GetOtherParts((TypeDecl)@object, otherParts, parentTypes); } } } } }
/// <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 NamespaceTypeGroup) { target = new NamespaceTypeGroup(source); } else { target = source; } } else if (source != null) { if (!(target is NamespaceTypeGroup)) { target = new NamespaceTypeGroup(target); } ((NamespaceTypeGroup)target).Add(source); } }
/// <summary> /// Remove the type or namespace object with the specified name from the dictionary. /// </summary> /// <param name="name">The name of the object.</param> /// <param name="obj">The <see cref="TypeDecl"/>, <see cref="Type"/>, or <see cref="Namespace"/> object.</param> protected void Remove(string name, object obj) { object existingObj; if (_dictionary.TryGetValue(name, out existingObj)) { if (existingObj is NamespaceTypeGroup) { // If there's a group with the given name, remove the object from the group NamespaceTypeGroup group = (NamespaceTypeGroup)existingObj; group.Remove(obj); 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, obj); } } else { _dictionary.Remove(name); } } }