checks for type null before deferencing it

The old code use accessed members of type before the check for null, which would result in a NullReferenceException. This change also removes the unnecessary `Func` object.
Merge pull request #3 from breyed/patch-2

checks for type null before deferencing it