Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a method to get the non-generic signature of a MethodSpec #501

Closed
Misaka-Mikoto-Tech opened this issue May 12, 2023 · 2 comments
Closed

Comments

@Misaka-Mikoto-Tech
Copy link

Misaka-Mikoto-Tech commented May 12, 2023

I want to generate a Method with exactly the same ParameterDef and return type as MethodSpec, but the parameters obtained through methodSpec.GetParams() has generic type, such as T, U, how can I get its real type?

@ElektroKill
Copy link
Contributor

ElektroKill commented May 13, 2023

Access the GenericInstMethodSig property of MethodSpec. It contains the instantiation of the generic parameters (in order the same as generic method arguments). If you want to create an instantiated type, you must traverse the TypeSig structure until you find a GenericMVar and substitute it with the signature from the list. An example implementation of this can be found in ConfuserEx, see https://github.com/mkaring/ConfuserEx/blob/master/Confuser.Renamer/GenericArgumentResolver.cs

@Misaka-Mikoto-Tech
Copy link
Author

I made a slight modification and used it in my own project. Thank you very much for providing the solution, it helped me a lot!

https://github.com/Misaka-Mikoto-Tech/UnityScriptHotReload/blob/main/Assets/HotReload/Editor/AssemblyPatcher~/Source/GenericArgumentResolver.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants