views:

54

answers:

1

I'm trying to do some processing on all assemblies that own forms that are currently open in my application. I can easily get the form objects with:

System.Windows.Forms.Application.OpenForms

I want to iterate through this list and find the owning assembly for each instance. I know how to find the assembly that owns a given form class, but not a specific class instance.

+7  A: 
formInstance.GetType().Assembly

Edit in response to comment:

from form in Application.OpenForms
where form.Owner != null
select form.Owner.GetType().Assembly
Bryan Watts
No, as I was saying above, that finds the Assembly owning the class Type. I want the assembly where formInstance is owned.
Wade Tandy
It sounds like you want the assembly containing the `Form` class corresponding to the `.Owner` property of each instance in `OpenForms`. Is that correct? I have updated my answer to reflect my new understanding. I was confused because you said "I want to iterate through this list [OpenForms] and find the owning assembly for each instance." "Owning assembly" implies the assembly in which the form is declared, not the assembly of its owner. I think you meant "I want to iterate through this list and find the assembly of the owner of each instance." Let me know if that's right.
Bryan Watts
I didn't realize that's what I wanted, but now that you've put that code in front of me, yes, that's the answer I was looking for.
Wade Tandy
Glad to hear it :-)
Bryan Watts