Skip to content

Methods

jerry1333 edited this page Oct 30, 2017 · 5 revisions

Available methods in version 1.4.0 (all available from shared class 'Utils') :

Utils.cs

GetValueDescriptionEnumerable()

Returns description of enum field.

Example

    public enum KomunikatKod
    {
        [Description("User must enter valid captcha")]
        NeedCaptcha = 1,
        [Description("Result returned to many ID's")]
        TooManyIds = 2,
        [Description("Result empty")]
        NoSubjects = 4,
        [Description("User must login")]
        NoSession = 7
    }

PreserveStackTrace()

When using throw(); to pass exception to be handled in parent method, exception will not have full stack trace.

Example:

    try
    {
        throw new ArgumentException(nameof(test));
    }
    catch (Exception)
    {
         throw;
    }

Will produce this exception, notice that line 54 is line where throw; is.

System.ArgumentException: test
   w TestApp.Program.testFunc(String test) TestApp\Program.cs:wiersz 54
   w TestApp.Program.Main(String[] args) w TestApp\Program.cs:wiersz 17

Now using function will produce more complete exception:

    try
    {
        throw new ArgumentException(nameof(test));
    }
    catch (Exception e)
    {
        Utils.PreserveStackTrace(e);
        throw e;
    }

Where line 51 is 'throw new Arg...' and line 56 is throw e;.

System.ArgumentException: test
   w TestApp.Program.testFunc(String test) w TestApp\Program.cs:wiersz 51
   w TestApp.Program.testFunc(String test) w TestApp\Program.cs:wiersz 56
   w TestApp.Program.Main(String[] args) w TestApp\Program.cs:wiersz 18

GetVersion()

Returns version of and assembly based on type.

Example:

    GetVersion(typeof(Utils));

GetUtilsVersion()

Returns version of Utils library using method shown above.

AddressUtils.cs

FormatAddress()

Format Polish address from raw city, street etc. to one string.

Example:

FormatAddress("Warszawa", "00-000", "Warszawa", "Testowa", "12") => "ul. Testowa 12, 00-000 Warszawa"

FormatAddress("Testowo", "00-000", "Warszawa", "Testowa", "12") => "ul. Testowa 12, Testowo, 00-000 Warszawa"

FormatAddress("Warszawa", "00-000", "Warszawa", null, "12") => "Warszawa 12, 00-000 Warszawa"

FormatPostalCode()

Format Polish postal code and returns in XX-XXX format.

EnumerableUtils.cs

IsIn

HashUtils.cs

Sha1()

Returns SHA-1 hash of given string, optional parameter is encoding to use (null equals UTF-8).

Md5()

Returns MD5 hash of given string, optional parameter is encoding to use (null equals UTF-8).

NipUtils.cs

ValidateNip()

FormatNip()

NumberUtils.cs

IsBetweenII()

min <= value <= max

IsBetweenEI()

min < value <= max

IsBetweenIE()

min <= value < max

IsBetweenEE()

min < value < max

RegExUtils.cs

IsPatternValid()

Return true if provided string is valid regex pattern.

RemoveNonNumbers()

RemoveNonAplhaNumbers()

RemoveNonAplha()

RemoveRegexPattern()

RegonUtils.cs

ValidateRegon()

Validate REGON number (Wikipedia)

Regon9To14()

Converts 9 digits REGON to 14 digits

StringUtils.cs

IsNullOrEmpty()

Simple extension method. Instead:

var test = "Sample string";
if (string.IsNullOrEmpty(test)) 
    return "It works!";

You can use:

var test = "Sample string";
if (test.IsNullOrEmpty()) 
    return "It works!";

SplitWithCheckSeparator()