Innovt Platform
Search Results for

    Show / Hide Table of Contents

    Class Extensions

    Provides extension methods for various data types and operations.

    Inheritance
    object
    Extensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Innovt.Core.Utilities
    Assembly: Innovt.Core.dll
    Syntax
    public static class Extensions

    Methods

    | Edit this page View Source

    ConvertToStringArray(int)

    Converts an integer value to a string array containing numbers from 0 to the specified value.

    Declaration
    public static string[] ConvertToStringArray(this int value)
    Parameters
    Type Name Description
    int value

    The integer value specifying the upper bound of the array.

    Returns
    Type Description
    string[]

    An array of strings containing numbers from 0 to the specified value.

    | Edit this page View Source

    CopyTo(Stream, Stream)

    Copies data from one stream to another.

    Declaration
    public static void CopyTo(Stream src, Stream dest)
    Parameters
    Type Name Description
    Stream src

    The source stream to copy from.

    Stream dest

    The destination stream to copy to.

    | Edit this page View Source

    ExtractCoordinates(string, char)

    Extracts latitude and longitude coordinates from a string.

    Declaration
    public static (long Latitude, long Longitude) ExtractCoordinates(this string str, char splittedBy = ';')
    Parameters
    Type Name Description
    string str

    The string containing coordinates.

    char splittedBy

    The character used to split latitude and longitude values.

    Returns
    Type Description
    (long Latitude, long Longitude)

    A tuple containing latitude and longitude values.

    | Edit this page View Source

    FormatToCurrency(decimal)

    Formats a decimal value as currency.

    Declaration
    public static string FormatToCurrency(this decimal value)
    Parameters
    Type Name Description
    decimal value

    The decimal value to format.

    Returns
    Type Description
    string

    A string representation of the decimal value in currency format.

    | Edit this page View Source

    FormatToExtensionDateTime(DateTimeOffset)

    Formats a DateTimeOffset as a human-readable date and time string.

    Declaration
    public static string FormatToExtensionDateTime(this DateTimeOffset value)
    Parameters
    Type Name Description
    DateTimeOffset value

    The DateTimeOffset to format.

    Returns
    Type Description
    string

    A string representation of the DateTimeOffset in a custom format.

    | Edit this page View Source

    FormatToPeriod(DateTime, DateTime, CultureInfo)

    Formats a date period between two DateTimes as a string.

    Declaration
    public static string FormatToPeriod(this DateTime startDate, DateTime endDate, CultureInfo cultureInfo = null)
    Parameters
    Type Name Description
    DateTime startDate

    The start date of the period.

    DateTime endDate

    The end date of the period.

    CultureInfo cultureInfo

    Optional CultureInfo for formatting. Defaults to null.

    Returns
    Type Description
    string

    A string representing the formatted date period.

    | Edit this page View Source

    FormatToPeriod(DateTimeOffset, DateTimeOffset, CultureInfo)

    Formats a date period between two DateTimeOffset instances as a string, considering culture information.

    Declaration
    public static string FormatToPeriod(this DateTimeOffset startDate, DateTimeOffset endDate, CultureInfo cultureInfo = null)
    Parameters
    Type Name Description
    DateTimeOffset startDate

    The start date of the period.

    DateTimeOffset endDate

    The end date of the period.

    CultureInfo cultureInfo

    Optional CultureInfo for formatting. Defaults to null.

    Returns
    Type Description
    string

    A string representing the formatted date period.

    | Edit this page View Source

    FormatToSimpleDateTime(DateTimeOffset)

    Formats a DateTimeOffset as a simple date and time string.

    Declaration
    public static string FormatToSimpleDateTime(this DateTimeOffset value)
    Parameters
    Type Name Description
    DateTimeOffset value

    The DateTimeOffset to format.

    Returns
    Type Description
    string

    A string representation of the DateTimeOffset in a simple format.

    | Edit this page View Source

    FromUnixTimestamp(double)

    Converts a Unix timestamp (seconds since the Unix epoch) to a DateTime.

    Declaration
    public static DateTime FromUnixTimestamp(this double unixTimestamp)
    Parameters
    Type Name Description
    double unixTimestamp

    The Unix timestamp to convert.

    Returns
    Type Description
    DateTime

    A DateTime representing the converted date and time.

    | Edit this page View Source

    GetMimeType(string)

    Returns a mimetype based on the file extension

    Declaration
    public static string GetMimeType(this string fileName)
    Parameters
    Type Name Description
    string fileName
    Returns
    Type Description
    string
    | Edit this page View Source

    IsGuidEmpty(Guid)

    Determines whether the specified Guid is empty.

    Declaration
    public static bool IsGuidEmpty(this Guid id)
    Parameters
    Type Name Description
    Guid id

    The Guid to check for emptiness.

    Returns
    Type Description
    bool

    True if the Guid is empty; otherwise, false.

    | Edit this page View Source

    IsGuidNullOrEmpty(Guid?)

    Determines whether the specified nullable Guid is null or empty.

    Declaration
    public static bool IsGuidNullOrEmpty(this Guid? id)
    Parameters
    Type Name Description
    Guid? id

    The nullable Guid to check for null or emptiness.

    Returns
    Type Description
    bool

    True if the Guid is null or empty; otherwise, false.

    | Edit this page View Source

    IsLessThanOrEqualToZero(double)

    Determines whether the specified double is less than or equal to zero.

    Declaration
    public static bool IsLessThanOrEqualToZero(this double id)
    Parameters
    Type Name Description
    double id

    The double to check.

    Returns
    Type Description
    bool

    True if the double is less than or equal to zero; otherwise, false.

    | Edit this page View Source

    IsLessThanOrEqualToZero(int)

    Determines whether the specified integer is less than or equal to zero.

    Declaration
    public static bool IsLessThanOrEqualToZero(this int id)
    Parameters
    Type Name Description
    int id

    The integer to check.

    Returns
    Type Description
    bool

    True if the integer is less than or equal to zero; otherwise, false.

    | Edit this page View Source

    IsLessThanOrEqualToZero(long)

    Determines whether the specified long integer is less than or equal to zero.

    Declaration
    public static bool IsLessThanOrEqualToZero(this long id)
    Parameters
    Type Name Description
    long id

    The long integer to check.

    Returns
    Type Description
    bool

    True if the long integer is less than or equal to zero; otherwise, false.

    | Edit this page View Source

    IsLessThanOrEqualToZero(int?)

    Determines whether the specified nullable integer is null or less than or equal to zero.

    Declaration
    public static bool IsLessThanOrEqualToZero(this int? id)
    Parameters
    Type Name Description
    int? id

    The nullable integer to check.

    Returns
    Type Description
    bool

    True if the integer is null or less than or equal to zero; otherwise, false.

    | Edit this page View Source

    IsNull(object)

    Determines whether the specified object is null.

    Declaration
    public static bool IsNull(this object obj)
    Parameters
    Type Name Description
    object obj

    The object to check for null.

    Returns
    Type Description
    bool

    True if the object is null; otherwise, false.

    | Edit this page View Source

    IsPrimitiveType(Type)

    Determines whether the specified type is a primitive data type.

    Declaration
    public static bool IsPrimitiveType(this Type type)
    Parameters
    Type Name Description
    Type type

    The Type to check.

    Returns
    Type Description
    bool

    True if the type is a primitive data type; otherwise, false.

    | Edit this page View Source

    LastDayOfMonth(DateTimeOffset)

    Returns the last day of the month for a given DateTimeOffset.

    Declaration
    public static DateTimeOffset LastDayOfMonth(this DateTimeOffset date)
    Parameters
    Type Name Description
    DateTimeOffset date

    The DateTimeOffset for which to find the last day of the month.

    Returns
    Type Description
    DateTimeOffset

    The DateTimeOffset representing the last day of the month.

    | Edit this page View Source

    MaskCreditCard(string)

    Masks the credit card number by replacing the middle digits with asterisks.

    Declaration
    public static string MaskCreditCard(this string number)
    Parameters
    Type Name Description
    string number

    The credit card number to mask.

    Returns
    Type Description
    string

    The masked credit card number.

    | Edit this page View Source

    MillisecondToDateTime(double)

    Converts a double value representing milliseconds since the Unix epoch to a DateTimeOffset.

    Declaration
    public static DateTimeOffset? MillisecondToDateTime(this double fromSeconds)
    Parameters
    Type Name Description
    double fromSeconds

    The double value representing milliseconds since the Unix epoch.

    Returns
    Type Description
    DateTimeOffset?

    A DateTimeOffset representing the converted date and time.

    | Edit this page View Source

    OnlyDate(DateTimeOffset)

    Returns a DateTimeOffset with the same date as the input DateTimeOffset but with the time set to midnight (00:00:00).

    Declaration
    public static DateTimeOffset OnlyDate(this DateTimeOffset now)
    Parameters
    Type Name Description
    DateTimeOffset now

    The input DateTimeOffset.

    Returns
    Type Description
    DateTimeOffset

    A DateTimeOffset with the same date and midnight time.

    | Edit this page View Source

    StartOfWeek(DateTimeOffset, DayOfWeek)

    Calculates the start of the week for a given DateTimeOffset based on the specified DayOfWeek.

    Declaration
    public static DateTimeOffset StartOfWeek(this DateTimeOffset dt, DayOfWeek startOfWeek)
    Parameters
    Type Name Description
    DateTimeOffset dt

    The DateTimeOffset for which to find the start of the week.

    DayOfWeek startOfWeek

    The DayOfWeek that defines the start of the week.

    Returns
    Type Description
    DateTimeOffset

    The DateTimeOffset representing the start of the week.

    | Edit this page View Source

    ToBase64(Stream)

    Converts a stream to a base 64 string

    Declaration
    public static string ToBase64(this Stream stream)
    Parameters
    Type Name Description
    Stream stream
    Returns
    Type Description
    string
    | Edit this page View Source

    ToBrazilianTimeZone(DateTime)

    Converts a DateTime to the Brazilian time zone (UTC-3).

    Declaration
    public static DateTime ToBrazilianTimeZone(this DateTime date)
    Parameters
    Type Name Description
    DateTime date

    The DateTime to convert.

    Returns
    Type Description
    DateTime

    The DateTime converted to the Brazilian time zone.

    | Edit this page View Source

    ToDataUriBase64(Stream, string)

    Converts a string to a uri base 64 pattern

    Declaration
    public static string ToDataUriBase64(this Stream stream, string mimeType)
    Parameters
    Type Name Description
    Stream stream

    The Stream file.

    string mimeType

    The stream mimeType

    Returns
    Type Description
    string
    | Edit this page View Source

    ToStringOrDefault(object)

    Converts the specified object to a string or returns an empty string if the object is null.

    Declaration
    public static string ToStringOrDefault(this object obj)
    Parameters
    Type Name Description
    object obj

    The object to convert to a string.

    Returns
    Type Description
    string

    The string representation of the object or an empty string if the object is null.

    | Edit this page View Source

    ToTimeZone(DateTime, TimeSpan, TimeSpan)

    Converts one timezone to another using the offset difference.

    Declaration
    public static DateTime ToTimeZone(this DateTime sourceDateTime, TimeSpan sourceOffset, TimeSpan targetOffset)
    Parameters
    Type Name Description
    DateTime sourceDateTime

    The datetime without timezone

    TimeSpan sourceOffset

    The offset from the source

    TimeSpan targetOffset

    The final offset.

    Returns
    Type Description
    DateTime

    A DateTime with the difference.

    | Edit this page View Source

    ToTimeZone(DateTimeOffset, TimeSpan)

    Converts one timezone to another using the offset difference.

    Declaration
    public static DateTime ToTimeZone(this DateTimeOffset sourceDateTime, TimeSpan targetOffset)
    Parameters
    Type Name Description
    DateTimeOffset sourceDateTime

    The datetime without timezone

    TimeSpan targetOffset

    The final offset.

    Returns
    Type Description
    DateTime

    A DateTime with the difference.

    | Edit this page View Source

    ToUnixTimestamp(DateTime)

    Converts a DateTime to a Unix timestamp (seconds since the Unix epoch).

    Declaration
    public static double ToUnixTimestamp(this DateTime dateTime)
    Parameters
    Type Name Description
    DateTime dateTime

    The DateTime to convert.

    Returns
    Type Description
    double

    A double representing the Unix timestamp.

    | Edit this page View Source

    ToUnixTimestamp(DateTimeOffset)

    Converts a DateTimeOffset to a Unix timestamp (seconds since the Unix epoch).

    Declaration
    public static double ToUnixTimestamp(this DateTimeOffset dateTime)
    Parameters
    Type Name Description
    DateTimeOffset dateTime

    The DateTimeOffset to convert.

    Returns
    Type Description
    double

    A double representing the Unix timestamp.

    | Edit this page View Source

    ToYesNo(bool)

    Converts a boolean value to a "Sim" (Yes) or "Não" (No) string representation.

    Declaration
    public static string ToYesNo(this bool value)
    Parameters
    Type Name Description
    bool value

    The boolean value to convert.

    Returns
    Type Description
    string

    "Sim" if the value is true; otherwise, "Não".

    | Edit this page View Source

    Unzip(byte[])

    Decompresses a compressed byte array using GZip compression into a string.

    Declaration
    public static string Unzip(this byte[] bytes)
    Parameters
    Type Name Description
    byte[] bytes

    The compressed byte array to decompress.

    Returns
    Type Description
    string

    The decompressed string.

    | Edit this page View Source

    Zip(byte[])

    Compresses a byte array using GZip compression.

    Declaration
    public static byte[] Zip(this byte[] bytes)
    Parameters
    Type Name Description
    byte[] bytes

    The byte array to compress.

    Returns
    Type Description
    byte[]

    The compressed byte array.

    | Edit this page View Source

    Zip(string)

    Compresses a string into a byte array using GZip compression.

    Declaration
    public static byte[] Zip(this string str)
    Parameters
    Type Name Description
    string str

    The string to compress.

    Returns
    Type Description
    byte[]

    The compressed byte array.

    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX