Generic parameter properties seem to have incorrect values, making them hard to compare #97
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've been using the following logic for comparing two TypeReferences (since reference equality isn't adequate), and for most type references it works correctly (there are a few exceptions I know of that I already handle):
In this case TypesAreEqual just maps to the function that performs this (and other) comparison(s).
AFAIK this has no false positives for any Mono.Cecil TypeReference, with the exception of GenericParameters.
For GenericParameters, however, the properties don't have values that I would expect.
Given the following two generic parameters:
The two parameters compare as the same. This is because they both have an empty Namespace (instead of, for example, the namespace of the type that declared the parameter), and they both have a null DeclaringType (instead of the type that declared the parameter). Worse still, they both have the same FullName - while I could imagine the DeclaringType and Namespace properties having the same value being intentional, I feel like these generic properties should absolutely have different FullNames (even though I try to avoid using FullName for comparisons because it creates garbage).
Thoughts? Is there a better way for me to do type comparisons that isn't vulnerable to this problem? Right now, I'm special-casing GenericParameter instances and directly comparing their Owners, but I hate having to have special code for each distinct class of TypeReference.
There's not really any choice besides comparing all details of types : you can't compare an array type like you compare a generic parameter or a generic instantiation.
You can have a look at how the MetadataResolver handles it: https://github.com/jbevain/cecil/blob/master/Mono.Cecil/MetadataResolver.cs
That's really useful, thanks. It might be worthwhile to have the GenericParameter's FullName include the FullName of the scope, though?