C# Class ClrPlus.Core.Extensions.StringExtensions

Extensions for strings. Whheeee
Afficher le fichier Open project: perpetual-motion/clrplus

Méthodes publiques

Méthode 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

Méthode 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 méthode

public static CamelCaseToDashed ( this camelCaseText, char separator = '-' ) : string
camelCaseText this
separator char
Résultat string

Contains() public static méthode

public static Contains ( this text ) : bool
text this
Résultat bool

ContainsAllAsWildcards() public static méthode

public static ContainsAllAsWildcards ( this source ) : bool
source this
Résultat bool

ContainsAnyAsWildcards() public static méthode

public static ContainsAnyAsWildcards ( this source ) : bool
source this
Résultat bool

ContainsIgnoreCase() public static méthode

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

CreateGuid() public static méthode

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

CreatePublicKeyToken() public static méthode

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

DashedToCamelCase() public static méthode

public static DashedToCamelCase ( this dashedText, char separator = '-' ) : string
dashedText this
separator char
Résultat string

DashedToPascalCase() public static méthode

public static DashedToPascalCase ( this dashedText, char separator = '-' ) : string
dashedText this
separator char
Résultat string

EmptyAsNull() public static méthode

public static EmptyAsNull ( this str ) : string
str this
Résultat string

EqualsEx() public static méthode

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
Résultat bool

Error() public static méthode

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

FormatWithMacros() public static méthode

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
Résultat string

GetKeyTokenFromFullKey() public static méthode

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

Gunzip() public static méthode

Gunzips the specified input.
public static Gunzip ( this input ) : string
input this The input.
Résultat string

GunzipFromBase64() public static méthode

Gunzips from base64.
public static GunzipFromBase64 ( this input ) : string
input this The input.
Résultat string

Gzip() public static méthode

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

GzipToBase64() public static méthode

Gzips to base64.
public static GzipToBase64 ( this input ) : string
input this The input.
Résultat string

HasWildcardMatch() public static méthode

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.
Résultat bool

HasWildcards() public static méthode

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

HtmlDecode() public static méthode

decodes an HTML encoded string
public static HtmlDecode ( this s ) : string
s this The string
Résultat string

HtmlEncode() public static méthode

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

IfNullOrEmpty() public static méthode

public static IfNullOrEmpty ( this text, string defaultText ) : string
text this
defaultText string
Résultat string

Is() public static méthode

public static Is ( this str ) : bool
str this
Résultat bool

IsBoolean() public static méthode

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

IsEmail() public static méthode

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

IsFalse() public static méthode

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

IsMultiline() public static méthode

public static IsMultiline ( this text ) : bool
text this
Résultat bool

IsNegative() public static méthode

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.
Résultat bool

IsPositive() public static méthode

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.
Résultat bool

IsTrue() public static méthode

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

IsWebUri() public static méthode

public static IsWebUri ( this text ) : bool
text this
Résultat bool

MD5Hash() public static méthode

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
Résultat string

MakeAttractiveFilename() public static méthode

public static MakeAttractiveFilename ( this input ) : string
input this
Résultat string

MakeSafeDirectoryId() public static méthode

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

MakeSafeFileName() public static méthode

public static MakeSafeFileName ( this input ) : string
input this
Résultat string

Match() public static méthode

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

MatchIgnoreCase() public static méthode

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

NewIsWildcardMatch() public static méthode

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
Résultat bool

OnlyContains() public static méthode

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.
Résultat bool

OnlyContains() public static méthode

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.
Résultat bool

PositionOfFirstCharacterNotIn() public static méthode

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.
Résultat int

PositionOfFirstCharacterNotIn() public static méthode

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.
Résultat int

ProtectBinaryForMachine() public static méthode

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.
Résultat IEnumerable

ProtectBinaryForUser() public static méthode

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.
Résultat IEnumerable

ProtectForMachine() public static méthode

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.
Résultat IEnumerable

ProtectForUser() public static méthode

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.
Résultat IEnumerable

Replace() public static méthode

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
Résultat string

StartsWithNumber() public static méthode

public static StartsWithNumber ( this str ) : bool
str this
Résultat bool

ToByteArray() public static méthode

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

ToHexString() public static méthode

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

ToInt32() public static méthode

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

ToInt32() public static méthode

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.
Résultat int

ToSecureString() public static méthode

public static ToSecureString ( this password ) : SecureString
password this
Résultat System.Security.SecureString

ToUnsecureString() public static méthode

public static ToUnsecureString ( this securePassword ) : string
securePassword this
Résultat string

ToUri() public static méthode

public static ToUri ( this stringUri ) : Uri
stringUri this
Résultat System.Uri

ToUtf8String() public static méthode

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

UnprotectBinaryForMachine() public static méthode

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.
Résultat IEnumerable

UnprotectBinaryForUser() public static méthode

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.
Résultat IEnumerable

UnprotectForMachine() public static méthode

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.
Résultat string

UnprotectForUser() public static méthode

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.
Résultat string

UrlDecode() public static méthode

decodes the URL encoded string
public static UrlDecode ( this s ) : string
s this The s.
Résultat string

UrlEncode() public static méthode

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

UrlEncodeJustBackslashes() public static méthode

public static UrlEncodeJustBackslashes ( this s ) : string
s this
Résultat string

WhenNullOrEmpty() public static méthode

public static WhenNullOrEmpty ( this original, string whenEmpty ) : string
original this
whenEmpty string
Résultat string

format() public static méthode

Formats the specified format string.
public static format ( this formatString ) : string
formatString this The format string.
Résultat string