void SafeReadMembers() { var propertyNames = new HashSet <string> (); var members = new List <Tuple <RepresentedMemberInfo, object> > (); for (var type = RepresentedType; type != null; type = type.BaseType) { foreach (var memberItem in type.ProxyableMembers) { var pi = memberItem.Value.ResolvedMemberInfo as PropertyInfo; if (pi != null) { if (propertyNames.Contains(pi.Name)) { continue; } propertyNames.Add(pi.Name); } object value; try { if (memberFilter != null && !memberFilter(memberItem.Value, representedObject)) { value = new GetMemberValueError(); } else { value = memberItem.Value.GetValue(representedObject); } } catch (TargetInvocationException e) { value = new GetMemberValueError(e.InnerException); } catch (Exception e) { value = new GetMemberValueError(e); } var preparedValue = new RepresentedObject(value?.GetType()); ItemPreparer(preparedValue, Depth + 1, value); if (preparedValue.Count == 0) { preparedValue = null; } members.Add(Tuple.Create(memberItem.Value, (object)preparedValue)); } } members.Sort((x, y) => string.Compare(x.Item1.Name, y.Item1.Name)); Members = new RepresentedMemberInfo [members.Count]; Values = new object [members.Count]; for (int i = 0; i < members.Count; i++) { Members [i] = members [i].Item1; Values [i] = members [i].Item2; } }
public void Add(MemberInfo memberInfo, object value, bool wrapAsMemberValueError = false) { if (wrapAsMemberValueError && value is Exception) { var e = (Exception)value; if (value is TargetInvocationException) { value = new GetMemberValueError(e.InnerException); } else { value = new GetMemberValueError(e); } } values.Add(Tuple.Create(new RepresentedMemberInfo(memberInfo), value)); }