-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from I-RzR-I/feature/17-10-23-AddNewExtensions
Add IDataReader extensions.
- Loading branch information
Showing
14 changed files
with
737 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/DomainCommonExtensions/ConvertExtensions/DataReader/ToBoolExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// *********************************************************************** | ||
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions | ||
// Author : RzR | ||
// Created On : 2023-10-18 09:00 | ||
// | ||
// Last Modified By : RzR | ||
// Last Modified On : 2023-10-18 09:05 | ||
// *********************************************************************** | ||
// <copyright file="ToBoolExtensions.cs" company=""> | ||
// Copyright (c) RzR. All rights reserved. | ||
// </copyright> | ||
// | ||
// <summary> | ||
// </summary> | ||
// *********************************************************************** | ||
|
||
#region U S A G E S | ||
|
||
using System.Data; | ||
using DomainCommonExtensions.CommonExtensions.SystemData; | ||
|
||
#endregion | ||
|
||
namespace DomainCommonExtensions.ConvertExtensions.DataReader | ||
{ | ||
/// <summary> | ||
/// DataReader to bool extensions | ||
/// </summary> | ||
public static class ToBoolExtensions | ||
{ | ||
/// <summary> | ||
/// Convert to bool from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static bool ToBool(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
&& bool.Parse(dataReader[columnName].ToString()); | ||
|
||
/// <summary> | ||
/// Convert to nullable bool from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static bool? ToNullBool(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? bool.Parse(dataReader[columnName].ToString()) | ||
: (bool?)null; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/DomainCommonExtensions/ConvertExtensions/DataReader/ToByteExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// *********************************************************************** | ||
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions | ||
// Author : RzR | ||
// Created On : 2023-10-18 08:52 | ||
// | ||
// Last Modified By : RzR | ||
// Last Modified On : 2023-10-18 08:58 | ||
// *********************************************************************** | ||
// <copyright file="ToByteExtensions.cs" company=""> | ||
// Copyright (c) RzR. All rights reserved. | ||
// </copyright> | ||
// | ||
// <summary> | ||
// </summary> | ||
// *********************************************************************** | ||
|
||
#region U S A G E S | ||
|
||
using System.Data; | ||
using DomainCommonExtensions.CommonExtensions.SystemData; | ||
|
||
#endregion | ||
|
||
namespace DomainCommonExtensions.ConvertExtensions.DataReader | ||
{ | ||
/// <summary> | ||
/// DataReader to byte/sbyte extensions | ||
/// </summary> | ||
public static class ToByteExtensions | ||
{ | ||
/// <summary> | ||
/// Convert to byte from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static byte ToByte(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? byte.Parse(dataReader[columnName].ToString()) | ||
: byte.MinValue; | ||
|
||
/// <summary> | ||
/// Convert to nullable byte from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static byte? ToNullByte(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? byte.Parse(dataReader[columnName].ToString()) | ||
: (byte?)null; | ||
|
||
/// <summary> | ||
/// Convert to sbyte from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static sbyte ToSByte(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? sbyte.Parse(dataReader[columnName].ToString()) | ||
: sbyte.MinValue; | ||
|
||
/// <summary> | ||
/// Convert to nullable sbyte from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static sbyte? ToNullSByte(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? sbyte.Parse(dataReader[columnName].ToString()) | ||
: (sbyte?)null; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/DomainCommonExtensions/ConvertExtensions/DataReader/ToCharExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// *********************************************************************** | ||
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions | ||
// Author : RzR | ||
// Created On : 2023-10-18 09:30 | ||
// | ||
// Last Modified By : RzR | ||
// Last Modified On : 2023-10-18 09:33 | ||
// *********************************************************************** | ||
// <copyright file="ToCharExtensions.cs" company=""> | ||
// Copyright (c) RzR. All rights reserved. | ||
// </copyright> | ||
// | ||
// <summary> | ||
// </summary> | ||
// *********************************************************************** | ||
|
||
#region U S A G E S | ||
|
||
using System.Data; | ||
using DomainCommonExtensions.CommonExtensions.SystemData; | ||
|
||
#endregion | ||
|
||
namespace DomainCommonExtensions.ConvertExtensions.DataReader | ||
{ | ||
/// <summary> | ||
/// DataReader to char extensions | ||
/// </summary> | ||
public static class ToCharExtensions | ||
{ | ||
/// <summary> | ||
/// Convert to char from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static char ToChar(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? char.Parse(dataReader[columnName].ToString()) | ||
: char.MinValue; | ||
|
||
/// <summary> | ||
/// Convert to nullable char from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns></returns> | ||
/// <remarks></remarks> | ||
public static char? ToNullChar(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? char.Parse(dataReader[columnName].ToString()) | ||
: (char?)null; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/DomainCommonExtensions/ConvertExtensions/DataReader/ToDateTimeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// *********************************************************************** | ||
// Assembly : RzR.Shared.Extensions.DomainCommonExtensions | ||
// Author : RzR | ||
// Created On : 2023-10-18 15:06 | ||
// | ||
// Last Modified By : RzR | ||
// Last Modified On : 2023-10-18 15:06 | ||
// *********************************************************************** | ||
// <copyright file="ToDateTimeExtensions.cs" company=""> | ||
// Copyright (c) RzR. All rights reserved. | ||
// </copyright> | ||
// | ||
// <summary> | ||
// </summary> | ||
// *********************************************************************** | ||
|
||
#region U S A G E S | ||
|
||
using System; | ||
using System.Data; | ||
using System.Globalization; | ||
using DomainCommonExtensions.CommonExtensions.SystemData; | ||
|
||
#endregion | ||
|
||
namespace DomainCommonExtensions.ConvertExtensions.DataReader | ||
{ | ||
/// <summary> | ||
/// DataReader to DateTime extensions | ||
/// </summary> | ||
public static class ToDateTimeExtensions | ||
{ | ||
/// <summary> | ||
/// Convert to DateTime from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns>Return converted DateTime value or DateTime.MinValue if the reader does not have value.</returns> | ||
/// <remarks></remarks> | ||
public static DateTime ToDateTime(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? Convert.ToDateTime(dataReader[columnName].ToString()) | ||
: DateTime.MinValue; | ||
|
||
/// <summary> | ||
/// Convert to nullable Guid from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns>Return converted DateTime value or NULL if the reader does not have value.</returns> | ||
/// <remarks></remarks> | ||
public static DateTime? ToNullDateTime(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? Convert.ToDateTime(dataReader[columnName].ToString()) | ||
: (DateTime?)null; | ||
|
||
/// <summary> | ||
/// DateTime.ParseExact from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <param name="format">DateTime format</param> | ||
/// <returns>Return parsed DateTime value or DateTime.MinValue if the reader does not have value.</returns> | ||
/// <remarks></remarks> | ||
public static DateTime ToDateTimeParseExact(this IDataReader dataReader, string columnName, string format) | ||
=> dataReader.IsWithValue(columnName) | ||
? DateTime.ParseExact(dataReader[columnName].ToString(), format, CultureInfo.InvariantCulture) | ||
: DateTime.MinValue; | ||
|
||
/// <summary> | ||
/// Nullable DateTime.ParseExact from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <param name="format">DateTime format</param> | ||
/// <returns>Return parsed DateTime value or NULL if the reader does not have value.</returns> | ||
/// <remarks></remarks> | ||
public static DateTime? ToNullDateTimeParseExact(this IDataReader dataReader, string columnName, string format) | ||
=> dataReader.IsWithValue(columnName) | ||
? DateTime.ParseExact(dataReader[columnName].ToString(), format, CultureInfo.InvariantCulture) | ||
: (DateTime?)null; | ||
|
||
/// <summary> | ||
/// DateTime.Parse from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns>Return parsed DateTime value or DateTime.MinValue if the reader does not have value.</returns> | ||
/// <remarks></remarks> | ||
public static DateTime ToDateTimeParse(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? DateTime.Parse(dataReader[columnName].ToString()) | ||
: DateTime.MinValue; | ||
|
||
/// <summary> | ||
/// Nullable DateTime.Parse from DataReader | ||
/// </summary> | ||
/// <param name="dataReader">Data reader</param> | ||
/// <param name="columnName">Column name</param> | ||
/// <returns>Return parsed DateTime value or NULL MinValue if the reader does not have value.</returns> | ||
/// <remarks></remarks> | ||
public static DateTime? ToNullDateTimeParse(this IDataReader dataReader, string columnName) | ||
=> dataReader.IsWithValue(columnName) | ||
? DateTime.Parse(dataReader[columnName].ToString()) | ||
: (DateTime?)null; | ||
} | ||
} |
Oops, something went wrong.