private static void AddCapturedLocalVariables(List <DebugLocalVariableInfo> vars, int scopeStartOffset, int scopeEndOffset, ValueGetter getCaptureClass, DebugType captureClassType) { if (captureClassType.IsDisplayClass || captureClassType.IsYieldEnumerator) { foreach (DebugFieldInfo fieldInfo in captureClassType.GetFields()) { DebugFieldInfo fieldInfoCopy = fieldInfo; if (fieldInfo.Name.StartsWith("CS$")) { continue; // Ignore } DebugLocalVariableInfo locVar = new DebugLocalVariableInfo( fieldInfo.Name, -1, scopeStartOffset, scopeEndOffset, (DebugType)fieldInfo.FieldType, delegate(StackFrame context) { return(getCaptureClass(context).GetFieldValue(fieldInfoCopy)); } ); locVar.IsCaptured = true; if (locVar.Name.StartsWith("<>")) { bool hasThis = false; foreach (DebugLocalVariableInfo l in vars) { if (l.IsThis) { hasThis = true; break; } } if (!hasThis && locVar.Name.EndsWith("__this")) { locVar.Name = "this"; locVar.IsThis = true; } else { continue; // Ignore } } if (locVar.Name.StartsWith("<")) { int endIndex = locVar.Name.IndexOf('>'); if (endIndex == -1) { continue; // Ignore } locVar.Name = fieldInfo.Name.Substring(1, endIndex - 1); } vars.Add(locVar); } } }
public Expression[] AppendObjectMembers(DebugType type, BindingFlags bindingFlags) { List <Expression> members = new List <Expression>(); foreach (FieldInfo field in type.GetFields(bindingFlags)) { members.Add(this.AppendFieldReference(field)); } foreach (PropertyInfo property in type.GetProperties(bindingFlags)) { members.Add(this.AppendPropertyReference(property)); } members.Sort(); return(members.ToArray()); }
IEnumerable <NamedValue> GetObjectMembersEnum(DebugType type, BindingFlags bindingFlags) { DebugType currentType = type ?? this.Type; while (currentType != null) { foreach (FieldInfo field in currentType.GetFields(bindingFlags)) { yield return(field.GetValue(this)); } foreach (PropertyInfo property in currentType.GetProperties(bindingFlags)) { yield return(property.GetValue(this)); } if (type == null) { currentType = currentType.BaseType; } else { yield break; } } }