About

SubSonic is a .net open source project developed by Rob Conery and a core team of developers including Eric Kemp, Scott Watermasysk, Jon Galloway, Phil Haack, and Gavin Joyce. The current stable release is version 2.0.3. Nightly builds are available in our SVN respository.

Tags

The Sugar Namespace

SubSonic.Sugar is a Utility Class that is our attempt at refactoring the main Utility class that we've been using over the last year, and rather than keep it to ourselves, we thought "why not share with the lovely people". It's also tons of useful utility classes that we think you'll use a lot of.

File Operations:

Files.GetFileText(System.String):
Read a text file and obtain it's contents.
Files.CreateToFile(System.String,System.String):
Creates or opens a file for writing and writes text to it.
Files.UpdateFileText(System.String,System.String,System.String):
Update text within a file by replacing a substring within the file.
Files.WriteToFile(System.String,System.String):
Writes out a string to a file.

Dates and Date Math

Dates.DaysAgo(System.Int32):
Days the ago.
Dates.DaysFromNow(System.Int32):
Days from now.
Dates.HoursAgo(System.Int32):
Hours the ago.
Dates.HoursFromNow(System.Int32):
Hours from now.
Dates.MinutesAgo(System.Int32):
Minutes the ago.
Dates.MinutesFromNow(System.Int32):
Minutes from now.
Dates.SecondsAgo(System.Int32):
Seconds the ago.
Dates.SecondsFromNow(System.Int32):
Seconds from now.
Dates.Diff(System.DateTime,System.DateTime):
Diffs the specified date one.
Dates.DiffDays(System.String,System.String):
Diffs the days.
Dates.DiffDays(System.DateTime,System.DateTime):
Diffs the days.
Dates.DiffHours(System.String,System.String):
Diffs the hours.
Dates.DiffHours(System.DateTime,System.DateTime):
Diffs the hours.
Dates.DiffMinutes(System.String,System.String):
Diffs the minutes.
Dates.DiffMinutes(System.DateTime,System.DateTime):
Diffs the minutes.
Dates.ReadableDiff(System.DateTime,System.DateTime):
Displays the difference in time between the two dates. Return example is "12 years 4 months 24 days 8 hours 33 minutes 5 seconds"
Dates.CountWeekdays(System.DateTime,System.DateTime):
Counts the number of weekdays between two dates.
Dates.CountWeekends(System.DateTime,System.DateTime):
Counts the number of weekends between two dates.
Dates.IsDate(System.Object):
Verifies if the object is a date
Dates.IsWeekDay(System.DateTime):
Checks to see if the date is a week day (Mon - Fri)
Dates.IsWeekEnd(System.DateTime):
Checks to see if the date is Sat or Sunday
Dates.TimeDiff(System.DateTime,System.DateTime):
Displays the difference in time between the two dates. Return example is "12 years 4 months 24 days 8 hours 33 minutes 5 seconds"
Dates.GetFormattedMonthAndDay(System.DateTime):
Given a datetime object, returns the formatted month and day, i.e. "April 15th"
Dates.GetDateDayWithSuffix(System.DateTime):
Given a datetime object, returns the formatted day, "15th"

String Fun

Strings.Chop(System.String,System.Int32):
Strips the last specified chars from a string.
Strings.Chop(System.String,System.String):
Strips the last specified chars from a string.
Strings.Clip(System.String,System.Int32):
Removes the specified chars from the beginning of a string.
Strings.Clip(System.String,System.String):
Removes chars from the beginning of a string, up to the specified string
Strings.Chop(System.String):
Strips the last char from a a string.
Strings.Clip(System.String):
Strips the last char from a a string.
Strings.Crop(System.String,System.String,System.String):
Returns text that is located between the startText and endText tags.
Strings.Squeeze(System.String):
Removes excess white space in a string.
Strings.ToWords(System.String):
Creates a string array based on the words in a sentence
Strings.StripHTML(System.String):
Strips all HTML tags from a string
Strings.StripHTML(System.String,System.String):
Strips all HTML tags from a string and replaces the tags with the specified replacement
Strings.ToProper(System.String):
Convert string to proper case
Strings.CamelToProper(System.String):
Camels to proper.
Strings.PluralToSingular(System.String):
Plurals to singular.
Strings.SingularToPlural(System.String):
Singulars to plural.
Strings.Strip(System.String,System.String):
Strips the specified input.
Strings.StripNonAlphaNumeric(System.String):
Replaces most non-alpha-numeric chars
Strings.AsciiToUnicode(System.Int32):
Converts ASCII encoding to Unicode
Strings.TextToEntity(System.String):
Converts Text to HTML-encoded string
Strings.EntityToText(System.String):
Converts HTML-encoded bits to Text

Web Utility

