Skip to content

Commit

Permalink
publish 1.0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nameofSEOKWONHONG committed May 9, 2024
1 parent f7553bc commit 3969341
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 216 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Refer to the test code for how to use it.
net7, net8

## Version
* 1.0.0.9
* remove - xForEach: remove thread.sleep
* remove - xForEach: remove number type from to xforeach, use Enumerable.Range(from, to)
* modify - xForEach: change xforeach func item priority. (int Index, Generic T Item)
* remove - XHttpExtension
* add - xToDayOfWeek : day of week name (base by cultureinfo)
* etc - XFileExtension change huge naming.
* caution - xForEach can happen object null exception.
case 1 : use AOT, happen exception after serialize object.

* 1.0.0.8
* add - xToDictionary(this DataTable datatable) return IDictionary<string, object?>
* add - xToDate(this DateTime dt, string format, CultureInfo culture) return string
Expand Down
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMajor",
"allowPrerelease": false
}
}
69 changes: 35 additions & 34 deletions src/DataType/XEnumBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace eXtensionSharp
/// </code>
/// </example>
/// <typeparam name="T">The string-valued enum type. (i.e. class Color : StringEnum&lt;Color&gt;)</typeparam>
[Obsolete("don't use", true)]
public abstract class XEnumBase<T> : IEquatable<T> where T : XEnumBase<T>, new()
{
private static readonly Dictionary<string, T> valueDict = new();
Expand Down Expand Up @@ -122,38 +123,38 @@ public static T TryParse(string value, bool caseSensitive = true)
}
}

public class XEnumBaseTypeConverter<T> : TypeConverter where T : XEnumBase<T>, new()
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
return XEnumBase<T>.Parse((string)value);
}
return base.ConvertFrom(context, culture, value);
}
}

public class XEnumBaseJsonConverter<T> : JsonConverter<T> where T : XEnumBase<T>, new()
{
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var s = reader.GetString();
return XEnumBase<T>.Parse(s);
}

public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
// public class XEnumBaseTypeConverter<T> : TypeConverter where T : XEnumBase<T>, new()
// {
// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
// {
// if (sourceType == typeof(string))
// {
// return true;
// }
// return base.CanConvertFrom(context, sourceType);
// }
//
// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
// {
// if (value is string)
// {
// return XEnumBase<T>.Parse((string)value);
// }
// return base.ConvertFrom(context, culture, value);
// }
// }
//
// public class XEnumBaseJsonConverter<T> : JsonConverter<T> where T : XEnumBase<T>, new()
// {
// public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
// {
// var s = reader.GetString();
// return XEnumBase<T>.Parse(s);
// }
//
// public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
// {
// writer.WriteStringValue(value.ToString());
// }
// }
}
1 change: 1 addition & 0 deletions src/DataType/XEnumString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace eXtensionSharp
/// <summary>
/// enum string class, use attribute
/// </summary>
[Obsolete("don't use", true)]
public class XEnumString
{
#region Instance implementation
Expand Down
38 changes: 22 additions & 16 deletions src/XDateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static DateTime xToDate(this string date)
return datetime;
}

public static string xToDate(this DateTime date, ENUM_DATE_FORMAT format = null)
public static string xToDate(this DateTime date, string format = null)
{
if (format.xIsEmpty()) format = ENUM_DATE_FORMAT.YYYY_MM_DD;
if (format.xIsEmpty()) format = "yyyy-MM-dd";
return date.ToString(format);
}

Expand Down Expand Up @@ -239,6 +239,12 @@ public static bool xTryDateParse(this string date, string format, out DateTime d
{
return DateTime.TryParseExact(date, format, null, DateTimeStyles.None, out dateTime);
}

public static string xToDayOfWeek(this DateTime date, string culture = null)
{
if (culture.xIsEmpty()) culture = CultureInfo.CurrentCulture.Name;
return date.ToString("dddd", new CultureInfo(culture));
}
}

