I was using 3rd-party package to a .Net cms, kind of ORM from internal data representation to a POCO. To get it worked I needed to take it's source code from GitHub to debug and see what is wrong. I've found that there is reflection MethodInfo.Invoke call to a method that uses yield return. The return from this method is supposed to be assigned to a POCO's property with property.SetValue(). And this very call returned null that, being set to a property, caused invalid result of mapping.
I changed method's logic a bit to compose IEnumerable<> first and then return it as it is with ordinary return, no yield - then everything started working properly.
My question is - since this package was downloaded and used by other people so it is considered to be working, putting aside my source code change - perhaps there is some approach to deal with Invoked methods that return with yield? I know that yield returns an ienumerator (state machine) that is to be used in foreach-like loops over some IEnumerable but it is for direct IEnumerable generator method call, it was the first time when I saw reflection-call of such method. Thanks.
Aucun commentaire:
Enregistrer un commentaire