-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enabled old commented out extensions now that we are using dotn…
…et 6 plus
- Loading branch information
Showing
4 changed files
with
125 additions
and
180 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,59 +1,59 @@ | ||
namespace MoreDotNet.Extensions.Common | ||
{ | ||
using System; | ||
////using System.Drawing; | ||
|
||
using System; | ||
using System.Drawing; | ||
|
||
/// <summary> | ||
/// <see cref="Color"/> extensions. | ||
/// </summary> | ||
public static class ColorExtensions | ||
{ | ||
/////// <summary> | ||
/////// Converts a <see cref="Color"/> object to a hex string. | ||
/////// </summary> | ||
/////// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/////// <returns>A hex string.</returns> | ||
////public static string ToHexString(this Color input) | ||
////{ | ||
//// return "#" + input.R.ToString("X2") + input.G.ToString("X2") + input.B.ToString("X2"); | ||
////} | ||
/// <summary> | ||
/// Converts a <see cref="Color"/> object to a hex string. | ||
/// </summary> | ||
/// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/// <returns>A hex string.</returns> | ||
public static string ToHexString(this Color input) | ||
{ | ||
return "#" + input.R.ToString("X2") + input.G.ToString("X2") + input.B.ToString("X2"); | ||
} | ||
|
||
/////// <summary> | ||
/////// Converts a <see cref="Color"/> object to a RGB string. | ||
/////// </summary> | ||
/////// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/////// <returns>A RGB string.</returns> | ||
////public static string ToRgbString(this Color input) | ||
////{ | ||
//// return "RGB(" + input.R + "," + input.G + "," + input.B + ")"; | ||
////} | ||
/// <summary> | ||
/// Converts a <see cref="Color"/> object to a RGB string. | ||
/// </summary> | ||
/// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/// <returns>A RGB string.</returns> | ||
public static string ToRgbString(this Color input) | ||
{ | ||
return "RGB(" + input.R + "," + input.G + "," + input.B + ")"; | ||
} | ||
|
||
/////// <summary> | ||
/////// Converts a <see cref="Color"/> object o gray-scale. | ||
/////// </summary> | ||
/////// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/////// <returns>A gray-scale equivalent of the input <see cref="Color"/> object.</returns> | ||
////public static Color ToGray(this Color input) | ||
////{ | ||
//// int g = (int)(input.R * .299) + (int)(input.G * .587) + (int)(input.B * .114); | ||
//// return Color.FromArgb(input.A, g, g, g); | ||
////} | ||
/// <summary> | ||
/// Converts a <see cref="Color"/> object o gray-scale. | ||
/// </summary> | ||
/// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/// <returns>A gray-scale equivalent of the input <see cref="Color"/> object.</returns> | ||
public static Color ToGray(this Color input) | ||
{ | ||
int g = (int)(input.R * .299) + (int)(input.G * .587) + (int)(input.B * .114); | ||
return Color.FromArgb(input.A, g, g, g); | ||
} | ||
|
||
/////// <summary> | ||
/////// Gets a color that will be readable on top of a given background color | ||
/////// </summary> | ||
/////// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/////// <returns>Black or white depending on the starting color.</returns> | ||
////public static Color ToReadableForegroundColor(this Color input) | ||
////{ | ||
//// // Math taken from one of the replies to | ||
//// // http://stackoverflow.com/questions/2241447/make-foregroundcolor-black-or-white-depending-on-background | ||
//// if (Math.Sqrt((input.R * input.R * .299) + (input.G * input.G * .587) + (input.B * input.B * .114)) > 128) | ||
//// { | ||
//// return Color.Black; | ||
//// } | ||
/// <summary> | ||
/// Gets a color that will be readable on top of a given background color | ||
/// </summary> | ||
/// <param name="input">The <see cref="Color"/> instance on which the extension method is called.</param> | ||
/// <returns>Black or white depending on the starting color.</returns> | ||
public static Color ToReadableForegroundColor(this Color input) | ||
{ | ||
// Math taken from one of the replies to | ||
// http://stackoverflow.com/questions/2241447/make-foregroundcolor-black-or-white-depending-on-background | ||
if (Math.Sqrt((input.R * input.R * .299) + (input.G * input.G * .587) + (input.B * input.B * .114)) > 128) | ||
{ | ||
return Color.Black; | ||
} | ||
|
||
//// return Color.White; | ||
////} | ||
return Color.White; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
namespace MoreDotNet.Extensions.Common | ||
{ | ||
////using System; | ||
////using System.Data; | ||
using System; | ||
using System.Data; | ||
|
||
/////// <summary> | ||
/////// Data related extensions. | ||
/////// </summary> | ||
////public static class DataExtensions | ||
////{ | ||
//// /// <summary> | ||
//// /// Safely gets a value from a <see cref="IDataRecord"/> item. | ||
//// /// </summary> | ||
//// /// <typeparam name="T">Type of the requested item.</typeparam> | ||
//// /// <param name="dataRecord">The <see cref="IDataRecord"/> instance on which the extension method is called.</param> | ||
//// /// <param name="ordinal">The ordinal of the value we want to acquire.</param> | ||
//// /// <returns>The value corresponding to the given ordinal.</returns> | ||
//// public static T GetNullable<T>(this IDataRecord dataRecord, int ordinal) | ||
//// { | ||
//// if (dataRecord == null) | ||
//// { | ||
//// throw new ArgumentNullException(nameof(dataRecord)); | ||
//// } | ||
/// <summary> | ||
/// Data related extensions. | ||
/// </summary> | ||
public static class DataExtensions | ||
{ | ||
/// <summary> | ||
/// Safely gets a value from a <see cref="IDataRecord"/> item. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the requested item.</typeparam> | ||
/// <param name="dataRecord">The <see cref="IDataRecord"/> instance on which the extension method is called.</param> | ||
/// <param name="ordinal">The ordinal of the value we want to acquire.</param> | ||
/// <returns>The value corresponding to the given ordinal.</returns> | ||
public static T GetNullable<T>(this IDataRecord dataRecord, int ordinal) | ||
{ | ||
if (dataRecord == null) | ||
{ | ||
throw new ArgumentNullException(nameof(dataRecord)); | ||
} | ||
|
||
//// return dataRecord.IsDBNull(ordinal) ? default(T) : (T)dataRecord.GetValue(ordinal); | ||
//// } | ||
////} | ||
return dataRecord.IsDBNull(ordinal) ? default(T) : (T)dataRecord.GetValue(ordinal); | ||
} | ||
} | ||
} |
112 changes: 56 additions & 56 deletions
112
src/MoreDotNet/Extensions/Common/OperatingSystemExtensions.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 |
---|---|---|
@@ -1,73 +1,73 @@ | ||
namespace MoreDotNet.Extensions.Common | ||
{ | ||
////using System; | ||
using System; | ||
|
||
/// <summary> | ||
/// <see cref="OperatingSystem"/> extensions. | ||
/// </summary> | ||
public static class OperatingSystemExtensions | ||
{ | ||
/////// <summary> | ||
/////// Checks if the OS is Windows XP or higher. | ||
/////// </summary> | ||
/////// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/////// <returns>True if the OS is Windows XP or higher. False otherwise.</returns> | ||
////public static bool IsWinXpOrHigher(this OperatingSystem os) | ||
////{ | ||
//// if (os == null) | ||
//// { | ||
//// throw new ArgumentNullException(nameof(os)); | ||
//// } | ||
/// <summary> | ||
/// Checks if the OS is Windows XP or higher. | ||
/// </summary> | ||
/// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/// <returns>True if the OS is Windows XP or higher. False otherwise.</returns> | ||
public static bool IsWinXpOrHigher(this OperatingSystem os) | ||
{ | ||
if (os == null) | ||
{ | ||
throw new ArgumentNullException(nameof(os)); | ||
} | ||
|
||
//// return (os.Platform == PlatformID.Win32NT) | ||
//// && ((os.Version.Major > 5) || ((os.Version.Major == 5) && (os.Version.Minor >= 1))); | ||
////} | ||
return (os.Platform == PlatformID.Win32NT) | ||
&& ((os.Version.Major > 5) || ((os.Version.Major == 5) && (os.Version.Minor >= 1))); | ||
} | ||
|
||
/////// <summary> | ||
/////// Checks if the OS is Windows Vista or higher. | ||
/////// </summary> | ||
/////// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/////// <returns>True if the OS is Windows Vista or higher. False otherwise.</returns> | ||
////public static bool IsWinVistaOrHigher(this OperatingSystem os) | ||
////{ | ||
//// if (os == null) | ||
//// { | ||
//// throw new ArgumentNullException(nameof(os)); | ||
//// } | ||
/// <summary> | ||
/// Checks if the OS is Windows Vista or higher. | ||
/// </summary> | ||
/// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/// <returns>True if the OS is Windows Vista or higher. False otherwise.</returns> | ||
public static bool IsWinVistaOrHigher(this OperatingSystem os) | ||
{ | ||
if (os == null) | ||
{ | ||
throw new ArgumentNullException(nameof(os)); | ||
} | ||
|
||
//// return (os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 6); | ||
////} | ||
return (os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 6); | ||
} | ||
|
||
/////// <summary> | ||
/////// Checks if the OS is Windows 7 or higher. | ||
/////// </summary> | ||
/////// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/////// <returns>True if the OS is Windows 7 or higher. False otherwise.</returns> | ||
////public static bool IsWin7OrHigher(this OperatingSystem os) | ||
////{ | ||
//// if (os == null) | ||
//// { | ||
//// throw new ArgumentNullException(nameof(os)); | ||
//// } | ||
/// <summary> | ||
/// Checks if the OS is Windows 7 or higher. | ||
/// </summary> | ||
/// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/// <returns>True if the OS is Windows 7 or higher. False otherwise.</returns> | ||
public static bool IsWin7OrHigher(this OperatingSystem os) | ||
{ | ||
if (os == null) | ||
{ | ||
throw new ArgumentNullException(nameof(os)); | ||
} | ||
|
||
//// return (os.Platform == PlatformID.Win32NT) | ||
//// && ((os.Version.Major > 6) || ((os.Version.Major == 6) && (os.Version.Minor >= 1))); | ||
////} | ||
return (os.Platform == PlatformID.Win32NT) | ||
&& ((os.Version.Major > 6) || ((os.Version.Major == 6) && (os.Version.Minor >= 1))); | ||
} | ||
|
||
/////// <summary> | ||
/////// Checks if the OS is Windows 8 or higher. | ||
/////// </summary> | ||
/////// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/////// <returns>True if the OS is Windows 8 or higher. False otherwise.</returns> | ||
////public static bool IsWin8OrHigher(this OperatingSystem os) | ||
////{ | ||
//// if (os == null) | ||
//// { | ||
//// throw new ArgumentNullException(nameof(os)); | ||
//// } | ||
/// <summary> | ||
/// Checks if the OS is Windows 8 or higher. | ||
/// </summary> | ||
/// <param name="os">The <see cref="OperatingSystem"/> instance on which the extension method is called.</param> | ||
/// <returns>True if the OS is Windows 8 or higher. False otherwise.</returns> | ||
public static bool IsWin8OrHigher(this OperatingSystem os) | ||
{ | ||
if (os == null) | ||
{ | ||
throw new ArgumentNullException(nameof(os)); | ||
} | ||
|
||
//// return (os.Platform == PlatformID.Win32NT) | ||
//// && ((os.Version.Major > 6) || ((os.Version.Major == 6) && (os.Version.Minor >= 2))); | ||
////} | ||
return (os.Platform == PlatformID.Win32NT) | ||
&& ((os.Version.Major > 6) || ((os.Version.Major == 6) && (os.Version.Minor >= 2))); | ||
} | ||
} | ||
} |