Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

type registration

Chris Vos edited this page Jul 16, 2014 · 8 revisions

Type registration

Typescript (JS) doesn't have a runtime type information system like C#. But most C# library's exploit the type information to do stuff. That's why we simulate a type system by registrering the types to the library.

Register a class

Registering a class to the system is done by defining a static property called _type within the class. Type.registerClass is used with 3 parameters

  1. class
  2. the full name, including module naming, of the class as string
  3. array of string of the fullname interfaces the class implements

Sample

module System {
  export class Guid extends System.Object implements ICloneable        {
    static _type: Type = Type.registerClass(Guid, "System.Guid", ["System.ICloneable"]);
  }
}

Register an interface

Registering a interface to the system is done by calling the System.Type.registerInterface and passing the full interface name, with extended

sample

module System.Sample {
  export interface IThing extends System.IOther {
   someMethod() : void;
  }
    System.Type.registerInterface("System.Sample.IThing", "System.IOther");
}

##Register an Enumaration Registering an Enumaration to the system is done by typing System.Type.registerEnum and the enumaration and after the comma you type the string name.

Sample

module System
{
    export enum SampleColor
    {
        Red,
        White,
    } 
    System.Type.registerEnum(SampleColor, "System.SampleColor");
}
Clone this wiki locally