✅ How can i turn this into a query?
Current code:
foreach (var type in module.Types)
{
if (type.Name == "foo")
{
foreach (var method in type.Methods)
{
if (method.Name == "bar")
MethodDefinition myMethod = method;
}
}
}
I am trying to turn this code into a query, so it's shorter and prettier.. but i can't seem to get it right..
MethodDefinition myMethod =
from type module.Types
where type.Name == "foo"
...
I just get errors with whatever i try..
10 Replies
something like this I guess
Where do i put the assignment of:
MethodDefinition myMethod = method ?
what is this for?
I need to get the myMethod reference, so i can pass it as an argument to a different function
it's from mono.cecil library
using it to inject .net code into a .net binary
dont know much about this mono lib, but if you need all them to pass, use
Oh i thought it would select only one.. ok i think i understand my mistake
Yes that looks very good
mono lib is amazing btw
if you need only one, then use
.FirstOrDefault()
That's perfect man, thanks a lot.
$close
If you have no further questions, please use /close to mark the forum thread as answered