当前位置: 首页>>代码示例>>C#>>正文


C# Exception.?.GetType方法代码示例

本文整理汇总了C#中System.Exception.?.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.?.GetType方法的具体用法?C# Exception.?.GetType怎么用?C# Exception.?.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Exception的用法示例。


在下文中一共展示了Exception.?.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToError

 private static Error ToError(Exception exception)
 {
     var type = exception?.GetType().FullName ?? "Unknown";
     var message = exception?.Message ?? "Unknown error.";
     //var dictionary = exception?.Data.Cast<DictionaryEntry>().Where(x => x.Value != null).ToDictionary(item => item.Key.ToString(), item => item.Value.ToString());
     var a = new Error
     {
         Code = 1,
         Type = type,
         Message = message.Replace(Environment.NewLine, " "),
         //Data = dictionary,
     };
     return a;
 }
开发者ID:Quilt4,项目名称:Quilt4.Service,代码行数:14,代码来源:ExceptionHandlingAttribute.cs

示例2: ExceptionModel

 public ExceptionModel(Exception exception, int number)
 {
     Number = number;
     _exception = exception;
     Properties = new List<ExceptionProperty>();
     if (exception == null) return;
     Properties.Add(new ExceptionProperty("Type", exception.GetType()));
     Properties.AddRange(exception?.GetType().GetProperties()
         .Where(x => x.Name != nameof(Exception.Data) && 
             x.Name != nameof(Exception.InnerException) &&
             x.Name != nameof(Exception.HResult))
         .Select(x => new ExceptionProperty(x.Name, 
             x.GetValue(exception)))
         .OrderBy(x => x.Name));
 }
开发者ID:mikeobrien,项目名称:NLog.Mustache,代码行数:15,代码来源:ExceptionModel.cs

示例3: Rethrowing

 public bool Rethrowing(Exception exception)
 {
     if (IsErrorEnabled)
     {
         var msg = $"Rethrowing an exception of type '{exception?.GetType()?.FullName ?? UndefinedExceptionType}'";
         WriteInternal(LogLevel.Error, msg, exception);
     }
     return DoNotFilterException;
 }
开发者ID:finsaspa,项目名称:Caravan,代码行数:9,代码来源:CaravanLogger.cs

示例4: Throwing

 public void Throwing(Exception exception)
 {
     if (IsErrorEnabled)
     {
         var msg = $"Throwing an exception of type '{exception?.GetType()?.FullName ?? UndefinedExceptionType}'";
         WriteInternal(LogLevel.Error, msg, exception);
     }
 }
开发者ID:finsaspa,项目名称:Caravan,代码行数:8,代码来源:CaravanLogger.cs

示例5: ExceptionEquals

 private static bool ExceptionEquals(Exception a, Exception b)
 {
     return a?.GetType() == b?.GetType() &&
            a?.Message == b?.Message;
 }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:5,代码来源:BindingNotification.cs

示例6: Command_Display_Error

		private DialogResult Command_Display_Error(string tryingToDoWhat, string objectsThatFailed = null, Exception ex = null,
			string message = null) {
			//TODO: Better error dialog
			var errorType = "";
			if (ex is PatchException) {
				errorType = "A patch was invalid, incompatible, or caused an error.";
			} else if (ex is IOException) {
				errorType = "Related to reading/writing files.";
			} else if (ex is ApplicationException) {
				errorType = "An application error.";
			} else if (ex != null) {
				errorType = "A system error or some sort of bug.";
			}
			var errorString = "An error has occurred,\r\n";
			errorString += tryingToDoWhat.IsNullOrWhitespace() ? "" : $"While trying to: {tryingToDoWhat}\r\n";
			errorString += errorType.IsNullOrWhitespace() ? "" : $"Error type: {errorType} ({ex?.GetType().Name})\r\n";
			errorString += ex == null ? "" : $"Internal message: {ex.Message}\r\n";
			errorString += objectsThatFailed.IsNullOrWhitespace() ? "" : $"Object(s) that failed: {objectsThatFailed}\r\n";
			errorString += message.IsNullOrWhitespace() ? "" : $"{message}\r\n";
			Logger.Error(ex, errorString);
			return MessageBox.Show(errorString, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
		}
开发者ID:GregRos,项目名称:Patchwork,代码行数:22,代码来源:LaunchManager.cs


注:本文中的System.Exception.?.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。