Adding IN Search Functionality To .NET

Jay Robinson shows off a few extension methods he creates to make dealing with C# easier:

Then I could use the extension like this:

if (mySeries.In(Enum.Series.ProMazda, Enum.Series.Usf2000)) myChassis = "Tatuus";

As for the other two methods, well… When is a null not a null? When it’s a System.DBNull.Value, of course! SQL Server pros who have spent any time in the .NET Framework will recognize this awkwardness:

var p = new System.Data.SqlClient.SqlParameter("@myParam", System.Data.SqlDbType.Int);
p.Value = (object)myVar ?? System.DBNull.Value;

With the extension, the second line becomes:

p.Value = mVar.ToDbNull();

I like it that Jay ended up going with a different language than T-SQL.  It’s no F#, but it’ll do.

Related Posts

Monads and Monoids and Functors

Anmol Sarna explains the concept of a monad: In functional programming, a monad is a design pattern that allows structuring programs generically while automating away boilerplate code needed by the program logic. To simplify the above definition a bit more, We can think of monads as wrappers. You just take an object and wrap it with […]

Read More

T-SQL Tuesday 113 Roundup

Todd Kleinhans takes us through T-SQL Tuesday #113: Wow, we had a variety of responses to the April 2019 topic of “What Do YOU Use Databases For?” I think the overall response to the question and the theme is both mixed and varied. I have been struggling with the personal use of databases for a […]

Read More

Categories

July 2018
MTWTFSS
« Jun Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031