private void FillNodesToParents(Tree node, Tree parent) { nodesToParents.Add(node, parent); foreach (Tree child in node.Children()) { FillNodesToParents(child, node); } }
/// <summary> /// Looks for new names, destructively strips them out. /// Destructively unescapes escaped chars, including "=", as well. /// </summary> private void InitializeNamesNodesMaps(Tree t) { foreach (Tree node in t.SubTreeList()) { var m = NamePattern.Match(node.Label().Value()); if (m.Success) { pnamesToNodes.Add(m.Groups[2].Value, node); nodesToNames.Add(node, m.Groups[2].Value); node.Label().SetValue(m.Groups[1].Value); } node.Label().SetValue(Unescape(node.Label().Value())); } }
protected IDictionary <ICacheRetriever, IList <IObjRelation> > AssignObjRelsToCacheRetriever(IDictionary <Type, IList <IObjRelation> > sortedIObjRefs) { IDictionary <ICacheRetriever, IList <IObjRelation> > serviceToAssignedObjRefsDict = new IdentityDictionary <ICacheRetriever, IList <IObjRelation> >(); DictionaryExtension.Loop(sortedIObjRefs, delegate(Type type, IList <IObjRelation> objRefs) { ICacheRetriever cacheRetriever = GetRetrieverForType(type); IList <IObjRelation> assignedObjRefs = DictionaryExtension.ValueOrDefault(serviceToAssignedObjRefsDict, cacheRetriever); if (assignedObjRefs == null) { assignedObjRefs = new List <IObjRelation>(); serviceToAssignedObjRefsDict.Add(cacheRetriever, assignedObjRefs); } foreach (IObjRelation objRef in objRefs) { assignedObjRefs.Add(objRef); } }); return(serviceToAssignedObjRefsDict); }
/// <summary> /// Gets called by the ObjectCopierState on custom / default behavior switches /// </summary> internal T CloneRecursive <T>(T source, ObjectCopierState ocState) { // Don't clone a null object or immutable objects. Return the identical reference in these cases if (source == null || ImmutableTypeSet.IsImmutableType(source.GetType())) { return(source); } Type objType = source.GetType(); IdentityDictionary <Object, Object> objectToCloneDict = ocState.objectToCloneDict; Object clone = DictionaryExtension.ValueOrDefault(ocState.objectToCloneDict, source); if (clone != null) { // Object has already been cloned. Cycle detected - we are finished here return((T)clone); } if (objType.IsArray) { return((T)CloneArray(source, ocState)); } if (source is IEnumerable && !(source is String)) { return((T)CloneCollection(source, ocState)); } // Check whether the object will be copied by custom behavior IObjectCopierExtension extension = extensions.GetExtension(objType); if (extension != null) { clone = extension.DeepClone(source, ocState); objectToCloneDict.Add(source, clone); return((T)clone); } // Copy by default behavior return((T)CloneDefault(source, ocState)); }
void IObjectCopierState.AddClone <T>(T source, T clone) { objectToCloneDict.Add(source, clone); }