How do I … use Reflection to build a project that will inspect/analyse other assemblies
29-Mar-1212 Leave a comment
For instance:
- My preference is that TableAdapters are not in the component tray of forms, but ideally in a DAL, or if not that good then in a using part of the forms code. I have always struggled to find these. I want a Reflection utility that will find these
Key reflection code snippets to do this are:
How do I … use reflection to load an Assembly at runtime
Dim asm = System.Reflection.Assembly.LoadFrom(AssemblyFileName)
or
Dim asm = System.Reflection.Assembly.GetExecutingAssembly
How do I … loop around forms of a Loaded assembly
ForEach t1 In asm.GetTypes.Where(Function(f) f.IsPublic).Where(Function(f) f.BaseType.Name = “Form”)
Me.ListBox1.Items.Add(String.Concat(t1.Name))
Next
How do I … loop around forms and GetFields
For Each f1 In asm.GetTypes.Where(Function(f) f.IsPublic).Where(Function(f) f.BaseType.Name = “Form”)
For Each prop In f1.GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).Where(Function(f) f.Name.ToLower.Contains(FieldName))
Me.ListBox1.Items.Add(String.Concat(f1.Name, “: “, prop.Name, “: “, prop.FieldType.Name))
Next
Next