How do I … use Reflection to build a project that will inspect/analyse other assemblies

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

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: