C# Class ClrPlus.Core.Extensions.StringExtensions

Extensions for strings. Whheeee
Datei anzeigen Open project: perpetual-motion/clrplus

Public Methods

Method Description
CamelCaseToDashed ( this camelCaseText, char separator = '-' ) : string
Contains ( this text ) : bool
ContainsAllAsWildcards ( this source ) : bool
ContainsAnyAsWildcards ( this source ) : bool
ContainsIgnoreCase ( this source, string value ) : bool

A case insensitive Contains() method.

CreateGuid ( this str ) : System.Guid

Creates a GUID from an MD5 value of the string passed in.

CreatePublicKeyToken ( this publicKey ) : string

Creates the public key token given a public key.. Note: Does this work?

DashedToCamelCase ( this dashedText, char separator = '-' ) : string
DashedToPascalCase ( this dashedText, char separator = '-' ) : string
EmptyAsNull ( this str ) : string
EqualsEx ( this str1, string str2 ) : bool

Checks to see if strings are equal, with empty strings being considered equal to null.

Error ( this formatString ) : void

Errors the specified format string.

FormatWithMacros ( this value, GetMacroValueDelegate getMacroValue, object eachItem = null, GetMacroValueDelegate preprocessValue = null, GetMacroValueDelegate postprocessValue = null ) : string
GetKeyTokenFromFullKey ( this fullKey ) : byte[]

Gets the key token from full key. Does this work?

Gunzip ( this input ) : string

Gunzips the specified input.

GunzipFromBase64 ( this input ) : string

Gunzips from base64.

Gzip ( this input ) : byte[]

Gzips the specified input.

GzipToBase64 ( this input ) : string

Gzips to base64.

HasWildcardMatch ( this source, string value, string ignorePrefix = null ) : bool

Runs IsWildcardMatch on a collection.

HasWildcards ( this input ) : bool

Determines whether the specified input has wildcards.

HtmlDecode ( this s ) : string

decodes an HTML encoded string

HtmlEncode ( this s ) : string

Encodes a string into HTML encoding format, encoding control characters as well.

IfNullOrEmpty ( this text, string defaultText ) : string
Is ( this str ) : bool
IsBoolean ( this text ) : bool

Determines whether the specified text is a boolean (true or false).

IsEmail ( this email ) : bool

Determines whether the specified email is email.

IsFalse ( this text ) : bool

Determines whether the specified text is equal to "false" (ignoring case).

IsMultiline ( this text ) : bool
IsNegative ( this text ) : bool

Determines whether the specified text is equal to some value indicated negative/off/false/no (ignoring case).

IsPositive ( this text ) : bool

Determines whether the specified text equal to some value indicated on/true/enabled (ignoring case).

IsTrue ( this text ) : bool

Determines whether the specified text equal to "true" (ignoring case).

IsWebUri ( this text ) : bool
MD5Hash ( this input ) : string

Calculates the MD5 hash of a string. Additionally all the letters in the hash are in uppercase.

MakeAttractiveFilename ( this input ) : string
MakeSafeDirectoryId ( this input ) : string

Creates a safe directory ID for MSI for a possibly non-safe one.

MakeSafeFileName ( this input ) : string
Match ( this input, string rxExpression ) : Match

Matches the specified input.

MatchIgnoreCase ( this input, string rxExpression ) : Match

Matches a regular expression, ignoring case.

NewIsWildcardMatch ( this text, string wildcardMask, bool isMatchingLocation = false, string currentLocation = null ) : bool

The new implementation of the wildcard matching function. Rules: * means matches anything except slash or backslash ? means match any one character ** means matches anything

OnlyContains ( this str, char characters ) : bool

returns true when the string contains only the characters passed in.

OnlyContains ( this str, string characters ) : bool

returns true when the string contains only the characters in the string passed in .

PositionOfFirstCharacterNotIn ( this str, char characters ) : int

Gets the position of the first character that is not in the collection of characters passed in.

PositionOfFirstCharacterNotIn ( this str, string characters ) : int

Gets the position of the first character that is not in the string passed in.

ProtectBinaryForMachine ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable

encrypts the given collection of bytes with the machine key and salt (defaults to "CoAppToolkit")

ProtectBinaryForUser ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable

encrypts the given collection of bytes with the user key and salt (defaults to "CoAppToolkit")

ProtectForMachine ( this text, string salt = "CoAppToolkit" ) : IEnumerable

encrypts the given string with the machine key and salt (defaults to "CoAppToolkit")

ProtectForUser ( this text, string salt = "CoAppToolkit" ) : IEnumerable

encrypts the given string with the machine key and salt (defaults to "CoAppToolkit")

