In this video, we demonstrate how to use reflection. Reflection is an

Transcription

In this video, we demonstrate how to use reflection. Reflection is an
In this video, we demonstrate how to use reflection. Reflection is an object oriented concept that helps
developers build tools and frameworks. With reflection, you can inspect classes, interfaces, properties
and methods at runtime without knowing the names of them at compile time.
Programmers who need reflection know exactly why they need it. If you are new to reflection, this video
provides a brief introduction to how programmers might use it.
The Class Browser view in Progress Developer Studio for OpenEdge is an example of something you
could build into your tools with the help of reflection. The tool is able inspect the Package, Class, and
Methods like Clone. Let’s review how you could collect this same information at runtime to inspect the
classes in the OpenEdge.Mobile package.
We have enhanced Progress.Lang.Class in OpenEdge 11.6 by adding new methods to get that
information. In this example we use GetMethods.
We added several new built-in classes that inherit from Progress.Lang.Object in 11.6. The
image shows an alphabetic list of these new classes. Each class includes new methods and properties to
assist with reflection.
We also added new built-in classes that inherit from the new Progress.Lang.Enum class in 11.6.
The comments introduce the sample, which builds a .json file of the information collected for the
OpenEdge.Mobile package.
A complete TreeView would need to collect all the details. For this example, we’ll focus on the classes
and methods.
We create two temp tables. ttType with a field TypeType stores a class, interface or enum value.
ttMember stores the Member type.
The dataset combines the temp tables to gather all the classes and their related members.
To simulate a runtime value, we pull input from a file with a list of files in a package and get the classes
in that package.
We create a type record and store whether the class is abstract class.
Using GetMethods, we get the methods for each class.
We loop through each one to add details about the method such as Name, NumParameters, AccessMode,
etc.
Then we write the dataset to a file.
Opening the json file, we search for the following text.
This jumps to the json for that typeName and it shows that this is an abstract class.
Copyright © 2015 Progress Software Corporation. All rights Reserved.
If we search for the string again, we land on the first method, Initialize , for that class showing the details
we collected including Name, NumParameters, AccessMode, etc.
If we search further to find the clone method,
The DeclaringClass and the AccessLevel are being found at runtime using reflection.
Comparing this with our ClassBrowser from earlier, the PUBLIC is our AccessMode and the Member of
is the Declaring Class.
Now that you have the basic code to build the ProDataSet, you can use the online help files to build
DataSource and link that DataSource to a TreeView.
Copyright © 2015 Progress Software Corporation. All rights Reserved.