Add migrated to .NET 8.0 variant of Hcs.Client
This commit is contained in:
63
Hcs.ClientNet/Client/Internal/Util.cs
Normal file
63
Hcs.ClientNet/Client/Internal/Util.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Hcs.ClientNet.Internal
|
||||
{
|
||||
internal static class Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Возвращает список все вложенных исключений для данного исключения
|
||||
/// </summary>
|
||||
internal static List<Exception> EnumerateInnerExceptions(Exception e)
|
||||
{
|
||||
var list = new List<Exception>();
|
||||
WalkInnerExceptionsRecurse(e, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void WalkInnerExceptionsRecurse(Exception e, List<Exception> list)
|
||||
{
|
||||
if (e == null || list.Contains(e))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
list.Add(e);
|
||||
|
||||
WalkInnerExceptionsRecurse(e.InnerException, list);
|
||||
|
||||
if (e is AggregateException)
|
||||
{
|
||||
var aggregate = e as AggregateException;
|
||||
foreach (var inner in aggregate.InnerExceptions)
|
||||
{
|
||||
WalkInnerExceptionsRecurse(inner, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static string FormatDate(DateTime date)
|
||||
{
|
||||
return date.ToString("yyyyMMdd");
|
||||
}
|
||||
|
||||
internal static string FormatDate(DateTime? date)
|
||||
{
|
||||
return (date == null) ? string.Empty : FormatDate((DateTime)date);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Преобразует массиб байтов в строку в формате binhex
|
||||
/// </summary>
|
||||
internal static string ConvertToHexString(byte[] ba)
|
||||
{
|
||||
var buf = new StringBuilder(ba.Length * 2);
|
||||
foreach (byte b in ba)
|
||||
{
|
||||
buf.AppendFormat("{0:x2}", b);
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user