Web.QueryString<>(System.String):
Queries the string.
Web.Cookie<>(System.String):
Cookies the specified param.
Web.SessionValue<>1(System.String):
Sessions the value.
Web.ReadWebPage(System.String):
Fetches a web page
Web.DNSLookup(System.String):
Gets DNS information about a url and puts it in an array of strings
Web.ScrapeImages(System.String):
Scrapes the image tags from a given URL
Web.ScrapeLinks(System.String,System.Boolean):
Scrapes a web page and parses out all the links.
Web.GetGravatar(System.String,System.Int32):
Calls the Gravatar service to and returns an HTML tag for use on your pages.
Web.CreateSpamFreeEmailLink(System.String):
Given a valid email address, returns a short javascript block that will emit a valid mailto: link that can't be picked up by address harvesters. Call this method where you would normally place the link in your html code.
Web.IsLocalNetworkRequest:
Whether or not the request originated from the local network, or more specifically from localhost or a NAT address. This property is only accurate if NAT addresses are a valid indicators of a request being from within the internal network.

Validation

Validation.IsAlpha(System.String):
Determines whether the specified eval string contains only alpha characters.
Validation.IsAlphaNumeric(System.String):
Determines whether the specified eval string contains only alphanumeric characters
Validation.IsEmail(System.String):
Determines whether the specified email address string is valid based on regular expression evaluation.
Validation.IsLowerCase(System.String):
Determines whether the specified string is lower case.
Validation.IsUpperCase(System.String):
Determines whether the specified string is upper case.
Validation.IsGuid(System.String):
Determines whether the specified string is a valid GUID.
Validation.IsZIPCodeAny(System.String):
Determines whether the specified string is a valid US Zip Code, using either 5 or 5+4 format.
Validation.IsZIPCodeFive(System.String):
Determines whether the specified string is a valid US Zip Code, using the 5 digit format.
Validation.IsZIPCodeFivePlusFour(System.String):
Determines whether the specified string is a valid US Zip Code, using the 5+4 format.
Validation.IsSocialSecurityNumber(System.String):
Determines whether the specified string is a valid Social Security number. Dashes are optional.
Validation.IsIPAddress(System.String):
Determines whether the specified string is a valid IP address.
Validation.IsUSState(System.String):
Determines whether the specified string is a valid US state either by full name or two letter abbreviation.
Validation.IsUSTelephoneNumber(System.String):
Determines whether the specified string is a valid US phone number using the referenced regex string.
Validation.IsUSCurrency(System.String):
Determines whether the specified string is a valid currency string using the referenced regex string.
Validation.IsURL(System.String):
Determines whether the specified string is a valid URL string using the referenced regex string.
Validation.IsStrongPassword(System.String):
Determines whether the specified string is consider a strong password based on the supplied string.
Validation.IsCreditCardAny(System.String):
Determines whether the specified string is a valid credit, based on matching any one of the eight credit card strings
Validation.IsCreditCardBigFour(System.String):
Determines whether the specified string is an American Express, Discover, MasterCard, or Visa
Validation.IsCreditCardAmericanExpress(System.String):
Determines whether the specified string is an American Express card
Validation.IsCreditCardCarteBlanche(System.String):
Determines whether the specified string is an Carte Blanche card
Validation.IsCreditCardDinersClub(System.String):
Determines whether the specified string is an Diner's Club card
Validation.IsCreditCardDiscover(System.String):
Determines whether the specified string is a Discover card
Validation.IsCreditCardEnRoute(System.String):
Determines whether the specified string is an En Route card
Validation.IsCreditCardJCB(System.String):
Determines whether the specified string is an JCB card
Validation.IsCreditCardMasterCard(System.String):
Determines whether the specified string is a Master Card credit card
Validation.IsCreditCardVisa(System.String):
Determines whether the specified string is Visa card.
Validation.CleanCreditCardNumber(System.String):
Cleans the credit card number, returning just the numeric values.
Validation.CreditPassesFormatCheck(System.String):
Determines whether the credit card number, once cleaned, passes the Luhn algorith. See: http://en.wikipedia.org/wiki/Luhn_algorithm
Validation.IsValidLuhn(System.Int32[]):
Determines whether the specified int array passes the Luhn algorith

Numbers

Numbers.IsNaturalNumber(System.String):
Determines whether [is natural number] [the specified s item].
Numbers.IsWholeNumber(System.String):
Determines whether [is whole number] [the specified s item].
Numbers.IsInteger(System.String):
Determines whether the specified s item is integer.
Numbers.IsNumber(System.String):
Determines whether the specified s item is number.
Numbers.IsEven(System.Int32):
Determines whether the specified value is an even number.
Numbers.IsOdd(System.Int32):
Determines whether the specified value is an odd number.
Numbers.Random(System.Boolean):
Generates a random number
Numbers.Random(System.Int32):
Generates a random number with an upper bound
Numbers.Random(System.Int32,System.Int32):
Generates a random number between the specified bounds
Numbers.Random:
Generates a random double

Subscribe