Convert object objects and String Conversion Arrays

Source: Internet
Author: User

      ///   <Summary>          ///  Convert object  ///   </Summary>          ///   <Typeparam name = "T1">  Converted entity  </Typeparam>          ///   <Typeparam name = "T2"> Converted entity  </Typeparam>          ///   <Param name = "T1"> </param>          ///   <Param name = "T2"> </param>          ///   <Returns> </returns>          Public T2 parstmodel <T1, T2> (T1 T1, T2 T2 ){  Try  {  If (T1 = Null ){  Return  T2 ;}  Else  {System. reflection. propertyinfo [] Properties = T1.gettype (). getproperties (system. reflection. bindingflags. instance | System. reflection. bindingflags. Public );  If (Properties. Length <= 0  ){  Return T2 ;}  Foreach (System. reflection. propertyinfo item In  Properties ){  String Name = Item. Name;  Object Value = item. getvalue (T1, Null  );  If (Item. propertytype. isvaluetype | item. propertytype. Name. startswith ( " String  "  ) {T2.gettype (). getproperty (name). setvalue (t2, value,  Null  );}  Else  {Parstmodel (value, T2 );}}}  Return  T2 ;}  Catch  (Exception ex ){ Throw  Ex ;}}  ///   <Summary>          ///  Convert string to array  ///   </Summary>          ///   <Param name = "str">  String object to be converted  </Param>          ///   <Param name = "arr">  Returned String Array </Param>          ///   <Returns> </returns>          Public   String [] Strsplittoarry ( String STR, String  [] ARR ){  If (Str. Contains ( '  ,  '  ) {Arr = Str. Split ( ' ,  '  );}  Else  {Array. Resize (  Ref Arr, 1  ); Arr [  0 ] = STR ;}  Return  Arr ;} 

 

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.