Skip to content

Commit

Permalink
feat: enabled old commented out extensions now that we are using dotn…
Browse files Browse the repository at this point in the history
…et 6 plus
  • Loading branch information
Teodor92 committed Dec 29, 2023
1 parent 76b2e41 commit 13530f1
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 180 deletions.
55 changes: 0 additions & 55 deletions src/MoreDotNet/Extensions/Common/BitmapExtensions.cs

This file was deleted.

92 changes: 46 additions & 46 deletions src/MoreDotNet/Extensions/Common/ColorExtensions.cs
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;
}
}
}
46 changes: 23 additions & 23 deletions src/MoreDotNet/Extensions/Common/DataExtensions.cs
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 src/MoreDotNet/Extensions/Common/OperatingSystemExtensions.cs
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)));
}
}
}

0 comments on commit 13530f1

Please sign in to comment.