Geeks Research And eXplain

Grax Coding Blog

Advanced Coding Techniques Explained


Ridiculously Easy Scheduled Azure WebJobs
   If you are hosting on Azure, you might have been introduced to WebJobs. WebJobs are great for performing background or batch tasks.When you do a deployment of an Azure WebJob, the job will end up in your root-level site's App_Data/jobs folder. I use ... More

4 Steps to More Effective Meetings
   In my business, meetings are constantly happening. As a developer by nature, I tend to think I am not working when I am in a meeting but the truth is that these meetings are an essential part of the process.In order to have more effective meetings, ... More

Trimming all strings submitted to ASP.NET
   "Usernames cannot end with a space." You had the time to code that error message, but not the time to call trim()? @shanselman In my C#/ASP.NET applications, I add the following TrimModelBi ... More

OrderByString enables string search parameters in LINQ OrderBy clauses
   Here is something new to play with. I just released a package that adds commands for OrderBy that take strings for property name and direction.Usage is very flexible. Here are some of the different ways to use the new commands: .OrderBy("Property") ... More

fFastInjector 1.0.1 is here. Brace yourself!
   fFastInjector 1.0.1 is here! (I skipped the 1.0.0 release since that programs with that version number always seems to have problems.)fFastInjector is one of the fastest and smallest dependency injectors available for .NET. It is available as a por ... More

Sony Hacking: Who Screwed Up?
   TLDR: Sony's leadership is setting the security bar too low for a Fortune 500 company and the result is repeated embarrassing hack attacks.Perhaps now Sony will get the message that their information security needs a lot of improvement before it rise ... More

Use of unassigned local variable in C#
   Here is a simple tip that you may not have run across yet. TLDR: Initialize a variable to null to indicate to the compiler that you plan to assign it later.Suppose you have a situation where you need to create a variable but you will be assigning a v ... More
Keywords: C#, tidbit, TIL

