示例#1
0
        private static IEnumerable <ExceptionEntry> FromMethodBase(MethodBase source)
        {
            if (source is null)
            {
                return(null);
            }

            return(ExceptionEntry.FromAssignments(ExceptionEntry.GetProperties(source)));
        }
示例#2
0
        public static IEnumerable <ExceptionEntry> FromException(Exception source)
        {
            if (source is null)
            {
                return(null);
            }

            try
            {
                return(ExceptionEntry.FromAssignments(ExceptionEntry.GetProperties(source)));
            }
            catch (Exception error)
            {
                System.Diagnostics.Debug.WriteLine(error);
                return(null);
            }
        }
示例#3
0
        public ExceptionEntry(String name, Object value, Type type)
        {
            this.Name  = (name ?? ExceptionEntry.Null).ToString();
            this.Value = (value ?? ExceptionEntry.Null);
            this.Type  = type;

            if (value is Int32 && this.Name.Equals(nameof(Exception.HResult)))
            {
                this.Value = $"{((Int32)value).ToString()} (0x{((Int32)value).ToString("X8")})";
                return;
            }

            if (value is Exception)
            {
                this.Elements = ExceptionEntry.FromException(value as Exception);
                return;
            }

            if (value is IDictionary)
            {
                this.Elements = ExceptionEntry.FromDictionary(value as IDictionary);
                return;
            }

            if (value is MethodBase)
            {
                this.Elements = ExceptionEntry.FromMethodBase(value as MethodBase);
                return;
            }

            if (this.Name.Equals(nameof(MethodBase.CustomAttributes)))
            {
                // It doesn't really make any sense to resolve all those custom attributes.
                IEnumerable <CustomAttributeData> helper = (value as IEnumerable <CustomAttributeData>);
                this.Value = $"Count = {(helper is null ? ExceptionEntry.Null : helper.Count().ToString())}";
                return;
            }
        }