/// <summary> /// 字符串 /// </summary> /// <returns>字符串</returns> public override string ToString() { if (toString == null) { list <string> .unsafer errorString = new list <string>(2).Unsafer; if (Message != null) { errorString.Add("附加信息 : " + Message); } if (StackFrame != null) { errorString.Add("堆栈帧信息 : " + StackFrame.toString()); } if (StackTrace != null) { errorString.Add("堆栈信息 : " + StackTrace.ToString()); } if (Exception != null) { errorString.Add("异常信息 : " + Exception.ToString()); } if (Type != exceptionType.None) { errorString.Add("异常类型 : " + Type.ToString()); } toString = errorString[0] + @" " + errorString[1]; } return(toString); }
/// <summary> /// 字符串 /// </summary> /// <returns>字符串</returns> public override string ToString() { if (toString == null) { string stackFrameMethodTypeName = null, stackFrameMethodString = null, stackFrameFile = null, stackFrameLine = null, stackFrameColumn = null; if (StackFrame != null) { MethodBase stackFrameMethod = StackFrame.GetMethod(); if (stackFrameMethod == null) { StackFrame = null; if (StackTrace == null) { StackTrace = new StackTrace(true); } } else { stackFrameMethodTypeName = stackFrameMethod.ReflectedType.FullName; stackFrameMethodString = stackFrameMethod.ToString(); stackFrameFile = StackFrame.GetFileName(); if (stackFrameFile != null) { stackFrameLine = StackFrame.GetFileLineNumber().toString(); stackFrameColumn = StackFrame.GetFileColumnNumber().toString(); } } } string stackTrace = StackTrace == null ? null : StackTrace.ToString(); string exception = Exception == null ? null : Exception.ToString(); Monitor.Enter(toStringStreamLock); try { if (Message != null) { toStringStream.SimpleWriteNotNull(@" 附加信息 : "); toStringStream.WriteNotNull(Message); } if (StackFrame != null) { toStringStream.Write(@" 堆栈帧信息 : "); toStringStream.WriteNotNull(stackFrameMethodTypeName); toStringStream.SimpleWriteNotNull(" + "); toStringStream.WriteNotNull(stackFrameMethodString); if (stackFrameFile != null) { toStringStream.SimpleWriteNotNull(" in "); toStringStream.WriteNotNull(stackFrameFile); toStringStream.SimpleWriteNotNull(" line "); toStringStream.SimpleWriteNotNull(stackFrameLine); toStringStream.SimpleWriteNotNull(" col "); toStringStream.SimpleWriteNotNull(stackFrameColumn); } } if (stackTrace != null) { toStringStream.SimpleWriteNotNull(@" 堆栈信息 : "); toStringStream.WriteNotNull(stackTrace); } if (exception != null) { toStringStream.SimpleWriteNotNull(@" 异常信息 : "); toStringStream.WriteNotNull(exception); } if (Type != exceptionType.None) { toStringStream.SimpleWriteNotNull("异常类型 : "); toStringStream.SimpleWriteNotNull(Type.ToString()); } toString = toStringStream.ToString(); } finally { toStringStream.Clear(); Monitor.Exit(toStringStreamLock); } } return(toString); }