About

Camalot.Common contains extensions, objects and other methods that I found myself rewriting over and over. I made this library so I did not have to duplicate the code. You may find these useful, or you may not.



Nuget

PM> Install-Package Camalot.Common
PM> Install-Package Camalot.Common.Mvc5
PM> Install-Package Camalot.Common.Mvc4
PM> Install-Package Camalot.Common.Mvc


License



Documentation



Gets a configuration object from the configuration context.

Gets a configuration object from the configuration context.



Turns the byte array in to a Stream.

Turns the byte array in to a Stream.

Parameters

Name Description
writable then the stream is writable.

Turns the byte array in to a Stream.

Parameters

Name Description
index The index.
count The count.

Turns the byte array in to a Stream.

Parameters

Name Description
index The index.
count The count.
writable then the stream is writable.

Compresses the bytes using GZIP compression.

Compresses the stream using GZIP compression.

Compresses the bytes using GZIP compression.

Compresses the stream using GZIP compression.

Creates the instance.

Creates the instance.

Creates the instance.

Parameters

Name Description
args The arguments.

Creates the instance.

Parameters

Name Description
args The arguments.

Decompresses the GZIP byte array.

Decompresses the GZIP stream.

Decompresses the GZIP byte array.

Decompresses the GZIP stream.

just gets Epoch representation of DateTime

Gets the extension of the specified file.

Gets the type that the specified method is an extension method of.

Gets the first match group value.

Exceptions

Type Description
System.InvalidOperationException System.InvalidOperationException

Gets the first match group value.

Enumerate through each match. Automatically calls NextMatch for you.

Parameters

Name Description
action The action to execute on each match

Converts the ticks since Epoch to a date.

Reads the bytes of a file and returns the bytes.

Reads the bytes of a file and returns the bytes.

Parameters

Name Description
maxLength The maximum length of bytes to read.

Gets the bytes from the specified string.

Gets the bytes from the specified string.

Parameters

Name Description
encoding The encoding.

Gets the custom attribute.

Gets the custom attribute.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the custom attribute value.

Parameters

Name Description
expression The expression.

Gets the loadable types.

Gets the methods that have the specified return type.

Gets the methods that have the specified return type.

Parameters

Name Description
bindingFlags The binding flags.

Gets the mime type of the specified file using the specified FileTypeMap.

Gets the mime type of the specified file using the Default FileTypeMap.

Gets the string representation of the array of bytes.

Gets the string representation of the array of bytes.

Parameters

Name Description
encoding The encoding.

Gets the types that are assignable from TType.

Gets the types that are assignable from TType.

This sample shows AppDomain, but works the same for assemblies as well.

Determines whether the specified fields has attribute.

Determines whether the specified members has attribute.

Determines whether all the methods in the enumeration have the specified attribute.

Determines whether the all parameters in the enumeration have the specified attribute.

Determines whether the specified properties has attribute.

Determines whether the specified types has attribute.

Determines whether the specified field has attribute.

Determines whether the specified member has attribute.

Determines whether the method has the specified attribute.

Determines whether the parameter has the specified attribute.

Determines whether the specified property has attribute.

Determines whether the specified type has attribute.

Decodes the HTML encoded input string

Decodes the HTML encoded input string

Parameters

Name Description
output The output.

HTML encodes the input string

HTML encodes the input string

Parameters

Name Description
output The output.

Determines whether the Type is the specified type to check for.

Determines whether the Type is the specified type to check for.

Determines whether the specified date falls on the specified day of the week.

Parameters

Name Description
dow The day of the week.

Determines whether the specified unique identifier is empty.

Determines whether the specified date is the end of the accounting period (the last friday of the month).

Determines whether the specified method is extension of some type.

Determines whether the specified method is an extension method of the specified type.

Determines whether the specified string is match to the specified pattern.

Parameters

Name Description
pattern The pattern.

Determines whether the specified string is match to the specified pattern.

Parameters

Name Description
pattern The pattern.
options The options.

Determines whether the specified type is nullable.

Determines whether the specified type is primitive.

Determines whether the specified date is the same day as the utc date.

Parameters

Name Description
utcDate The UTC date.

Determines whether the specified date is today.

Determines whether the specified date is a week day.

Performs a Regular Expression Match.

Parameters

Name Description
pattern The pattern.

Performs a Regular Expression Match.

Parameters

Name Description
pattern The pattern.
options The options.

Gets the file name without extension.

Returns the object or the specified value object if null (or empty).

Parameters

Name Description
value The value.

Returns the guid or the specified value guid if empty.

Parameters

Name Description
value The value.

Returns the object or the specified value object if null (or empty).

Parameters

Name Description
value The value.

Returns the object or the specified value object if null (or empty).

Parameters

Name Description
value The value.

Returns the string or the specified value if null (or empty).

Parameters

Name Description
value The value.

Gets the fully qualified name of the type

Renames the specified file.

Parameters

Name Description
fileName Name of the file. If it does not contain an extension, it will use the old extension.

Does a Regex Replace on the string based on the specified pattern and the specified replacement.

Parameters

Name Description
pattern The pattern.
evaluator The evaluator.

Does a Regex Replace on the string based on the specified pattern and the specified replacement.

Parameters

Name Description
pattern The pattern.
replacement The replacement.
options The options.

Does a Regex Replace on the string based on the specified pattern and the specified evaluator.

Parameters

Name Description
pattern The pattern.
options The options.
evaluator The evaluator.

Requires the specified object to have a value.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Parameters

Name Description
message The message.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Parameters

Name Description
message The message.

Requires the specified object to have a value.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified nullable object to have a value.

Parameters

Name Description
message The message.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Parameters

Name Description
message The message.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified object to have a value.

Parameters

