CS CodeSmith Snippet of the Day

I know I should be able to crank out an instance of a custom Community Server Data Provider in my sleep, but I’m a wuss and find it tedious, even though we’re only talking about two lines of code.  I seem to have to type those two lines pretty frequently, too, so today I created a quick CodeSmith ActiveSnippet to do it for me.

DBVTDataProvider dp = DBVTDataProvider.Instance();
userPurchases = dp.GetUserPurchases(userID);

With my CodeSmith ActiveSnippet I type

dp userPurchases

then Ctrl-E, Ctrl-E and I have my instance code written up to the GetUserPurchases(userID) part.  A cool minor functional point about this snippet is that the cursor is at the end of “dp” when the snippet creates the code, so typing “.” with no additional cursor movement displays Intellisense right away.

 

 

The CodeSmith template has nothing interesting going on other than the logic to optionally return an object for those times I need to use an ExecuteNonQuery command.

 

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.