. NET implements code by using a dictionary to assign values to a class

Source: Internet
Author: User
Needless to say, the code is directly affixed, the specific code is described as follows:

<summary>/////</summary>///<typeparam name= "T" ></typeparam>///<param Name= "origin "> Source data </param>///<param name=" target "> Object data </param>///<param name=" dict "> variable name corresponding dictionary </ Param>public static void Copyto<t> (This object origin, T target,dictionary<string,string> dict) where T: Class,new () {propertyinfo[] props = target. GetType (). GetProperties (); foreach (PropertyInfo info in props) {var variable = Dict. FirstOrDefault (m = M.value = = info. Name); if (variable. Key!=null) {string variableName = variable. key;string chinesename = variable. Value;var PropertyValue =origin. GetType (). GetProperty (VariableName). GetValue (origin, null); if (propertyvalue! = null) {if (Propertyvalue.gettype (). IsClass) {}target. GetType (). InvokeMember (chinesename, BindingFlags.SetProperty, NULL, target,new object[] {propertyvalue});}}}



The above is. NET through the dictionary to assign values to the content of the code, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.