Wednesday, January 31, 2007

During my investigation of how and what of AutoGenerateColumns in GridView in my recent articles, I had a need to check if a type is a Nullable type. I have used reflector to search for a siutable method, but I haven't found one. What I have found though was a strange class: System.Internal. It is internal so it is not accessible outside its assembly, but nevertheless I find it worth mentioning because of its contents.

The class has 3 methods that make me think:

  • CommonlyUsedGenericInstantiations_HACK()
  • NullableHelper_HACK<T>()
  • SZArrayHelper_HACK<T>()

Just by looking at the names I can tell that there is something about them, that is not your usual BCL code :-)

When I have looked inside the first one of those methods I have found a lot of code that only instanties Generic type objects such as List<T> where T is bool, int, Guid etc. The second method on the other hand calls Compare<T> and Equals<T>.

Why is that? In my opinion, all the operations there are perfoemed to improve performance of some code. By doing the operations in a batch, once, at some point in time, we do not risk the JIT compiler compiling every generic class and every generic method on demand later. If this really helps or is useful? I don't know, but MS has done it and I usually do not believe in "random code". Maybe there are some performance considerations in some scenarios that require the HACK approach? I haven't been able to find a place in the BCL that uses the System.Internal class.

kick it on DotNetKicks.com

Thursday, February 01, 2007 12:05:48 AM (Central European Standard Time, UTC+01:00)
Apparently hacking is a well known term among MS programmers. There are more traces in a framework that prove it :)

System.RuntimeType+RuntimeTypeCache.Prejitinit_HACK()
System.Reflection.Assembly.LoadWithPartialNameHack()
Microsoft.Win32.WinInetCache.c_SPARSE_ENTRY_HACK
System.Data.DataSet.OnRemoveRelationHack()

Long live Reflector !

RadekP
Thursday, February 01, 2007 12:25:46 AM (Central European Standard Time, UTC+01:00)
Yep, I have noticed some of the other ones, but none of them kept my attention like the ones described. For example, if I remember correctly: OnRemoveRelationHack in DataSet does nothing special. But then again, it makes me wonder, if this method is there for some JIT related reason?
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview