コード例 #1
0
        private void InitializeEnumerableHeaderOnly(string?headerPrefix, IEnumerable e)
        {
            Header = headerPrefix;

            try
            {
                var count      = 0;
                var enumerator = e.GetEnumerator();
                using (enumerator as IDisposable)
                {
                    while (count < _quotas.MaxEnumerableLength && enumerator.MoveNext())
                    {
                        ++count;
                    }
                    var hasMore = enumerator.MoveNext() ? "+" : "";
                    Value = $"<enumerable Count: {count}{hasMore}>";
                }
            }
            catch (Exception exception)
            {
                Header   = _member?.Name;
                Value    = $"Threw {exception.GetType().Name}";
                Children = new List <ResultObject> {
                    ExceptionResultObject.Create(exception, _quotas)
                };
            }
        }
コード例 #2
0
        private bool TryPopulateMember(object?o, DumpQuotas targetQuotas)
        {
            if (_member == null)
            {
                return(false);
            }

            object?value;

            try
            {
                if (o is Exception exception)
                {
                    if (_member.Name == nameof(Exception.StackTrace))
                    {
                        value = GetStackTrace(exception);
                    }
                    else
                    {
                        value = GetMemberValue(o);

                        if (_member.Name == "TargetSite")
                        {
                            targetQuotas = targetQuotas.WithMaxDepth(0);
                        }
                    }
                }
                else
                {
                    value = GetMemberValue(o);
                }
            }
            catch (TargetInvocationException exception)
            {
                Header = _member.Name;
                // ReSharper disable once PossibleNullReferenceException
                Value    = $"Threw {exception.InnerException.GetType().Name}";
                Children = new List <ResultObject> {
                    ExceptionResultObject.Create(exception.InnerException, _quotas)
                };
                return(true);
            }

            if (value == null)
            {
                if (_member is PropertyInfo propertyInfo)
                {
                    SetType(propertyInfo.PropertyType);
                }
                else if (_member is FieldInfo fieldInfo)
                {
                    SetType(fieldInfo.FieldType);
                }
            }

            PopulateObject(value, _member.Name, targetQuotas);
            return(true);
        }
コード例 #3
0
        private void InitializeEnumerable(string?headerPrefix, IEnumerable e, DumpQuotas targetQuotas)
        {
            try
            {
                Header = headerPrefix;

                var items = new List <ResultObject>();

                var type = e.GetType().GetTypeInfo();

                var enumerableInterface = type.ImplementedInterfaces
                                          .FirstOrDefault(x => x.IsConstructedGenericType && x.GetGenericTypeDefinition() == typeof(IEnumerable <>));
                var enumerableType     = enumerableInterface?.GenericTypeArguments[0] ?? typeof(object);
                var enumerableTypeName = GetTypeName(enumerableType);

                var enumerator = e.GetEnumerator();
                using (enumerator as IDisposable)
                {
                    var index = 0;
                    while (index < _quotas.MaxEnumerableLength && enumerator.MoveNext())
                    {
                        var item = new ResultObject(enumerator.Current, targetQuotas, $"[{index}]");
                        if (item.Type == null)
                        {
                            item.Type = enumerableTypeName;
                        }
                        items.Add(item);
                        ++index;
                    }

                    var hasMore           = enumerator.MoveNext() ? "+" : "";
                    var groupingInterface = type.ImplementedInterfaces
                                            .FirstOrDefault(x => x.IsConstructedGenericType &&
                                                            x.GetGenericTypeDefinition() == typeof(IGrouping <,>));
                    Value = groupingInterface != null
                        ? $"<grouping Count: {items.Count}{hasMore} Key: {groupingInterface.GetRuntimeProperty("Key").GetValue(e)}>"
                        : $"<enumerable Count: {items.Count}{hasMore}>";
                    Children = items;
                }
            }
            catch (Exception exception)
            {
                Header   = _member?.Name;
                Value    = $"Threw {exception.GetType().Name}";
                Children = new List <ResultObject> {
                    ExceptionResultObject.Create(exception, _quotas)
                };
            }
        }
コード例 #4
0
ファイル: ConsoleDumper.cs プロジェクト: hthubert/MyRoslynPad
 private void DumpExceptionResultObject(ExceptionResultObject result)
 {
     using (var jsonWriter = CreateJsonWriter()) {
         jsonWriter.WriteStartElement("root", "");
         jsonWriter.WriteAttributeString("type", "object");
         jsonWriter.WriteElementString("$type", _exceptionResultTypeName);
         jsonWriter.WriteElementString("m", result.Message);
         jsonWriter.WriteStartElement("l");
         jsonWriter.WriteValue(result.LineNumber);
         jsonWriter.WriteEndElement();
         WriteResultObjectContent(jsonWriter, result);
         jsonWriter.WriteEndElement();
     }
     DumpJsonData();
     DumpNewLine();
 }
コード例 #5
0
ファイル: ConsoleDumper.cs プロジェクト: hthubert/MyRoslynPad
        public void DumpException(Exception exception)
        {
            if (!CanDump())
            {
                return;
            }

            try {
                DumpExceptionResultObject(ExceptionResultObject.Create(exception));
            }
            catch (Exception ex) {
                try {
                    DumpMessage("Error during Dump: " + ex.Message);
                }
                catch {
                    // ignore
                }
            }
        }