Johnny Code
Fear no code

Extension Method

ASP.NET MVC Extension Method for the ID in the Route

By John Bubriski on November 9, 2011

If you’ve worked on an ASP.NET MVC site, you may have had to reference the ID in the current route.  In a Razor view you can reference it via the following variable: @Url.ViewContext.RouteData.Values["id"] You may use this a lot if you have a lot of inter-action navigation. Why not throw it into an extension method!? [...]

Posted in Programming | Tagged .NET Framework, ASP.NET, ASP.NET MVC, C#, Code, Extension Method | Leave a response

Batch Delete with the Entity Framework

By John Bubriski on March 12, 2010

There is a minor problem with the Entity Framework in that it doesn’t support certain batch operations. You can, of course, retrieve multiple rows at a time, and updates to tracked objects on a given data context can all be pushed back to the data store in a single SaveChanges() call. But what about adding [...]

Posted in Programming | Tagged batch, delete, entity-framework, Extension Method, SQL Server Compact 4 | 5 Responses

Can't use the same parameter list when creating Extension Methods

By John Bubriski on November 11, 2009

Everyone knows that you can’t create an extension method that uses the same name and parameter list as an existing method of the type your extending.  So for example, this method would be perfectly valid: public static string IsNullOrEmpty(this string text) { return string.IsNullOrEmpty(text); } Why?  Well, for one, the method parameters are different.  The [...]

Posted in Programming | Tagged Code, Extension Method | 3 Responses

Simple C# Extension Method to truncate a string, preserving the last word.

By John Bubriski on November 11, 2009

We needed to truncate a summary down to n number of characters to provide a uniform look and feel.  So I whipped up this extension method to take the current string and truncate to n characters, attach an ellipsis to the end, and optionally keep the last word of the string preserved.  In other words, [...]

Posted in Programming | Tagged C#, Code, Extension Method, Strings, Syntax Highlighting, wordpress | 2 Responses

About Me

I'm a Software Engineer at Worcester Envelope in Auburn, MA. Check out the About page to learn more about me.
Follow @JohnBubriski

Pages

  • About Me
  • Contact Me
  • Developer Resources
  • Kentico Resources
    • Kentico Tips and Tricks
    • Settings Module for Kentico CMS

What I’m Reading

  • The Quick Python Book, Second Edition
  • ASP.NET MVC 2 in Action
  • The Art of Unit Testing: With Examples in .Net
  • Code Complete: A Practical Handbook of Software Construction

My Recent Tweets

  • "Pumped Up Kicks" by #FosterThePeople actually has some twisted lyrics... 11 hours ago
  • @codeimpossible Last time I checked most weddings (and marriages) are not democratic in nature... 13 hours ago
  • New blog post: Get BizForm Record ID http://t.co/0wdZ8vAM 15 hours ago
  • @codeimpossible trying out preview/beta bits for vnext of ASPNET. Not as bad as I made it out to be, just frustrated by some changes. 1 day ago
  • @aschepis Thanks! 1 day ago

Tags

.NET Framework AES ASP.NET AspDotNetStoreFront blogging C# Code Code Camp Cryptography Decryption Elmah Encryption entity-framework Exceptions Extension Method HTML IIS IIS6 javascript jQuery Kentico API Programming Kentico BizForms Kentico CMS Learning Python 3 Microsoft PHP plugins Productivity Quick Tip random Return Values Shortcuts SQL SQLite Development Strings Symmetric Encryption Syntax Highlighting Time Saver Travian Add On Project URL Routing Using PyGame Visual Studio web-service Windows wordpress

Archives

  • 2012 (7)
  • 2011 (11)
  • 2010 (19)
  • 2009 (12)

Programming Blogs

  • Code: Impossible
  • Coding Horror
  • Self Elected
  • Stack Overflow

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Copyright © 2012 Johnny Code.

Powered by WordPress and Hybrid.

Maintained by John Bubriski