using System;
using System.Text;
namespace ExtensionMethods
{
///
/// Add extensions to
///
public static class ByteExtensions
{
///
/// Convert the given to a string, but return null if == null
///
///
/// null or
public static string ToNullableString(this byte? Byte)
{
if (Byte == null)
return null;
return Byte.ToString();
}
///
/// Concatenates a speceified separator between each element of a specified array, yielding a single concatenated string
///
///
/// A
/// The concatenated
public static string Join(this sbyte[] array, string separator)
{
StringBuilder concat = new StringBuilder();
bool notFirst = false;
foreach (sbyte item in array)
{
if (notFirst)
concat.Append(separator);
else
notFirst = true;
concat.Append(item);
}
return concat.ToString();
}
///
/// Concatenates a speceified separator between each element of a specified array, yielding a single concatenated string
///
///
/// A
/// T must be an enumerated type
/// The concatenated
public static string Join(this sbyte[] array, string separator) where T : struct, IConvertible
{
if (!typeof(T).IsEnum)
throw new ArgumentException("T must be an enumerated type");
StringBuilder concat = new StringBuilder();
bool notFirst = false;
foreach (sbyte item in array)
{
if (notFirst)
concat.Append(separator);
else
notFirst = true;
concat.Append(((T)((object)item)).ToString());
}
return concat.ToString();
}
}
}