XCodeFactory enhanced static check!

Source: Internet
Author: User

If many running errors/exceptions can be checked during compilation, the potential risks in the program will be greatly reduced. This is a problem we often pay attention to when writing programs.

Using DataEntrance to use XCodeFactory is very convenient. For example, to obtain the name of a student with an ID of 200308160033, this is usually done as follows:
String name = DataEntrance. GetFieldValue (typeof (Student), "200308160033", "Name"). ToString ();


The third parameter of GetFieldValue is the field name. If the field is renamed or deleted due to business needs, the code above will still be compiled, this error is detected only when an exception is thrown during running. This leaves too many potential risks for the program, because our business often changes, and the fields in our database tables also change frequently.
I hope that the field can be deleted or modified during compilation, but cannot be compiled. What should I do? In this way, a corresponding const string field is generated for each field when the data object class is generated. The value of this field is the name of the corresponding field. For example:
Public const string _ Name = "Name ";

The third parameter of GetFieldValue is the field name. If the field is renamed or deleted due to business needs, the code above will still be compiled, this error is detected only when an exception is thrown during running. This leaves too many potential risks for the program, because our business often changes, and the fields in our database tables also change frequently.
I hope that the field can be deleted or modified during compilation, but cannot be compiled. What should I do? In this way, a corresponding const string field is generated for each field when the data object class is generated. The value of this field is the name of the corresponding field. For example:
Public const string _ Name = "Name ";


The preceding call can be changed:
String name = DataEntrance. GetFieldValue (typeof (Student), "200308160033", Student. _ Name). ToString ();

In this way, if the Name field is deleted or modified, this error can be found during compilation. Are there any better solutions? Welcome to your discussion.


Related Article

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.