Skip to content

Commit

Permalink
代码清理
Browse files Browse the repository at this point in the history
  • Loading branch information
alexinea committed Dec 6, 2022
1 parent 6de1efb commit bde437d
Show file tree
Hide file tree
Showing 26 changed files with 259 additions and 257 deletions.
31 changes: 4 additions & 27 deletions src/Cosmos.Core/Cosmos/ByteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Cosmos;
/// </summary>
public static class ByteExtensions
{
#region Min & Max

/// <summary>
/// Gets max one. <br />
/// 获取大值。
Expand All @@ -26,37 +24,16 @@ public static class ByteExtensions
/// <returns></returns>
public static byte Min(this byte val1, byte val2) => Math.Min(val1, val2);

#endregion

#region Resize

/// <summary>
/// Resize <br />
/// 重新设置尺寸
/// </summary>
/// <param name="this"></param>
/// <param name="buff"></param>
/// <param name="newSize"></param>
/// <returns></returns>
public static byte[] Resize(this byte[] @this, int newSize)
{
Array.Resize(ref @this, newSize);
return @this;
}

#endregion

#region To MemoryStream

/// <summary>
/// Convert byte[] to <see cref="MemoryStream"/> <br />
/// 转换类型,将 <see cref="byte"/>[] 转换为 <see cref="MemoryStream"/>
/// </summary>
/// <param name="this"></param>
/// <returns></returns>
public static MemoryStream ToMemoryStream(this byte[] @this)
public static byte[] Resize(this byte[] buff, int newSize)
{
return new MemoryStream(@this);
Array.Resize(ref buff, newSize);
return buff;
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,9 @@
namespace Cosmos.Date;

/// <summary>
/// Datetime Output Styles <br />
/// 时间输出风格
/// </summary>
public enum DateTimeOutputStyles
{
/// <summary>
/// DateTime
/// </summary>
DateTime,

/// <summary>
/// Date
/// </summary>
Date,

/// <summary>
/// Time
/// </summary>
Time,

/// <summary>
/// LongDate
/// </summary>
LongDate,

/// <summary>
/// LongTime
/// </summary>
LongTime,

/// <summary>
/// ShortDate
/// </summary>
ShortDate,

/// <summary>
/// ShortTime
/// </summary>
ShortTime,

/// <summary>
/// Millisecond
/// </summary>
Millisecond,
}

/// <summary>
/// DateTime Helper (internal)
/// </summary>
internal static class DateTimeHelper
internal static class DateTimeOutputHelper
{
/// <summary>
/// If this then that...
Expand All @@ -70,7 +23,7 @@ public static string Ifttt(bool condition, string format1, string format2)
/// DateTime to String extensions <br />
/// DateTime 转换为 String 的扩展
/// </summary>
public static class DateTimeToStringExtensions
public static class DateTimeOutputExtensions
{
/// <summary>
/// Convert DateTime value to String. <br />
Expand All @@ -84,9 +37,9 @@ public static string ToString(this DateTime dt, DateTimeOutputStyles styles, boo
{
return styles switch
{
DateTimeOutputStyles.DateTime => dt.ToString(DateTimeHelper.Ifttt(isRemoveSecond, "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH:mm:ss")),
DateTimeOutputStyles.DateTime => dt.ToString(DateTimeOutputHelper.Ifttt(isRemoveSecond, "yyyy-MM-dd HH:mm", "yyyy-MM-dd HH:mm:ss")),
DateTimeOutputStyles.Date => dt.ToString("yyyy-MM-dd"),
DateTimeOutputStyles.Time => dt.ToString(DateTimeHelper.Ifttt(isRemoveSecond, "HH:mm", "HH:mm:ss")),
DateTimeOutputStyles.Time => dt.ToString(DateTimeOutputHelper.Ifttt(isRemoveSecond, "HH:mm", "HH:mm:ss")),
DateTimeOutputStyles.LongDate => dt.ToLongDateString(),
DateTimeOutputStyles.LongTime => dt.ToLongTimeString(),
DateTimeOutputStyles.ShortDate => dt.ToShortDateString(),
Expand Down
48 changes: 48 additions & 0 deletions src/Cosmos.Core/Cosmos/Date/DateTimeOutputStyles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Cosmos.Date;

/// <summary>
/// Datetime Output Styles <br />
/// 时间输出风格
/// </summary>
public enum DateTimeOutputStyles
{
/// <summary>
/// DateTime
/// </summary>
DateTime,

/// <summary>
/// Date
/// </summary>
Date,

/// <summary>
/// Time
/// </summary>
Time,

/// <summary>
/// LongDate
/// </summary>
LongDate,

/// <summary>
/// LongTime
/// </summary>
LongTime,

/// <summary>
/// ShortDate
/// </summary>
ShortDate,

/// <summary>
/// ShortTime
/// </summary>
ShortTime,

/// <summary>
/// Millisecond
/// </summary>
Millisecond,
}
4 changes: 2 additions & 2 deletions src/Cosmos.Core/Cosmos/Date/TimeStamp.UnixTimeStamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ private UnixTimeStamp(DateTime dt, long timestamp)
(time.ToUniversalTime().Ticks - 621355968000000000) / 10000000;

private static readonly Func<long, DateTime> FromUnixTimestampFunc = timestamp =>
(TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local))
.Add(new TimeSpan(long.Parse(timestamp + "0000000")));
TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local)
.Add(new TimeSpan(long.Parse(timestamp + "0000000")));

/// <summary>
/// Gets a func for unix now.
Expand Down
34 changes: 22 additions & 12 deletions src/Cosmos.Core/Cosmos/Exceptions/Try.Create.Future.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static partial class Try
/// <typeparam name="T2"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T> CreateFuture<T1, T2, T>(Func<T1, T2, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T> CreateFuture<T1, T2, T>(
Func<T1, T2, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -50,7 +51,8 @@ public static partial class Try
/// <typeparam name="T3"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T> CreateFuture<T1, T2, T3, T>(Func<T1, T2, T3, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T> CreateFuture<T1, T2, T3, T>(
Func<T1, T2, T3, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -63,7 +65,8 @@ public static partial class Try
/// <typeparam name="T4"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T> CreateFuture<T1, T2, T3, T4, T>(Func<T1, T2, T3, T4, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T> CreateFuture<T1, T2, T3, T4, T>(
Func<T1, T2, T3, T4, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -77,7 +80,8 @@ public static partial class Try
/// <typeparam name="T5"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T> CreateFuture<T1, T2, T3, T4, T5, T>(Func<T1, T2, T3, T4, T5, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T> CreateFuture<T1, T2, T3, T4, T5, T>(
Func<T1, T2, T3, T4, T5, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -92,7 +96,8 @@ public static partial class Try
/// <typeparam name="T6"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T> CreateFuture<T1, T2, T3, T4, T5, T6, T>(Func<T1, T2, T3, T4, T5, T6, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T> CreateFuture<T1, T2, T3, T4, T5, T6, T>(
Func<T1, T2, T3, T4, T5, T6, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -108,7 +113,8 @@ public static partial class Try
/// <typeparam name="T7"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T>(Func<T1, T2, T3, T4, T5, T6, T7, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T>(
Func<T1, T2, T3, T4, T5, T6, T7, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -125,7 +131,8 @@ public static partial class Try
/// <typeparam name="T8"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T>(
Func<T1, T2, T3, T4, T5, T6, T7, T8, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -143,7 +150,8 @@ public static partial class Try
/// <typeparam name="T9"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T>(
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -162,7 +170,8 @@ public static partial class Try
/// <typeparam name="T10"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T>(
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -182,7 +191,8 @@ public static partial class Try
/// <typeparam name="T11"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T> createFunction) => new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T>(
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand All @@ -203,8 +213,8 @@ public static partial class Try
/// <typeparam name="T12"></typeparam>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T>(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T> createFunction) =>
new(createFunction);
public static FutureCreatingBuilder<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T> CreateFuture<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T>(
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T> createFunction) => new(createFunction);

/// <summary>
/// Create a new instance of <see cref="Try{TResult}"/> in the future. <br />
Expand Down
Loading

0 comments on commit bde437d

Please sign in to comment.