I'm fairly new to C#
and got a bit of a problem that I'm sure has a good solution using LINQ.
Background:
There's a project I've inherited that uses CrystalReports, the reports themselves all have viewer-forms [containing components/controls] associated with them in a uniform way (I'm fairly sure they were machine generated), one of these is a component descended from ReportClass
which contains a database property. The database property is the only thing that differentiates a method (Log_On_Database
) that appears in all of these classes. What I would like to do is create a common base class that searches the form for ReportClass
and uses that to populate its local database variable w/ the value from the property so I can implement Log_On_Database
in a single location.
Question:
How does one use LINQ to get all of the components
(not [just] controls) belonging to a form and recursively for those that are controls (and thus can have their own)?
NOTE: Getting the result in a List
would be great, as I could then test for a length of 0 (something went horribly wrong), 1 (expected), or more (and then I could do what I need to on those odd cases) -- even if this is all generated code, I don't trust it to not have been modified in horrendously painful ways.