Be careful when calling GetType() on dynamic proxies
In case of [dynamic proxies](http://kozmic.pl/dynamic-proxy-tutorial/), it’s logical that `Object.GetType()` will return proxy type instead of original type. But it’s easy to overlook. For instance, if you retrieve `Foo` using Entity Framework (if you don’t know, EF can use proxies for lazy loading and change tracking), then `foo.GetType()` will return something like `System.Data.Entity.DynamicProxies.Foo_ !!!AE29723B5A3610FEA8D1964644C9B1B577178022056E8576B7BAA9E4B32DE05D!!!` (without exclamation marks which I added to boost effect) instead of just `Foo`. So let’s say you need to know what is exactly the original type and you are not using `is` operator. See `DoSomething` body: Foo foo = GetWithEF(); DoSomething(foo); private void DoSomething(BaseThing thing) { dictionary[thing.GetType()] } If `foo` is dynamic proxy, this will not work if you are looking for `Foo` type in `dictionary`. If you ask me, the simplest solution is to use generics: Foo foo = GetWithEF(); DoSomething(foo); private void DoSomething(T thing) where T : BaseThing { dictionary[typeof(T)] } As you can see, you don’t have to explicitly set type parameter when calling `DoSomething`, hence code which is calling `DoSomething` stays unchanged here.