Replace ( this s, string oldValue, string newValue, System.StringComparison comparisonType ) : string

Case insensitive version of String.Replace().

StartsWithNumber ( this str ) : bool
ToByteArray ( this text ) : byte[]

Encodes the string as an array of UTF8 bytes.

ToHexString ( this bytes ) : string

Creates a hex representaion of a collection of bytes

ToInt32 ( this str ) : int

coerces a string to an int32, defaults to zero.

ToInt32 ( this str, int defaultValue ) : int

coerces a string to an int32, defaults to zero.

ToSecureString ( this password ) : SecureString
ToUnsecureString ( this securePassword ) : string
ToUri ( this stringUri ) : Uri
ToUtf8String ( this bytes ) : string

Creates a string from a collection of UTF8 bytes

UnprotectBinaryForMachine ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable

decrypts the given collection of bytes with the machine key and salt (defaults to "CoAppToolkit") returns an empty collection of bytes on failure

UnprotectBinaryForUser ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable

decrypts the given collection of bytes with the user key and salt (defaults to "CoAppToolkit") returns an empty collection of bytes on failure

UnprotectForMachine ( this binaryData, string salt = "CoAppToolkit" ) : string

decrypts the given collection of bytes with the machine key and salt (defaults to "CoAppToolkit") and returns a string from the UTF8 representation of the bytes. returns an empty string on failure

UnprotectForUser ( this binaryData, string salt = "CoAppToolkit" ) : string

decrypts the given collection of bytes with the user key and salt (defaults to "CoAppToolkit") and returns a string from the UTF8 representation of the bytes. returns an empty string on failure

UrlDecode ( this s ) : string

decodes the URL encoded string

UrlEncode ( this s ) : string

encodes the string as a url encoded string

UrlEncodeJustBackslashes ( this s ) : string
WhenNullOrEmpty ( this original, string whenEmpty ) : string
format ( this formatString ) : string

Formats the specified format string.

Private Methods

Method Description
ProcessMacroInternal ( this value, GetMacroValueDelegate getMacroValue, object eachItem = null ) : string
WildcardToRegex ( string wildcard, string noEscapePrefix = "^" ) : Regex
camelCaseToDashed ( this camelCaseText, char separator = '-' ) : IEnumerable
dashedToCamelCase ( this dashedText, char separator = '-', bool pascalCase = false ) : IEnumerable

Method Details

CamelCaseToDashed() public static method

public static CamelCaseToDashed ( this camelCaseText, char separator = '-' ) : string
camelCaseText this
separator char
return string

Contains() public static method

public static Contains ( this text ) : bool
text this
return bool

ContainsAllAsWildcards() public static method

public static ContainsAllAsWildcards ( this source ) : bool
source this
return bool

ContainsAnyAsWildcards() public static method

public static ContainsAnyAsWildcards ( this source ) : bool
source this
return bool

ContainsIgnoreCase() public static method

A case insensitive Contains() method.
public static ContainsIgnoreCase ( this source, string value ) : bool
source this The source.
value string The value.
return bool

CreateGuid() public static method

Creates a GUID from an MD5 value of the string passed in.
public static CreateGuid ( this str ) : System.Guid
str this The STR.
return System.Guid

CreatePublicKeyToken() public static method

Creates the public key token given a public key.. Note: Does this work?
public static CreatePublicKeyToken ( this publicKey ) : string
publicKey this The public key.
return string

DashedToCamelCase() public static method

public static DashedToCamelCase ( this dashedText, char separator = '-' ) : string
dashedText this
separator char
return string

DashedToPascalCase() public static method

public static DashedToPascalCase ( this dashedText, char separator = '-' ) : string
dashedText this
separator char
return string

EmptyAsNull() public static method

public static EmptyAsNull ( this str ) : string
str this
return string

EqualsEx() public static method

Checks to see if strings are equal, with empty strings being considered equal to null.
public static EqualsEx ( this str1, string str2 ) : bool
str1 this First String to compare
str2 string Second String to compare
return bool

Error() public static method

Errors the specified format string.
public static Error ( this formatString ) : void
formatString this The format string.
return void

FormatWithMacros() public static method

public static FormatWithMacros ( this value, GetMacroValueDelegate getMacroValue, object eachItem = null, GetMacroValueDelegate preprocessValue = null, GetMacroValueDelegate postprocessValue = null ) : string
value this
getMacroValue GetMacroValueDelegate
eachItem object
preprocessValue GetMacroValueDelegate
postprocessValue GetMacroValueDelegate
return string

GetKeyTokenFromFullKey() public static method

Gets the key token from full key. Does this work?
public static GetKeyTokenFromFullKey ( this fullKey ) : byte[]
fullKey this The full key.
return byte[]

