Introduction
Good functionalities for developers in C#
Installation
-
Install Package
Install-Package EstecheAssemblies
Content
DateTime Extensions
-
ToFriendlyTimeSpan(Language)
Returns a friendly text on the TimeSpan got it for this DateTime until Now. E.g. "00:00:04" = "4 minutes ago" or “00:05:32” = “5 hours ago” It is available in English, Chinese, Spanish and Swedish.
-
ToShortFriendlyTimeSpan(Language)
Returns a shorter friendly text on the TimeSpan got it for this DateTime until Now. E.g. "00:00:04" = "4 min" or “00:05:32” = “5 hr” It is available in English, Spanish and Swedish. The Chinese has no shorter version.
String Extensions
-
IsAbsNumeric()
Returns a bool telling if a String is an absolut entire number
-
IsDateTime()
Returns a bool telling if a String is a DateTime and returns the value parsed in case it is correct.
-
IsGuid()
Returns a bool telling if a String is a DateTime and returns the value parsed in case it is correct.
-
IsSwedishPersonalNumber()
This is a functionality used in Sweden for validating a personal number (Social Security number) Returns a bool telling if a String is a correct Swedish Personal Number and in case of Not, it returns the Error Message.
-
ToSecureString()
This functionality convert a string to a SecureString
-
ToPlanString()
This convert a SecureString to a string
-
ToUpperFirstChar()
This turn the first char in a string to UpperCase
-
IsEqualTo(SecureString comparingSecureString)
This function compare is this "SecureString" is equeal to a comparing one.
Good to know
This package is free for everyone to use. It is open source wroten in C# allocated in AzureRepo: https://dev.azure.com/fuestechefamily/EstecheAssemblies/_git/EstecheAssemblies
Implementation
Add using
using EstecheAssemblies;
ToFriendlyTimeSpan(Language)
var date = new DateTime("2019-08-08 01:03:21");
var friendlyTextEnglish = date.ToFriendlyTimeSpan(Language.English);
var friendlyTextSimplifiedChinese = date.ToFriendlyTimeSpan(Language.SimplifiedChinese);
var friendlyTextTraditionalChinese = date.ToFriendlyTimeSpan(Language.TraditionalChinese);
var friendlyTextSwedish = date.ToFriendlyTimeSpan(Language.Swedish);
var friendlyTextSpanish = date.ToFriendlyTimeSpan(Language.Spanish);
var friendlyTextEnglishDefault = date.ToFriendlyTimeSpan();
ToShortFriendlyTimeSpan(Language)
var date = new DateTime("2019-08-08");
var shorterFriendlyTextEnglish = date.ToShortFriendlyTimeSpan(Language.English);
var shorterFriendlyTextSimplifiedChinese = date.ToShortFriendlyTimeSpan(Language.SimplifiedChinese);
var shorterFriendlyTextTraditionalChinese = date.ToShortFriendlyTimeSpan(Language.TraditionalChinese);
var shorterFriendlyTextSwedish = date.ToShortFriendlyTimeSpan(Language.Swedish);
var shorterFriendlyTextSpanish = date.ToShortFriendlyTimeSpan(Language.Spanish);
var shorterFriendlyTextEnglishDefault = date.ToShortFriendlyTimeSpan();
ToSecureString()
var myPassword = "My Password";
SecureString mySecureString = myPassword.ToSecureString();
ToPlanString()
string myStringPassword = mySecureString.ToPlanString();
ToUpperFirstChar
var myText = "it's a beutifull life";
string betterFormatedText = myText.ToUpperFirstChar();
IsEqualTo(SecureString comparingSecureString)
SecureString mySecureString = "it_is_my_Password".ToSecureString();
SecureString mySecureString2 = "it_is_my_Password".ToSecureString();
bool correctPassword = mySecureString.IsEqualTo(mySecureString2);
IsDateTime()
var text = "2019-08-08-68";
var validDate = text.IsDateTime();
IsGuid()
var text = "6B1A5C52-E10C-471C-422309EC06A1";
var validGuid = text.IsGuid();
IsAbsNumeric()
var text = "6B1A5C52";
var validNumber = text.IsAbsNumeric();
IsAbsNumeric()
var text = "121212-1212";
var validNumber = text.IsSwedishPersonalNumber();
