Consider the following C# code:
var methodBuilder1 = typeBuilder.DefineMethod("GetMedalIds", MethodAttributes.Public | MethodAttributes.HideBySig, CallingConventions.HasThis, typeof(int[]), null);
var methodBuilder2 = typeBuilder.DefineMethod("GetMedalIds", MethodAttributes.Public | MethodAttributes.HideBySig, CallingConventions.HasThis, typeof(int[]), null);
First, note that the arguments into DefineMethod
are identical (and arbitrary), and typeBuilder
is the same instance in both cases. With this in mind, I have discovered the methodBuilder1
and methodBuilder2
both point to the same instance (at least methodBuiilder1 == methodBuilder2
is always true), leading me to assume that if the method builder hasn't already been defined, type builder defines it, otherwise it returns the already defined method builder.
My question is this: The comments on DefineMethod(...)
says nothing about the above, so are my assumptions GUARANTEED to always be true as far as the C# specification is concerned, or is it an implementation detail that is subject to change? .