String templating with Interpolation Format Provider
   So I wrote this other blog post about a templating pattern that I like for simplicity and that it is something I can remember. The response to it was somewhere between meh and ick but the resulting discussion gave me some ideas. (I'm still proud of ... More
Keywords: iformatprovider, string.format, template, tostring

Implementing INotifyPropertyChanged Manually Just Got A Little Easier
   Implementing INotifyPropertyChanged got a little easier in C# 5.0 in .NET 4.5. With the addition of the CallerMemberName attribute, you can stop using magic strings* to identify the property that is changing. Before the CallerMemberName attribute, ... More
Keywords: inotifypropertychanged

Combining Function Expressions in C# using a ReplacementVisitor
   When working with expressions, I often want to combine multiple expressions into one. Using a ReplacementVisitor enables me to do that.ReplacementVisitor is a memorable pattern* for C#. I first saw it somewhere on StackOverflow and I have started t ... More
Keywords: expressions, memorable patterns, TIL

Tiny Template Engine Pattern that you can probably Remember
   Edit: Updated with working code samples for JavaScript and C#. See also string interpolation.Let's say you have a bunch of property values and you need a simple template engine. Here is a fairly simple pattern that you can memorize to make a templa ... More
Keywords: memorable patterns, string interpolation, template, TIL

Safely deal with the impossible
   I wanted to point out this little hidden coding gem from Ted Neward's column in the September 2014 issue of MSDN Magazine. if (locAmt == remAmt) { ... } else if (locAmt < remAmt) { ... } else if (locAmt > remAmt) { ... } else throw ne ... More

Detecting infinite recursion
   TLDR: Use ThreadStatic static variables for a performant recursion test.As I was building fFastInjector, I found that it was fairly easy to create infinitely recursive configurations of the dependency injection. As fFastInjector examines a construct ... More

Windows Phone 8.1 Goodies
   Two of my favorite features in Windows Phone 8.1 are the hands-free texting and the Word Flow Keyboard.With hands-free texting, I can reply to an incoming text without touching or looking at my phone. I can send a new text by pressing two buttons an ... More
Keywords: windows phone, windows phone 8.1

T-SQL ForEach style loop
   Here is a simple pattern that I came up with for executing a ForEach style loop in t-sql against a set of data in T-SQL.declare @Enumerator table (id int)insert into @Enumeratorselect UserIdfrom Userswhere IsActive = 1 -- your query to select a list ... More
Keywords: sql server, tsql

CSS Gotchas - Part 2 - CSS Margin Height In Percent is Calculated Using the Width of the Parent Object
   TLDR: In CSS, when you specify margin height using a percentage, that height is calculated using that percentage against the width of the parent object. The only workaround that I have found, assuming you want the margin to be set to a percentage of ... More
Keywords: css, margin height

CSS Gotchas - Part 1
   TLDR: 2 CSS Gotchas today. First, the default CSS box model will cause an overflow if a box contains 2 boxes that are each set to 50% of the outer box's height or width if either of the boxes contain a margin, border, or padding. Second, if you are ... More
Keywords: box model, css

Debugging Visual Studio 2013 Code Coverage with ILSpy in under 2 minutes
   So I am working on getting 100% code coverage for my tests on fFastMapper (My tool to do high-speed, precompiled mapping between 2 objects). The following method is a single line and was being called in my tests. However, Visual Studio 2013's code ... More
Keywords: C#, code analysis, code coverage, ffastmapper, visual studio, visual studio 2013

Notes on Time Zones
   TLDR Version (Too Long Didn't Read Version)In your persistence medium, database or otherwise, convert all times to UTC before storing them, store all times as UTC, and convert on-the-fly to the user's local time zone when displaying. In order to con ... More
Keywords: any language, localization, time zone

Orlando's Giant Melrose Technology Center is a Maker's Paradise
   I just returned from my vacation to Orlando, Florida. This time we did things a little different and skipped the Disney and Universal parks. We visited some museums, Leu Gardens, Gatorland, the Merritt Island Manatee Overlook, and a couple of beach ... More

Get Rid of Bad Code once and for all with nDepend 5
   nDepend is a tool used for analyzing a .NET code base. It can find issues, track metrics, and create reports.nDepend version 5nDepend comes with a lot of rules for analyzing your code base. It comes with over 150 rules to check your code against in ... More
Keywords: C#, code analysis, ndepend

The Free Way Get Started In Programming
   At our recent Code Camp, our keynote speaker was Iris Classon. She told us the inspiring tale of her journey into software development. Several of her stories struck a chord with me and reminded me of some of my own experiences. One part that stoo ... More
Keywords:, azure, C#, free, visual studio

Better Array Fill Function
   So last week, +Michael Hsu visited my blog and took my array fill function and made it better.First, he turned it into an extension method and changed the signature so that the overload isn't needed. public static class ArrayExtensions { ... More

Female Code Camp Speakers?
   Yesterday was the first day of 4th annual Nebraska Code Camp. It is an opportunity for developers of all types to meet, learn, and network with each other.Today is the free portion of Code Camp. It is a totally free event. All people are welcome, ... More

On Success
   "... the strikingly successful groups in America today share three traits that, together, propel success. The first is a superiority complex — a deep-seated belief in their exceptionality. The second appears to be the opposite — insecurity, a feeling ... More
Keywords: success, what drives success

SubtractJS: The Video
   SubtractJS: The Video SubtractJS: The Web Page ... More

SubtractJS Update
   Some of you already know how amazing SubtractJS 1.0 is, but now I have something else to add to it. With SubtractJS 1.0.1, you can add an additional class "sj-margin-box-model" to make it easy to set up percentage-based sections. For example, here ... More

Announcing SubtractJS
   Quick Summary:SubtractJS is a layout assistant for HTML that makes it easy to mix fixed-width or fixed-height elements on the page edges with a re-sizable body. It is great for managing headers, footers, menu bars, navigation elements, or advertisin ... More

Buying and Updating My New Surface RT Tablet
   This has been a great year for me for getting new or updated electronic devices. When I saw the Black Friday special for the $199 Surface RT 32GB, I decided it was time to buy.Black Friday Online MadnessI started trying to order at 11 PM my time, wh ... More

Testing Custom LINQ Filter Operators (and LINQ Where clauses in general)
   Quick SummaryIn my last post, I outlined how to build a Custom LINQ Filter Operator. In this post I will demonstrate how to write a unit test for that filter operator. The same basic methodology can be used for testing Where clauses in general.We a ... More
Keywords: entity framework, filter methods, filter operators, idbset, linq, linq filters, tdd, unit test

Custom LINQ Filter Operators
   Generics, expressions, and extension methods are amazing features that open the doors to incredible new features and abilities in C# (and .NET in general).Quick SummaryUsing C# extension methods, we will rewrite commonly used Linq "where" clauses int ... More
Keywords: dry, filter methods, linq, linq filters

Response to fFastInjector concerns
   Below are some comments from Daniel de Palme's IOC Container performance benchmark and my responses. Post #48Something to notice about fFastInjector is that it is st ... More

Why is fFastInjector so fast? Is it thread-safe and otherwise safe?
   fFastInjector gets its speed from creative use of static variables within a generic static class, optimizer friendly coding, coding to do activities not related to the resolution outside of the resolution piece.Generic static variablesGeneric static ... More

Fast array fill function (revisited)
   Update: A reader ( +Michael Hsu ) posted a faster improved version at and I blogged about it at back at my fir ... More

Simple Strongly-Typed pattern for ViewData, Session, Request, etc
   Here is a simple pattern for setting up strongly-typed but flexible access to your ViewData, Session, and Request variables.If you have worked with jQuery much, you are familiar with the pattern of using "SomeMethod(value)" to set a value and "SomeMe ... More

How fast is fFastInjector?
   I downloaded Danial Palme's wonderful IoC Container Benchmark and added an adapter for my own fFastInjector. As you can see from the results, fFastInjector is clearly faster than all other IoC containers, even managing to beat Hiro, Munq, and Funq b ... More
Keywords: dependency injection, ffastinjector, ioc, ioc container, service locator

fFastInjector - World's Fastest Dependency Injector
   (2013-6-16: See updated lifestyle section for details on singleton lifestyle)What is it?fFastInjector is the world's fastest .NET dependency injector/service locator. In order to prove that it is the fastest, I downloaded the code that accompanies th ... More
Keywords: dependency injection, ioc, ioc container, service locator

Linking db2 to MS Sql Server
   My current project has a need to read and update DB2 data in addition to MS Sql Server data. The primary server is Sql Server, DB2 is additional. Our selected way of doing this is by creating a linked server on Sql Server (2008 R2). As you will se ... More
Keywords: db2, linked server, sql server

A FakeDbSet that implements IDbSet and uses IList for data manipulation
   Author's note: At some point, I managed to destroy all of the formatting for this post. The formatting should all be back now but you may not see the inline code. Still working out the way that works and that I like for posting code on my blog. +Sc ... More
Keywords: dbset, entity framework, idbset

Fun with Generic's Source Code
   Last night I gave a presentation about C# generics to the Lincoln .NET user's group. If you were there and want to see the code or if you weren't there and just want to see some interesting generic code, check out this source code. You will want to ... More

Generic TryParse, convert string to any type
   I came up with this nifty little extension method today. This method works in a similar fashion to TryParse but you can pass in any type. You may want to throw an exception if converter == null, as that means there is no converter available for the ... More

Announcing fFastMapper release 0.5.2
   Announcing fFastMapper release 0.5.2. Get fFastMapper from nuGet.fFastMapper is a component (like AutoMapper) to automatically copy values between objects of different types. The default mapping is based on a match of property name and property typ ... More
Keywords: automapper, ffastmapper, valueinjector

Announcing fFastMapper release 0.5
   (Sorry for any confusion. The name HyperMapper is trademarked by another organization, so I had to change it).fFastMapper is ready and available via NuGet. Use "Install-Package fFastMapper"fFastMapper is a component to map property values between ob ... More

Fun with C# Generics in Visual Studio 2010
   For those of you that need a Visual Studio 2010 version of the generics sample code from my Nebraska Code Camp presentation, you can download it from ... More

Code Camp Code for Fun with C# Generics
   The source code from my Nebraska Code Camp presentation on Fun with C# Generics can be downloaded from This is a Visual Studio 2012 project.The example code is in the Unit Tests project. Feel free to ask questions of me here ... More

Kinect sample code from Code Camp
   I have posted my code from Nebraska Code Camp. The most significant change is that I am using shaders to merge the multiple layers I am creating.The original way to merge the layers was using C# code and reviewing each pixel to determine whether it ... More
Keywords: code camp, graxark, kinect

Nebraska Code Camp
   Don't miss my Nebraska Code Camp session on Augmented Reality with Microsoft's Kinect for Windows. I will be talking about the commercial API for the Kinect. (The description was written before the commercial API was released)I will be presenting a ... More
Keywords: code camp, graxark, kinect

Working Kinect sample code available
   When the commercial API came out, I found that they had made quite a few changes. I am sure they are mostly good changes but they broke my previous sample code. Here is the new WPF sample code, unfortunately minus the special effects such as 3D fre ... More
Keywords: graxark, kinect

Kinect sample code available
   Here is the code the goes along with my January 25 presentation titled "Augmented Reality with the Kinect" at the Lincoln .NET Users Group.Remember to check the Kinect for Windows site to verify you have all of the system requirements.To get started ... More
Keywords: graxark, kinect

Specifying and using a WebResource to access embedded resources
   Adam Miller had a great post on this blog about returning an embedded resource in an aspx page. Since I have some experience with embedded resources, I wanted to share instructions to access embedded resources using the WebResource attribute.If you ... More
Keywords: embedded resource, webresource

Initialize an array to a value in C# very fast
   Update: I decided to revisit this with a new blog post.Updated Update: A reader ( +Michael Hsu ) posted a faster improved version at and I blogged about it at ... More
Keywords: arrray