X++, C# Comparison: Classes about Reflection
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
In X++ the TreeNode class provides access to the Application Object Tree (AOT). The TreeNode class is the center of reflection functionality in X++. The TreeNode class and its methods can be compared to the System.Reflection namespace in the .NET Framework that C# uses.
Table of Class Comparisons
The following table lists several classes that are available to you when you write C# code. These are .NET Framework classes. For this table, all C# classes are in the System.Reflection namespace unless otherwise specified.
Each row shows the corresponding Microsoft Dynamics AX class, or class member, that is available to you when your write X++ code.
X++ |
C# |
Comments |
---|---|---|
TreeNode |
System .Assembly |
Assembly is the first class to use when a C# program must gather reflection information. Static methods on the X++ class TreeNode are the starting point for reflection in X++. |
TreeNode |
System .Type |
Instance methods on TreeNode correspond to instance methods on System.Type. |
TreeNode .AOTgetSource |
MethodInfo |
The AOTgetSource method returns several pieces of information together in one string. This includes the X++ source code in the method. In contrast, MethodInfo has a separate member for each piece of information. |
TreeNode .AOTfirstChild TreeNode .AOTnextSibling TreeNode .AOTiterator AOTiterator |
MethodInfo[] (an array) |
In C#, the GetMethods method on System.Type returns an array of MethodInfo objects. You can loop through the array by the common technique of incrementing an indexer. In contrast, the X++ model is to navigate the tree control of the AOT. The TreeNode methods of AOTfirstChild and AOTnextSibling accomplish the navigation. As an equivalent alternative, the X++ AOTiterator class is designed to navigate the tree control of the AOT. A class node is the parent over several method nodes. The AOTiterator steps through child nodes, returning each as another TreeNode instance. See also the TreeNode methods that are named AOTparent and AOTprevious. |
TreeNode .AOTgetProperty TreeNode .AOTgetProperties TreeNode .AOTname |
PropertyInfo |
In X++, the AOTgetProperties method returns a long string that contains name-value pairs for all the properties of the TreeNode. The AOTname method returns a string that contains only the value for the name property. |
TreeNode .AOTsave TreeNode .AOTinsert |
System .Reflection .Emit (namespace of classes) |
The AOTsave method applies changes from a TreeNode object in your X++ code to the AOT, and the changes are persisted. For a large code sample, see TreeNode.AOTsave Method. |
See also
Performing Reflection with the TreeNode Class
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.