Replies: 2 comments 3 replies
-
Hey Eric, Because Cecil tries to maintain the identity of GenericParameters, I think it's trying to find where the GenericParameter So you would do something like this? var d = ImportReference(declaring_type);
var rt = ImportReference(returnType, d); |
Beta Was this translation helpful? Give feedback.
-
Hey Eric, Sorry if I skimmed through the question too fast before answering. I think none of what I'm writing here solves the question but hopefully should provide a bit of a context. At the end of the day, There are 2 series of ImportReference methods:
The reflection based one is convenient but has a severe drawback: it creates references to the currently running runtime. Meaning if you're modifying an assembly for another runtime you'll get into troubles. The Cecil based one is one I encourage people using because it gives you more control. As I was writing above, Cecil tries to maintain generic parameter identity. Meaning that if you have an open generic instantiation, the To answer one of your concern, calling It's also possible that Cecil is doing weird stuff that would not be expected, I'd have to try and debug it.
My initial thought is that I think Cecil should be able to create a reference given the right context. Now if Cecil's default importer doesn't work for you, at least you can always roll-out your own. |
Beta Was this translation helpful? Give feedback.
-
My question is about the proper usage of
ImportReference
of aSystem.Type
.The particular
System.Type
here is the return type of this delegate from ASP.NET:https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.web.virtualization.itemsproviderdelegate-1?view=aspnetcore-5.0
which is:
Suppose I have:
Now, if I do this:
Then I get this error.
Which seems to indicate that the problem here is the generic type argument, which is not surprising.
If I instead import the generic type definition, like this:
Then I get no error, but I haven't really imported the same type.
I assume what I probably need to do is import the type definition, and then import the type arguments, and then put them back. Can you confirm that?
I'm pretty sure I can figure out how to do this, but I'm also curious if
DefaultReflectionImporter
should be able to do it. I'm looking at theIGenericParameterProvider
argument forImportReference()
. Perhaps I am supposed to be providing one of these? If so, where would I get it?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions