Create a custom generic instance through reflection.

Source: Internet
Author: User

For example, you can use the following format to create a demo. genericssimple <t, tt> instance by Using Reflection:

System. reflection. assembly. getexecutingassembly (). createinstance ("namespace. user 'parameter quantity N [[full name of the 1-type parameter, name of the Cheng set of the type of the parameter], [full name of the 2-type parameter, assembly name of the type of the parameter], [3. Full name of the parameter type, name of the Assembly where the parameter type is located] ...... n] ")

Code:

Namespace demo {public class genericssimple <t, tt> where T: class where TT: struct {} class program {static void main (string [] ARGs) {var o = system. reflection. assembly. getexecutingassembly (). createinstance ("demo. genericssimple '2 [[system. string, mscorlib], [system. int32, mscorlib] "); console. writeline ("{0}", O = NULL? "Null": O. GetType (). fullname); console. writeline ("=== end ="); console. Read ();}}}

 

 

 

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.