This project has moved and is read-only. For the latest updates, please go here.
Utilities class for .Net including Dynamic property getters/setters, automatic IQueryable searching, LinqToSql shortcuts, FileStream shortcuts, String extensions and more.

Naspinski.Utilities is now available via NuGet!

PM> Install-Package Naspinski.Utilities


Change a property value at run time without knowing the property ahead of time
  • someObject.SetPropertyValue("Name", "new value") is the same as someObject.Name = "new value"; - no need to know which property to code in

More Information:


Search all/any properties of an IQueryable with one single search.

The 'quick search' is a great tool. Google has shown us that searching with one single, universal search field is the way that people prefer to search. Anyone who has worked with Linq for any amount of time knows this is possible, but it requires a lot of hard-coding and a long jumble of 'where' statements. This class will allow you to run a universal 'google-like' search on any IQueryable.

More Information:


Universal Get Extensions for your DataContexts, Find the Primary Key of any table, and more
  • GetPrimaryKey will get the primary key of any Linq-to-SQL table
    • Naspinski.Utilities.GetPrimaryKey<table>() will return the PropertyInfo of the Primary Key(s) of 'table'
  • someDataContext.Get is a generic Get accessor for all of your tables
    • someDataContext.Get<Car>(someKey) is the same as writing someDataContext.Cars.FirstOrDefault(x => == someKey) regardless of what Type someKey is or what the PropertyInfo.Name of the Primary Key is; never write a Get accessor again!


Simple extension to save a FileStream to disk, option to avoid overwriting will automatically update the filename to avoid overwriting
  • someFileStream.Save(@"C:\file.txt") will save the file to the given path, or save as 'file[1].txt' if the file is already there (file[2].txt if that is there and so on); the file name will be returned
  • someFileStream.Save(@"C:\file.txt", false) will save the file to the given path, overwriting if the file already exists


Convert strings to things you often need to convert them to... easily
  • RemoveCharacters removes any instances of a character array
  • Strings.Random creates a random string with lower and upper limits of special characters
  • To turns a string into any Type
  • ToEnum turns a string into an Enum... simple!
  • ToNullable turns a string into any Nullable Type you want

Last edited Nov 11, 2016 at 3:02 AM by naspinski, version 37