Gunzip() public static method

Gunzips the specified input.
public static Gunzip ( this input ) : string
input this The input.
return string

GunzipFromBase64() public static method

Gunzips from base64.
public static GunzipFromBase64 ( this input ) : string
input this The input.
return string

Gzip() public static method

Gzips the specified input.
public static Gzip ( this input ) : byte[]
input this The input.
return byte[]

GzipToBase64() public static method

Gzips to base64.
public static GzipToBase64 ( this input ) : string
input this The input.
return string

HasWildcardMatch() public static method

Runs IsWildcardMatch on a collection.
public static HasWildcardMatch ( this source, string value, string ignorePrefix = null ) : bool
source this The source.
value string The value.
ignorePrefix string The ignore prefix.
return bool

HasWildcards() public static method

Determines whether the specified input has wildcards.
public static HasWildcards ( this input ) : bool
input this The input.
return bool

HtmlDecode() public static method

decodes an HTML encoded string
public static HtmlDecode ( this s ) : string
s this The string
return string

HtmlEncode() public static method

Encodes a string into HTML encoding format, encoding control characters as well.
public static HtmlEncode ( this s ) : string
s this The s.
return string

IfNullOrEmpty() public static method

public static IfNullOrEmpty ( this text, string defaultText ) : string
text this
defaultText string
return string

Is() public static method

public static Is ( this str ) : bool
str this
return bool

IsBoolean() public static method

Determines whether the specified text is a boolean (true or false).
public static IsBoolean ( this text ) : bool
text this The text.
return bool

IsEmail() public static method

Determines whether the specified email is email.
public static IsEmail ( this email ) : bool
email this The email.
return bool

IsFalse() public static method

Determines whether the specified text is equal to "false" (ignoring case).
public static IsFalse ( this text ) : bool
text this The text.
return bool

IsMultiline() public static method

public static IsMultiline ( this text ) : bool
text this
return bool

IsNegative() public static method

Determines whether the specified text is equal to some value indicated negative/off/false/no (ignoring case).
public static IsNegative ( this text ) : bool
text this The text.
return bool

IsPositive() public static method

Determines whether the specified text equal to some value indicated on/true/enabled (ignoring case).
public static IsPositive ( this text ) : bool
text this The text.
return bool

IsTrue() public static method

Determines whether the specified text equal to "true" (ignoring case).
public static IsTrue ( this text ) : bool
text this The text.
return bool

IsWebUri() public static method

public static IsWebUri ( this text ) : bool
text this
return bool

MD5Hash() public static method

Calculates the MD5 hash of a string. Additionally all the letters in the hash are in uppercase.
public static MD5Hash ( this input ) : string
input this a string to a calculate the hash for
return string

MakeAttractiveFilename() public static method

public static MakeAttractiveFilename ( this input ) : string
input this
return string

MakeSafeDirectoryId() public static method

Creates a safe directory ID for MSI for a possibly non-safe one.
public static MakeSafeDirectoryId ( this input ) : string
input this The input.
return string

MakeSafeFileName() public static method

public static MakeSafeFileName ( this input ) : string
input this
return string

Match() public static method

Matches the specified input.
public static Match ( this input, string rxExpression ) : Match
input this The input.
rxExpression string The rx expression.
return System.Text.RegularExpressions.Match

MatchIgnoreCase() public static method

Matches a regular expression, ignoring case.
public static MatchIgnoreCase ( this input, string rxExpression ) : Match
input this The input.
rxExpression string The rx expression.
return System.Text.RegularExpressions.Match

NewIsWildcardMatch() public static method

The new implementation of the wildcard matching function. Rules: * means matches anything except slash or backslash ? means match any one character ** means matches anything
public static NewIsWildcardMatch ( this text, string wildcardMask, bool isMatchingLocation = false, string currentLocation = null ) : bool
text this
wildcardMask string
isMatchingLocation bool
currentLocation string
return bool

OnlyContains() public static method

returns true when the string contains only the characters passed in.
public static OnlyContains ( this str, char characters ) : bool
str this The STR.
characters char The characters.
return bool

OnlyContains() public static method

returns true when the string contains only the characters in the string passed in .
public static OnlyContains ( this str, string characters ) : bool
str this The STR.
characters string The characters.
return bool

PositionOfFirstCharacterNotIn() public static method

Gets the position of the first character that is not in the collection of characters passed in.
public static PositionOfFirstCharacterNotIn ( this str, char characters ) : int
str this The STR.
characters char The characters.
return int

PositionOfFirstCharacterNotIn() public static method

