Skip to content

kulikov-dev/SmallNetUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SmallNetUtils

A bunch of small utils and extensions which I often used in different projects on .NET.

Data classes

  • DateInterval: Class to store interval of two DateTime values. Allows to check intersection/including, equality and split interval by DateIntervalType.
  • NumsRange: Class to store double range min-max. Contains NumsRangeUtil with few methods to create a list of NumsRange based on rules: by range size, by ranges amount.

Extensions

  • StringExtension:
    1. ToString: Common 'ToString' method with possibility to change empty value to default text;
    2. FirstCharToUpper: Change first char of input text to Upper;
    3. AddHtmlTag: Wrap string with a HTML tag;
    4. RemoveHtmlTags: Remove all HTML tags from string;
    5. CreateMultiLineByLength: Convert input text to multiline length with lines of specific row length. Preserve words;
    6. CreateMultiLineByDelimiters: Convert input text to multiline separated by delimiters;
    7. Append: Allow to append new line to a StringBuilder with delimeter (like spaces);
    8. ConvertFromBase64: Convert string from Base64 format to an UTF8.
  • ColorExtension:
    1. GetRandomColor: Get nice random color. Use LRU cache to create unique colors;
    2. Lightend, Darken: Tints the color by the given percent;
    3. Invert: Color inversion;
    4. GenerateColorFromString: Generate color based on a string hash;
  • DoubleExtension:
    1. Validate: Validate number if it has value (not nan or infinity). If empty - can return string/number default value;
    2. ToString: Get string representation with number validation. If empty - can return string/number default value;
    3. EqualsEpsilon, EqualsEpsilonNaN, EqualsEpsilonNanInf: equal two numbers with epsilon to fix floating-point comparison issue. Supports Nan and Infinitives to compare;
    4. RoundToSignificant: Round number up to significant digits;
  • DateTimeExtension:
    1. IsMidnight: Check if date is midnight
    2. IsMonthStart: Check if date is month start
    3. IsQuarterStart: Check if date is quarter start
    4. IsYearStart: Check if date is year start
    5. GetQuarter: Get date quarter (number/arabic number)
    6. IsStartOfIntervalType: Check if date is start of DateInterval type (day/month/quarter/etc)
    7. AddByType/SubtractByType: Addition/Subtracting amount to a date by DateInterval type
    8. Ceil/Floor: Ceil/floor date by DateInterval
    9. GetDateInterval: Convert DateTime to DateInterval according to DateInterval type
  • EnumExtension: Useful methods to work with enums:
    1. Allows to get caption/enum-value by DescriptionAttribute;
    2. Fill different DevExpress editors with enum values.
      public enum TestEnum
      {
          [Description("Show angles on the map")]
          Angles,
    
          [Description("Show axis on the graph")]
          Axis
      }
      
      var caption = TestEnum.Angles.GetCaption();

Utils

  • ConvertUtil. Some useful methods to extend a System.Convert library. All convert metods Process Unicode BOM symbols, DBull values.
    1. ToString: Convert an object to string. If object empty - can return string default value;
    2. ToBool: Convert an object/string to boolean. Supports different representation of 'true' value like 1, YES, Y;
    3. ToDateTime: Convert an object/string to DateTime. Supports both: default string representation of DateTime and OLE automation date (Excel);
    4. ToDouble: Convert object/string value to double with CurrentFormatInfo. Supports different delimiters, default value;
    5. ToInt: Convert object/string value to int. Supports different delimiters, default value.
  • FileSystemUtil
    1. GetFileEncoding: Determines a text file's encoding by analyzing its byte order mark (BOM);
    2. LaunchFile: Launch file in an assigned application or show it in the Explorer;
    3. OpenFolder: Open a folder in the Explorer;
    4. ShowFileInExplorer: Open the Explorer and focus on a file;
    5. ValidateFileName: Validate and return valid filename;
    6. GetFileExtension: Get file extension for a file, encoded in Base64 string.
  • DateTimeUtil
    1. Min/Max: Get bigger/smaller date between two of them;
    2. MonthsBetween: Get difference between two dates in months;
    3. Concat: Concat two lists of DateTime;
    4. ConvertDateIntervalsToDateTime: Convert list of DateInterval to list of DateTime;
    5. ConvertDateTimeToDateIntervals: Convert list of DateTime to list of DateInterval;
    6. Merge: Merge consecutive dates into one DateInterval.
  • FormsUtil
    1. IsDesignMode: Check if a form opened in Designer mode;
  • DPIUtil
    1. GetDpi: Get DPI: for a monitor, if OS supports DPI per monitor or for a control
    2. ScaleFactor: Get scale factor for each monitor (100%, 125%, etc.). If possible and OS supports DPI per monitor.

Releases

No releases published

Packages

No packages published

Languages