private static IEnumerable <MemoryTracker.ChildReference> DistillChildReferencesFromObject(object current, object parent, string currentPath) { Type type = current.GetType(); if (type.IsClass) { yield return(new MemoryTracker.ChildReference { child = current, path = currentPath }); } else if (!type.IsPrimitive) { if (!type.IsValueType) { throw new NotImplementedException(); } string structPath = currentPath + "."; foreach (MemoryTracker.ChildReference childReference in MemoryTracker.GetAllReferencedClassesFromClassOrStruct(current, MemoryTracker.GetFieldsFromHierarchy(type, BindingFlags.Instance), parent, structPath)) { yield return(childReference); } } }
private static void AccumulateReferences(object obj, Dictionary <object, ReferenceData> references, HashSet <object> seen, Queue <object> toProcess) { ReferenceData referenceData = null; if (!references.TryGetValue(obj, out referenceData)) { referenceData = (references[obj] = new ReferenceData()); } foreach (ChildReference item in MemoryTracker.GetAllReferencedClassesFromClassOrStruct(obj, MemoryTracker.GetFieldsFromHierarchy(obj.GetType(), BindingFlags.Instance), obj, string.Empty)) { ChildReference current = item; if (!current.child.GetType().IsClass) { throw new ApplicationException(); } ReferenceData referenceData3 = null; if (!references.TryGetValue(current.child, out referenceData3)) { referenceData3 = new ReferenceData(); references[current.child] = referenceData3; } referenceData3.referredBy.Add(new ReferenceData.Link { target = obj, targetRef = referenceData, path = current.path }); referenceData.refers.Add(new ReferenceData.Link { target = current.child, targetRef = referenceData3, path = current.path }); if (!seen.Contains(current.child)) { seen.Add(current.child); toProcess.Enqueue(current.child); } } }
private static void AccumulateReferences(object obj, Dictionary <object, MemoryTracker.ReferenceData> references, HashSet <object> seen, Queue <object> toProcess) { MemoryTracker.ReferenceData referenceData = null; if (!references.TryGetValue(obj, out referenceData)) { referenceData = new MemoryTracker.ReferenceData(); references[obj] = referenceData; } foreach (MemoryTracker.ChildReference childReference in MemoryTracker.GetAllReferencedClassesFromClassOrStruct(obj, MemoryTracker.GetFieldsFromHierarchy(obj.GetType(), BindingFlags.Instance), obj, "")) { if (!childReference.child.GetType().IsClass) { throw new ApplicationException(); } MemoryTracker.ReferenceData referenceData2 = null; if (!references.TryGetValue(childReference.child, out referenceData2)) { referenceData2 = new MemoryTracker.ReferenceData(); references[childReference.child] = referenceData2; } referenceData2.referredBy.Add(new MemoryTracker.ReferenceData.Link { target = obj, targetRef = referenceData, path = childReference.path }); referenceData.refers.Add(new MemoryTracker.ReferenceData.Link { target = childReference.child, targetRef = referenceData2, path = childReference.path }); if (!seen.Contains(childReference.child)) { seen.Add(childReference.child); toProcess.Enqueue(childReference.child); } } }
private static void AccumulateStaticMembers(Type type, Dictionary <object, MemoryTracker.ReferenceData> references, HashSet <object> seen, Queue <object> toProcess) { foreach (MemoryTracker.ChildReference current in MemoryTracker.GetAllReferencedClassesFromClassOrStruct(null, MemoryTracker.GetFields(type, BindingFlags.Static), null, type.ToString() + ".")) { if (!current.child.GetType().IsClass) { throw new ApplicationException(); } MemoryTracker.ReferenceData referenceData = null; if (!references.TryGetValue(current.child, out referenceData)) { referenceData = new MemoryTracker.ReferenceData(); referenceData.path = current.path; referenceData.pathCost = 0; references[current.child] = referenceData; } if (!seen.Contains(current.child)) { seen.Add(current.child); toProcess.Enqueue(current.child); } } }
private static IEnumerable <ChildReference> DistillChildReferencesFromObject(object current, object parent, string currentPath) { Type type = current.GetType(); if (type.IsClass) { yield return(new ChildReference { child = current, path = currentPath }); /*Error: Unable to find new state assignment for yield return*/; } if (!type.IsPrimitive) { if (!type.IsValueType) { throw new NotImplementedException(); } string structPath = currentPath + "."; using (IEnumerator <ChildReference> enumerator = MemoryTracker.GetAllReferencedClassesFromClassOrStruct(current, MemoryTracker.GetFieldsFromHierarchy(type, BindingFlags.Instance), parent, structPath).GetEnumerator()) { if (enumerator.MoveNext()) { ChildReference childReference = enumerator.Current; yield return(childReference); /*Error: Unable to find new state assignment for yield return*/; } } } yield break; IL_017e: /*Error near IL_017f: Unexpected return in MoveNext()*/; }