Gets the position of the first character that is not in the string passed in.
public static PositionOfFirstCharacterNotIn ( this str, string characters ) : int
str this The STR.
characters string The characters.
return int

ProtectBinaryForMachine() public static method

encrypts the given collection of bytes with the machine key and salt (defaults to "CoAppToolkit")
public static ProtectBinaryForMachine ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable
binaryData this The binary data.
salt string The salt.
return IEnumerable

ProtectBinaryForUser() public static method

encrypts the given collection of bytes with the user key and salt (defaults to "CoAppToolkit")
public static ProtectBinaryForUser ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable
binaryData this The binary data.
salt string The salt.
return IEnumerable

ProtectForMachine() public static method

encrypts the given string with the machine key and salt (defaults to "CoAppToolkit")
public static ProtectForMachine ( this text, string salt = "CoAppToolkit" ) : IEnumerable
text this The text.
salt string The salt.
return IEnumerable

ProtectForUser() public static method

encrypts the given string with the machine key and salt (defaults to "CoAppToolkit")
public static ProtectForUser ( this text, string salt = "CoAppToolkit" ) : IEnumerable
text this The text.
salt string The salt.
return IEnumerable

Replace() public static method

Case insensitive version of String.Replace().
public static Replace ( this s, string oldValue, string newValue, System.StringComparison comparisonType ) : string
s this String that contains patterns to replace
oldValue string Pattern to find
newValue string New pattern to replaces old
comparisonType System.StringComparison String comparison type
return string

StartsWithNumber() public static method

public static StartsWithNumber ( this str ) : bool
str this
return bool

ToByteArray() public static method

Encodes the string as an array of UTF8 bytes.
public static ToByteArray ( this text ) : byte[]
text this The text.
return byte[]

ToHexString() public static method

Creates a hex representaion of a collection of bytes
public static ToHexString ( this bytes ) : string
bytes this The bytes.
return string

ToInt32() public static method

coerces a string to an int32, defaults to zero.
public static ToInt32 ( this str ) : int
str this The STR.
return int

ToInt32() public static method

coerces a string to an int32, defaults to zero.
public static ToInt32 ( this str, int defaultValue ) : int
str this The STR.
defaultValue int The default value if the string isn't a valid int.
return int

ToSecureString() public static method

public static ToSecureString ( this password ) : SecureString
password this
return System.Security.SecureString

ToUnsecureString() public static method

public static ToUnsecureString ( this securePassword ) : string
securePassword this
return string

ToUri() public static method

public static ToUri ( this stringUri ) : Uri
stringUri this
return System.Uri

ToUtf8String() public static method

Creates a string from a collection of UTF8 bytes
public static ToUtf8String ( this bytes ) : string
bytes this The bytes.
return string

UnprotectBinaryForMachine() public static method

decrypts the given collection of bytes with the machine key and salt (defaults to "CoAppToolkit") returns an empty collection of bytes on failure
public static UnprotectBinaryForMachine ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable
binaryData this The binary data.
salt string The salt.
return IEnumerable

UnprotectBinaryForUser() public static method

decrypts the given collection of bytes with the user key and salt (defaults to "CoAppToolkit") returns an empty collection of bytes on failure
public static UnprotectBinaryForUser ( this binaryData, string salt = "CoAppToolkit" ) : IEnumerable
binaryData this The binary data.
salt string The salt.
return IEnumerable

UnprotectForMachine() public static method

decrypts the given collection of bytes with the machine key and salt (defaults to "CoAppToolkit") and returns a string from the UTF8 representation of the bytes. returns an empty string on failure
public static UnprotectForMachine ( this binaryData, string salt = "CoAppToolkit" ) : string
binaryData this The binary data.
salt string The salt.
return string

UnprotectForUser() public static method

decrypts the given collection of bytes with the user key and salt (defaults to "CoAppToolkit") and returns a string from the UTF8 representation of the bytes. returns an empty string on failure
public static UnprotectForUser ( this binaryData, string salt = "CoAppToolkit" ) : string
binaryData this The binary data.
salt string The salt.
return string

UrlDecode() public static method

decodes the URL encoded string
public static UrlDecode ( this s ) : string
s this The s.
return string

UrlEncode() public static method

encodes the string as a url encoded string
public static UrlEncode ( this s ) : string
s this The s.
return string

UrlEncodeJustBackslashes() public static method

public static UrlEncodeJustBackslashes ( this s ) : string
s this
return string

WhenNullOrEmpty() public static method

public static WhenNullOrEmpty ( this original, string whenEmpty ) : string
original this
whenEmpty string
return string

format() public static method

Formats the specified format string.
public static format ( this formatString ) : string
formatString this The format string.
return string