Hoping that this works…
I have been searching for an answer to this one and I am perplexed.
http://msdn2.microsoft.com/en-us/library/system.type.getgenericarguments.aspx returns an array of the generic arguments .. what I can't figure out is if they will ever be out of order. The arguments themselves have a position on them, is it possible that I get them back out of order where I would need to re-order them ...
basically what I am doing is something similar to the following on a generic type definition
string [] Params = new string[typeArguments.Length];
for (int i=0;i {
Params[i] = typeArguments[i].Name;
}
GenericTypeParameterBuilder[] typeParams = outputType.DefineGenericParameters(Params);
Debug.Assert(typeParams.Length == typeArguments.Length);
for(int i=0;i GenericTypeParameterBuilder builder = typeParams[i];
Type OriginalType = typeArguments[i];
builder.SetGenericParameterAttributes(OriginalType.GenericParameterAttributes);
builder.SetInterfaceConstraints(OriginalType.GetGenericParameterConstraints());
}
I have to say as well that I am rather unimpressed with the bridge I am forced to put up here .. it would be alot nicer to just pass through the generic arguments I already have as opposed to creating a string [] then iterating through .. maybe I am missing something with the API?
and for those who know me well .. you probably know what I am working on .. (hint, the topic this is posted in)\
Update: it seems the documentation has been updated to reflect the return being sorted http://msdn2.microsoft.com/en-us/library/system.type.getgenericarguments.aspx
Be very careful when using Array.Sort in 2.0. I had posted a bug report about this a while ago http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=62029e14-2d0b-4250-a163-1583034db250
The behavior observed was originally in arraylist (which uses Array.Sort internally) so keep in mind that this applies to it as well.
Array.Sort(Items, 0, Items.Length, Comparer.Default); //takes 1 minute
Array.Sort(Items2, 0, Items.Length, null); //takes 250 ms
Items and Items2 are both clones of the same object []
What is tricky about this code is that the second call does not actually call Array.Sort .. it calls Array<object> .Sort
First call:
IL_0083: ldsfld class [mscorlib]System.Collections.Comparer [mscorlib]System.Collections.Comparer::Default
IL_0088: call void [mscorlib]System.Array::Sort(class [mscorlib]System.Array, int32, int32, class [mscorlib]System.Collections.IComparer)
Second Call:
IL_00c9: ldnull
IL_00ca: call void [mscorlib]System.Array::Sort (!!0[], int32, int32, class [mscorlib]System.Collections.Generic.IComparer`1)
Ah .. :)
Basically what the issue is is that there are 2 distinct sorting algorithms .. one that is Array.Sort one that is Array.Sort .. they do not use the same algorithm. From what I understand some changes were made in how pivots are chosen.