Code Monkey home page Code Monkey logo

stickingplace's Introduction

Sticking Place

Macbeth:

If we should fail?

Lady Macbeth:

We fail?

But screw your courage to the sticking place,

And we'll not fail.

Sticking Place is yet another "junk drawer" C# library of useful extensions and helpers.

SqlHelpers

Helpers for ADO.NET/SQL

  • SqlExceptionHelper: Create SqlException objects with whatever message and error number you'd like. See SqlExceptionHelperTests for more information. This should only be used for testing, I can't think of a good reason to use it otherwise.

WebHelpers

Helpers for ASP.NET / ASP.NET MVC

  • HttpExtensions::SetAuthCookie: On the surface, it seems like Forms Auth only lets you put a string (username) into the auth cookie. You can put arbitrary objects in there, but you have to jump through some extra hoops to do it. SetAuthCookie jumps through the hoops.
  • HttpExtensions::GetAuthCookie: Get the arbitrary object back out of the Forms Auth cookie without all the hoop jumping.
  • ModelStateDictionaryExtensions::GetAllErrors: A convenience extension to walk through the whole MVC ModelState errors tree. Good for unit testing sometimes too.
  • HtmlHelperExtensions::ActionImage: A link with an image in it. You can specify routevalue and don't forget the alt!
  • HtmlHelperExtensions::IsSelected: In an ASP.NET View layout page, I will often have a bunch of nav links that need to be highlighted when the controller is "active". For instance, on a menu I have 3 links: "Home", "Invoices", "Locations", each going to an action in their respective controllers. When an action in the "Users" controller is executed, I want the "Users" link to be visually highlighted by putting a CSS class on the link. To make this easy, I'll use the IsSelected extension like below. ReSharper and/or Visual Studio may not be happy with it, but it's valid Razor. It assumes a default CSS class of "active", but you can pass in another one.
<ul class="nav navbar-nav">
    <li@(@Html.IsSelected("Home"))>@Html.ActionLink("Home", "Index", "Home")</li>` 
    <li@(@Html.IsSelected("Invoices"))>@Html.ActionLink("Invoices", "Index", "Invoices")</li>
    <li@(@Html.IsSelected("Locations"))>@Html.ActionLink("Locations", "Index", "Locations")</li>
</ul>
  • HtmlHelperExtensions::StateDropDownListFor, ProvicesDropDownListFor, TerritoriesDropDownListFor, StatesAndTerritoriesDropDownListFor, StatesAndProvincesDropDownListFor, StatesAndProvincesAndTerritoriesDropDownListFor: MVC Helpers to show dropdowns for U.S. States, Canadian provinces, and U.S. territories, and various permuations. Otherwise, it works just like Html.DropDownListFor. No offense intended to Canadians.
  • StatesProvincesTerritories: This is the source data used for all of the above, broken up into States (which included Washington D.C.), Provinces, and Territories.

StringHelpers

Helpers for string manipulation

LinqDatabaseHepers

Helpers for Linq providers (e.g. for OR/Ms)

  • IQueryableExtensions::OrderBy: Order a collection by a fieldname, specified by a string (ascending)
  • IQueryableExtensions::OrderByDescending: Order a collection by a fieldname, specified by a string (descending)
  • PredicateBuilder: A fluent way to build predicates using AND and (especially) OR that isn't supported by normal Linq extensions.

Roadmap

  • There is a really hacky unit test for Html::ActionImage that I only mostly understand. It could use improvement. Unit test organization in general could use some improvement.
  • I have some other mocking helpers that I use frequently with Telerik JustMock, but they aren't general enough (yet) to put in here.

Macbeth:

Away, and mock the time with fairest show.

False face must hide what the false heart doth know.

stickingplace's People

Contributors

mgroves avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.