// public static class WeekHelper {
Expand Down Expand Up @@ -312,18 +318,18 @@ public static bool xTryDateParse(this string date, string format, out DateTime d
/// <summary>
/// datetime format from korea.
/// </summary>
public class ENUM_DATE_FORMAT : XEnumBase<ENUM_DATE_FORMAT>
{
public static readonly ENUM_DATE_FORMAT YYYY_MM_DD = Define("yyyy-MM-dd");
public static readonly ENUM_DATE_FORMAT YYYY_MM = Define("yyyy-MM");
public static readonly ENUM_DATE_FORMAT YYYY_MM_DD_HH_MM_SS = Define("yyyy-MM-dd HH:mm:ss");
public static readonly ENUM_DATE_FORMAT YYYY_MM_DD_HH_MM_SS_FFF = Define("yyyy-MM-dd HH:mm:ss.fff");
public static readonly ENUM_DATE_FORMAT YYYYMMDD = Define("yyyyMMdd");
public static readonly ENUM_DATE_FORMAT YYYYMM = Define("yyyyMM");
public static readonly ENUM_DATE_FORMAT YYYY_FS_MM_FS_DD = Define("yyyy/MM/dd");
public static readonly ENUM_DATE_FORMAT YYYYMMDDHHMMSS = Define("yyyyMMddHHmmss");
public static readonly ENUM_DATE_FORMAT YYYYMMDDHH = Define("yyyyMMddHH");
public static readonly ENUM_DATE_FORMAT HHMMSS = Define("HHmmss");
public static readonly ENUM_DATE_FORMAT YYMMDD = Define("yyMMdd");
}
// public class ENUM_DATE_FORMAT : ENUM_DATE_FORMAT
// {
// public static readonly ENUM_DATE_FORMAT YYYY_MM_DD = Define("yyyy-MM-dd");
// public static readonly ENUM_DATE_FORMAT YYYY_MM = Define("yyyy-MM");
// public static readonly ENUM_DATE_FORMAT YYYY_MM_DD_HH_MM_SS = Define("yyyy-MM-dd HH:mm:ss");
// public static readonly ENUM_DATE_FORMAT YYYY_MM_DD_HH_MM_SS_FFF = Define("yyyy-MM-dd HH:mm:ss.fff");
// public static readonly ENUM_DATE_FORMAT YYYYMMDD = Define("yyyyMMdd");
// public static readonly ENUM_DATE_FORMAT YYYYMM = Define("yyyyMM");
// public static readonly ENUM_DATE_FORMAT YYYY_FS_MM_FS_DD = Define("yyyy/MM/dd");
// public static readonly ENUM_DATE_FORMAT YYYYMMDDHHMMSS = Define("yyyyMMddHHmmss");
// public static readonly ENUM_DATE_FORMAT YYYYMMDDHH = Define("yyyyMMddHH");
// public static readonly ENUM_DATE_FORMAT HHMMSS = Define("HHmmss");
// public static readonly ENUM_DATE_FORMAT YYMMDD = Define("yyMMdd");
// }
}
9 changes: 4 additions & 5 deletions src/XFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace eXtensionSharp
public static class XFileExtensions
{
/// <summary>
/// 파일명 조회
/// ���ϸ� ��ȸ
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string xGetFileName(this string fileName) => Path.GetFileName(fileName);

/// <summary>
/// 파일명 조회 (확장자 없이)
/// ���ϸ� ��ȸ (Ȯ���� ����)
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string xGetFileNameWithoutExtension(this string fileName) => Path.GetFileNameWithoutExtension(fileName);

/// <summary>
/// 파일 확장자 조회
/// ���� Ȯ���� ��ȸ
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
Expand Down Expand Up @@ -105,7 +105,7 @@ public static string xUniqueId(this FileInfo fileInfo)
{
if (!fileInfo.Exists.xIsFalse()) return string.Empty;
return
$"{fileInfo.FullName}|{fileInfo.CreationTime.xToDate(ENUM_DATE_FORMAT.YYYY_MM_DD_HH_MM_SS)}|{fileInfo.LastWriteTime.xToDate(ENUM_DATE_FORMAT.YYYY_MM_DD_HH_MM_SS)}"
$"{fileInfo.FullName}|{fileInfo.CreationTime.xToDate("yyyy-MM-dd HH:mm:ss")}|{fileInfo.LastWriteTime.xToDate("yyyy-MM-dd HH:mm:ss")}"
.xGetHashCode();
}

Expand Down Expand Up @@ -316,7 +316,6 @@ private static Dictionary<string, IEnumerable<string>> SearchFiles(string direct
string[] subdirectories = Directory.GetDirectories(directory);
foreach (string subdir in subdirectories)
{
// 재귀적으로 하위 디렉토리에서 파일 검색
var subdirectoryFiles = SearchFiles(subdir);
foreach (var kvp in subdirectoryFiles)
{
Expand Down
Loading

0 comments on commit 3969341

Please sign in to comment.