Name Description
message The message.

Exceptions

Type Description
System.ArgumentException System.ArgumentException

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be between the high and low.

Parameters

Name Description
low The low.
high The high.
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{2}' must be a value between {0} and {1}.With ( low, high, i )

Requires the specified number to be a negative value.

Requires the specified number to be a negative value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a negative value.

Requires the specified number to be a negative value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a negative value.

Requires the specified number to be a negative value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a negative value.

Requires the specified number to be a negative value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a negative value.

Requires the specified number to be a negative value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a negative value.

Requires the specified number to be a negative value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a positive value.

Requires the specified number to be a positive value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a positive value.

Requires the specified number to be a positive value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a positive value.

Requires the specified number to be a positive value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a positive value.

Requires the specified number to be a positive value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a positive value.

Requires the specified number to be a positive value.

Parameters

Name Description
param The parameter.

Requires the specified number to be a positive value.

Requires the specified number to be a positive value.

Parameters

Name Description
param The parameter.

Requires the specified number to be zero.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Parameters

Name Description
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Parameters

Name Description
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Parameters

Name Description
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero.With ( i )

Requires the specified number to be zero.

Parameters

Name Description
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Parameters

Name Description
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Requires the specified number to be zero.

Parameters

Name Description
param The parameter.

Exceptions

Type Description
System.ArgumentException value '{0}' must zero..With ( i )

Does a Regex Replace on the specified string based on the specified pattern and replacement.

Parameters

Name Description
pattern The pattern.
replacement The replacement.

Does a Regex Replace on the string based on the specified pattern and the specified evaluator.

Parameters

Name Description
pattern The pattern.
evaluator The evaluator.

Does a Regex Replace on the specified string based on the specified pattern and replacement.

Parameters

Name Description
pattern The pattern.
replacement The replacement.
options The options.

Does a Regex Replace on the string based on the specified pattern and the specified evaluator.

Parameters

Name Description
pattern The pattern.
options The options.
evaluator The evaluator.

Rounds a datetime down to the time span.

Parameters

Name Description
d The timespan.

Rounds a datetime up to the time span

Parameters

Name Description
d The timespan.

Gets a single match group.

Exceptions

Type Description
System.InvalidOperationException System.InvalidOperationException

Gets a single match group or a default if no match.

Splits the string based on the specified separator and trims each item.

Parameters

Name Description
separator The separator.

Splits the string based on the specified separator and trims each item.

Parameters

Name Description
separator The separator.
options The options.

Converts the byte array to a base64 encoded string.

Base64 Encodes the specified string.

Base64 Encodes the specified string.

Parameters

Name Description
encoding The encoding.

Gets the byte array from a stream.

Gets the byte array from a stream.

Converts the objects string representation to camelCase.

Converts the objects string representation to camelCase.

Transforms HTML hexadecimal string (#FFFFFF) in to a Color object

Exceptions

Type Description
System.ArgumentException Unexpected html color string format.

Converts the string to an SHA1 hash

This is the equivalent of <code>CAST(HASHBYTES('SHA1', RTRIM(LTRIM(LOWER([COLUMN_NAME])))) AS VARBINARY(20))</code> in TSQL.

To the friendly string.

Converts the byte array to a hexadecimal string.

Converts the byte array to a hexadecimal string.

Transforms the Color to an HTML hexadecimal string (#FFFFFF).

To the kind.

Parameters

Name Description
kind The kind.

Converts the objects string representation to PascalCase.

To the short friendly string.

Returns a string representation of the time

Returns the ticks since Epoch

Exceptions

Type Description
System.ArgumentOutOfRangeException System.ArgumentOutOfRangeException

Decodes a url encoded input string

Url encodes the input string

Sets the source string format with the values passed as arguments

Parameters

Name Description
args The arguments.

Sets the source string format with the values passed as arguments

Parameters

Name Description
culture The culture info .
args The arguments.

Gets all types that have the specified attribute

Gets field info that have the specified attribute

Gets member info that have the specified attribute

Gets method info that have the specified attribute

Gets module info that have the specified attribute

Gets parameter info that have the specified attribute

Gets property info that have the specified attribute

Gets types that have the specified attribute

Gets all types that have the specified attribute

This sample shows AppDomain, but works the same for assemblies as well.


A default file type map handler.

Gets the default file type map.

Gets the default mimetype if it is unknown.

Gets all MimeTypes.

Gets the mime type of the file.

Parameters

Name Description
file The file.

Gets the mime type of the file.

Parameters

Name Description
fileName Name of the file.

This reads http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types and builds a list of mimeTypes that can be queried against.

References

Gets all MimeTypes.

Gets the mime type of the file.

Parameters

Name Description
file The file.

References

Gets the mime type of the file.

Parameters

Name Description
fileName Name of the file.

References

Represents a Mime Type

Gets or sets the extensions.

Gets or sets the type of the media.

Reads the system registry for information on the mime types of a file.

Gets all MimeTypes that are registered.

Gets the mime type of the file.

Parameters

Name Description
file The file.

Gets the mime type of the file.

Parameters

Name Description
fileName Name of the file.


Converts Guids when Reading/Writing JSON

Converts Html Colors when reading / writing JSON.

Converts DateTime to Unix DateTime when reading / writing JSON.



A JSON Serialization Builder

Builds this instance.

Creates this instance.

An Xml Serialization Builder

Adds the type to the builder for a supported serialization type.

Adds the type to the builder for a supported serialization type.

Parameters

Name Description
type The type.

Start the building of the Xml Serializer

Start the building of the Xml Serializer

Parameters

Name Description
type The type.

Creates an instance of an XML Serializer with the options set from the builder.

Sets the default xml namespace.

Parameters

Name Description
ns The namespace to set as the default.