C # Generic constraints XXX <t> where T: Constraints (1)

Source: Internet
Author: User

We found that in our game code, the main program wrote a lot of code similar to this:

Public static t Createobject <t> (Out int objectid) where T: New () // method name

Public class csingleton <t> where T: New () // Singleton class

Public t getcontrol <t> (string Uri, transform findtrans = NULL, bool islog = true) where T: unityengine. Object // search for the UI control based on URL and type

Public t findcontrol <t> (string name) where T: Component

Public void OpenWindow <t> (Params object [] ARGs) where T: cuibase

Public void callui <t> (Action <t, object []> callback, Params object [] ARGs) where T: cuibase

Public void loadtab <t> (string tabpath) where T: cbaseinfo, new () // load the tab table

----- Specific usage -----

Definition: Public t getinfo <t> (string ID) where T: cbaseinfo

Use: actorinfo = cgamesettings. instance. getinfo <actorinfo> (actorid );

Explanation: [T getinfo (string ID)] When an ID is input, a class is returned. [where T: cbaseinfo] indicates that the type of this class must inherit cbaseinfo.

 

Of course, some plug-ins in the project are similar:

Fingergestures

Public abstract class continuousgesturerecognizer <t>: gesturerecognizerts <t> where T: continuousgesture, new ()

Public static t createasset <t> () where T: scriptableobject

Public abstract class fingereventdetector <t>: fingereventdetector where T: fingerevent, new ()

Ngui

Static public T [] findactive <t> () where T: Component

Static public t addchild <t> (gameobject parent, bool UNDO) where T: Component

Static public t begin <t> (gameobject go, float duration) where T: uitweener

Tk2d

Public static t loadresourcebyname <t> (string guid) where T: unityengine. Object

Public static t addcomponent <t> (gameobject go, tk2dspritecollectiondata spritecollection, string spritename) where T: tk2dbasesprite

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.