New tlbimp version released on codeplex: Rule-Based custom function

Source: Internet
Author: User

Hello everyone. It has been nearly half a year since we released the new tlbimp version on codeplex last time. In the past six months, apart from the main operations. in addition to the development of new functions related to net 4.0, our Shanghai CLR team did not forget to continue the development of tlbimp-related functions. In March 9 this year, a new version of tlbimp was released again:

Http://www.codeplex.com/clrinterop/Release/ProjectReleases.aspx? Releaseid = 17579

In this version, we have introduced two important functions:

1. Rule-Based custom interoperability Assembly and rule-based custom Editor

2. regression testing tools

Rule-based custom functions

Let's take a look at the custom functions. This new version of tlbimp allows users to specify how tlbimp generates the final interoperability Assembly through a series of custom rules. Many users have mentioned that when using tlbimp, you often need to make some modifications to the results generated by tlbimp, which must be automated. They usually use ildasm disassembly, Perl scripts to modify the disassembly code, and then ilasm to regenerate the interoperability assembly. To solve this problem, we introduced a new feature that allows users to define the results they finally want to see in a very free way.

Let's take a look at a simple example: Suppose we want to change the name of a type in the interoperability assembly. Double-click tlbimpconfigfileeditor.exe to start the User-Defined file editor, and then open the Type Library we need to customize. Here we select the release version samples/changemanagedname/changemanagednamesample. TLB file, as follows:

The left shows the type library we need to customize, while the right shows the rules we need to customize. These rules can tell tlbimp how to modify the final interoperability assembly. First, drag the icomparable interface node to the right from the left and release the mouse. The following dialog box is displayed:

The preceding dialog box is used to create a new rule that specifies the actions that tlbimp applies to which objects. In this dialog box, we need to define the action corresponding to this rule. Therefore, select changemanagedname in the Action drop-down box and click OK. The editor status is as follows (you need to expand the node yourself ):

You can see that a new rule named change interface name has appeared on the right, and the corresponding category is type, that is, this rule is set for the type in the interoperability assembly. Condition specifies the conditions to be met by the rule. If you select a condition node (or its subnodes), you can see the corresponding rule expression in the following condition expression, that is, nativename equal 'iconcompuareable ', this rule is for any type called icomparable. Note that these conditions are automatically generated by the editor because we drag them directly from the icomparable node to the right. If needed, you can also click the native equal icomparable condition to modify it, or click To add new conditions. Now we can click Node, select typekind in the drop-down box, equal in the second drop-down box, and interface in the third drop-down box. The final result is as follows:

Note that the expression nodes are organized in a similar way to the syntax tree. That is to say, the relationship between each other is and under the and node. The final result can always be seen in the condition expression column:

(Nativename equal 'iconfigable') and (typekind equal' interface ')

When the rule is edited, We need to specify the parameters for the specific action. Because we need to modify the object type name, double-click the newname subnode under action to bring up the following dialog box:

Enter the name we want to change to, and then click OK.

This rule is complete:

After modification, save the disk as changeinterfacename. XML, call tlbimp under the command line, and use the/config parameter to reference the config file of the previous disk (highlighted in yellow:

Then open the generated result through ildasm:

You can see that icomparable has been renamed imyinterface.

Tlbimp supports the following actions in total ):

1. changemanagedname: Modify the type and function name.

2. resolveto: replace one type with another (it can be another assembly type ). Now there are users who need this feature on codeplex: http://clrinterop.codeplex.com/WorkItem/View.aspx? Workitemid = 2565

3. addattribute: add any attribute for any type

4. preservesig: Add preservesigattribute to all functions of a single function or type and modify the prototype of the function accordingly.

5. convertize: Modify the parameter type in the function.

Examples of each corresponding action are provided under the samples directory. If you are interested, you can refer to the relevant documentation for your own experiment.

Regression testing tools

To help users easily ensure that their modifications do not cause other problems when modifying the tlbimp code, we have introduced a simple regression testing tool, which can be downloaded here:

Http://clrinterop.codeplex.com/Release/ProjectReleases.aspx? Releaseid = 17579

After the download, open the tlbimpregressiontesttool.exe file in the bindirectory, and open the testcases. xml file under the testcase directory through the File menu:

We can see that all testcase is listed. In the next step, select settings in the runmenu and enter the location of tlbimp2.exeand windiff.exe:

After that, select Run all testcases or run selected testcasesunder run. This tool will call tlbimp2.exe to run testcase in sequence to check whether the corresponding functions of tlbimp2 are correct:

Green indicates that the test is successful, and red indicates that the test fails. If any failure occurs, double-click the row to open windiff to compare the difference between the currently generated result of tlbimp2 and the expected result.

Finally, we hope you can actively use the new features of tlbimp. If you have hope to see the new features of tlbimp, or on the current tlbimp what do you think do not good enough, you can come to the following address to give your valuable advice: http://clrinterop.codeplex.com/WorkItem/List.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.