A common entity-class data replication solution in service-oriented (interface) development process

Source: Internet
Author: User

Now, service-oriented development has become an essential concept for b\s and c\s development, and has previously done a WCF service to invoke this service in the MVC Development mode on the Web side, which involves the replication of entity class data. Because the server-side model and the model in MVC are theoretically scoped differently, when you get the data returned by the service, you need to use the entity classes to load the data. In general, this is done by declaring a function on the Web side (no reflection or deep cloning required) to two parameters, one source object and one target object. Okay, here's the problem. Sometimes there are static fields in the entity class, so we have to deal with the data replication problem of this static field. The source code is as follows:

 Private voidEntitytoentity<tsource, ttarget> (TSource s)            whereTSource:New()            whereTtarget:New()        {            if(T.gettype (). GetFields ()! =NULL)            {                foreach(varP2inchT.gettype (). GetFields ()) {varS1 = S.gettype (). GetField (P2. Name);//Find field information for the source entity classP2. SetValue (t, S1. GetValue (NULL)); }            }
foreach(varPinchT.gettype (). GetProperties ())//target table as reference object { //Copy to local variable varP1 =p; { varS2 =S.gettype (). GetProperty (P1. Name); if(S2 = =NULL)Continue; P1. SetValue (t, S2. GetValue (s),NULL),NULL); } } }

A common entity-class data replication solution in service-oriented (interface) development process

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.