LanguageExtensions

Provides for commons language types.

Namespace:
Inetdev
Type:
Class
Public:
Yes
Protected:
No
Sealed:
Yes
Abstract:
Yes
Inherits from:
System.Object

Methods

Ellipse

Cut the string if it is larger than 20 characters adding an ellipse at the end.

Signature:
public String Ellipse(text)
Parameters
Name Type Summary
text String Text to ellipse.

Ellipse

Cut the string if it is larger than the maxLength adding an ellipse at the end.

Signature:
public String Ellipse(text, maxLength)
Parameters
Name Type Summary
text String Text to ellipse.
maxLength Int32 Maximum length of the returned string.

EnsureTrailingSlash

Ensures that the text ends with a slash.

Signature:
public String EnsureTrailingSlash(text)
Parameters
Name Type Summary
text String A text to process.

GetPropertiesWithAttribute

Returns a collection of properties that have the specified attribute.

Signature:
public IEnumerable<PropertyInfo> GetPropertiesWithAttribute<T>(type)
Returns

An enumeration of PropertyInfo objects.

Parameters
Name Type Summary
type Type The type to be scanned.

GetPropertyWithAttribute

Returns the first property that has the specified attribute.

Signature:
public PropertyInfo GetPropertyWithAttribute<T>(type)
Parameters
Name Type Summary
type Type The type to be scanned.

GetPropertyWithAttributeAssignableFrom

Returns the first property that has the specified attribute if it is assignable from the specified type.

Signature:
public PropertyInfo GetPropertyWithAttributeAssignableFrom<T>(type, assignableFrom)
Parameters
Name Type Summary
type Type The type to be scanned.
assignableFrom Type Type from which teh attribute must be assignable from.

GetSchemeHostAndPath

Gets the scheme host and path of the Uri.

Signature:
public String GetSchemeHostAndPath(uri)
Returns

The scheme and host from the Uri.

Parameters
Name Type Summary
uri Uri An Uri.

HexStringToByteArray

Converts a string in hexadecimal format into a byte array.

Signature:
public Byte[] HexStringToByteArray(input)
Returns

A byte array for the specified input.

Parameters
Name Type Summary
input String A hexadeciamal text to process.
Exceptions
Type Summary
ArgumentException Thrown then the length of the input is not multiple of 2.

Initials

Returns the first letter of the first and last word in value.

Signature:
public String Initials(value)
Returns

The upper case of the first letter from the first and last word of value.

Parameters
Name Type Summary
value String A space separated value.

RemoveAccent

Remove accents from the phrase.

Signature:
public String RemoveAccent(phrase)
Parameters
Name Type Summary
phrase String A phrase to remove the accent characters.
Exceptions
Type Summary
ArgumentNullException Thrown when phrase is null.

RemoveTrailingSlash

Remove all trailing slashes from the text.

Signature:
public String RemoveTrailingSlash(text)
Parameters
Name Type Summary
text String A text to process.

Replace

Replaces curly braces placeholder within the string, with the ToString() result from the values of the specified dictionary.

Placeholder must by in the format: {Key}.

Signature:
public String Replace(value, values)
Parameters
Name Type Summary
value String A curly braces tagged text.
values IDictionary<String, Object> A dictionary with replacement values.

Replace

Replaces curly braces placeholder within the string with the ToString() result from the values of the specified object.

Placeholder must by in the format: {PropertyName}.

Signature:
public String Replace(value, values)
Parameters
Name Type Summary
value String A curly braces tagged text.
values Object A dictionary with replacement values.

SplitAndTrim

Split a comma separated string and trim each individual value, empty strings won't be added to the array.

Signature:
public String[] SplitAndTrim(value)
Parameters
Name Type Summary
value String A text value to be splitted.

SplitAndTrim

Split a comma separated string and trim each individual value, empty strings won't be added to the array.

Signature:
public String[] SplitAndTrim(value, separator)
Parameters
Name Type Summary
value String A text value to be splitted.
separator Char[] The separator to split the text with.

ToDictionary

Maps a generic object to a key/value dictionary.

Signature:
public IDictionary<String, Object> ToDictionary(values)
Returns

A string/object dictionary with an element for each object property.

Parameters
Name Type Summary
values Object An object to be converted.

ToSlug

Generate a slug from the phrase.

Signature:
public String ToSlug(phrase)
Returns

A lower case phrase with:

- underscores and dots replaced with dashes.

- slashes replaced with dashes.

- non alpha-numeric characters removed.

- spaces trimmed and replaced with dashes.

Parameters
Name Type Summary
phrase String A phrase to be slugged.

ToSpaceSeparatedString

Converts the list to a space separated string.

Signature:
public String ToSpaceSeparatedString(list)
Parameters
Name Type Summary
list IEnumerable<String> A list to join into a string.

ToStream

Turns the string into a stream.

Signature:
public Stream ToStream(value)
Parameters
Name Type Summary
value String A string to be converted into a stream.

Truncate

Truncates the milliseconds of a DateTime.

Signature:
public DateTime Truncate(dateTime)
Returns

A truncated DateTime.

Parameters
Name Type Summary
dateTime DateTime A DateTime to be truncated.

Truncate

Trunctates a DateTime to a specified resolution.

Signature:
public DateTime Truncate(dateTime, resolution)
Returns

A truncated DateTime.

Example
myDate.Truncate(TimeSpan.TicksPerSecond); // truncates the milliseconds myDate.Truncate(TimeSpan.TicksPerMinute); // truncates the seconds
Parameters
Name Type Summary
dateTime DateTime A DateTime to be truncated.
resolution Int64 The required truncation resolution.