Detailed Description

This class represents a compiled script. It's not directly callable though. You'll need to Instance an object (and cast to whatever baseType used) using the Instance method and can then call methods on that.

Public Member Functions

 NitroCode ()
 
 NitroCode (string code)
 Creates a new NitroCode with the given nitro code to compile. Uses the default security manager and derives Nitro.Script. More...
 
 NitroCode (string code, Type baseType)
 Creates a new NitroCode with the given nitro code and type to derive from. Uses the default security manager. More...
 
 NitroCode (NitroDomainManager manager)
 Creates a new NitroCode with the given security manager. You'll need to call Nitro.NitroCode.Compile manually. More...
 
 NitroCode (string code, NitroDomainManager manager)
 Creates a new NitroCode with the given nitro code and security manager. More...
 
 NitroCode (string code, Type baseType, NitroDomainManager manager)
 Creates a new NitroCode with the given nitro code, type to derive from and security manager. More...
 
 NitroCode (string code, Type baseType, NitroDomainManager manager, string aotFile, string aotAssemblyName)
 Creates a new NitroCode with the given nitro code, type to derive from and security manager. More...
 
void Compile (string code, Type baseType)
 Compiles the given code now deriving from the given object. More...
 
void Compile (string code, Type baseType, string aotFile, string aotAssemblyName)
 Compiles the given code now deriving from the given object. More...
 
void AddReference (CodeFragment usingName)
 Adds a reference which is named in the given fragment. Using name; is handled here. More...
 
bool AllowUse (Type ofType)
 Checks if a type is allowed to be used. More...
 
bool ContainsMethod (string name)
 Checks if this code contains a method with the given name. More...
 
bool ContainsField (string field)
 Checks if this code contains a field with the given name. More...
 
Type GetType (string name)
 Searches for the system type with the given name by first performing an alias lookup. More...
 
List< TypeGetTypes (string name)
 Searches for all the types with the given name by first performing an alias lookup. More...
 
CompiledClass GetClass (Type type)
 Attempts to get a CompiledClass object from its system type. More...
 
CompiledClass GetClass (string name)
 Attempts to get a CompiledClass object from its class name. More...
 
object Instance ()
 Instances this code as an object which can have methods called upon it. If you defined a baseType in the NitroCode objects constructor, cast the result of this to that type. Otherwise, you can cast it to a Nitro.Script object which makes calling the methods easier. More...
 

Static Public Member Functions

static void Setup ()
 Sets up the compiler. More...
 

Public Attributes

string Code
 The raw code to compile. More...
 
ModuleBuilder Builder
 The builder that creates this script. More...
 

Static Public Attributes

static bool AotMode =true
 True if variable resolving is done AOT. This generally speeds up development with Nitro, but isn't compatible with typical JS. Flip this with "use aot"; and "use jit"; More...
 
static int ModuleCounter
 A counter for how many scripts have been compiled. Used to generate a unique module name. More...
 
static AotFileEvent OnAotFileExists
 Called when the AOT file we want to write to already exists. More...
 

Properties

CompiledClass MainClass [get]
 The main class of this code. More...
 
Type OutputType [get]
 The compiled useable type of the object returned by Instance. More...
 

Private Member Functions

string ParseReference (CodeFragment usingName)
 Retrieves a section of the reference from the given fragment. This is required as a reference is likely to be a chain of property fragments which must be followed to retrieve the full reference. More...
 
void FindClasses (CodeFragment frag)
 Finds all classes within the given code fragment, identified with 'class'. More...
 

Private Attributes

Type CompiledType
 The fully compiled type. Must call Instance to make use of it. More...
 
CompiledClass BaseClass
 The class to derive from. More...
 
List< CodeReferenceReferences
 The set of referenced assemblies from the top of this script file. More...
 
NitroDomainManager ScriptDomainManager
 The security domain manager which defines what the code can access. More...
 
Dictionary< string, CompiledClassTypes =new Dictionary<string,CompiledClass>()
 A set of all compiled classes defined within the code. More...
 

Static Private Attributes

static bool Started
 True if Setup has been called. More...
 

Constructor & Destructor Documentation

Nitro.NitroCode.NitroCode ( )
inline
Nitro.NitroCode.NitroCode ( string  code)
inline

Creates a new NitroCode with the given nitro code to compile. Uses the default security manager and derives Nitro.Script.

Parameters
codeThe code to compile.
Nitro.NitroCode.NitroCode ( string  code,
Type  baseType 
)
inline

Creates a new NitroCode with the given nitro code and type to derive from. Uses the default security manager.

Parameters
codeThe code to compile.
baseTypeThe type that the compiled code will inherit. This is the type to cast Nitro.NitroCode.Instance to.
Nitro.NitroCode.NitroCode ( NitroDomainManager  manager)
inline

Creates a new NitroCode with the given security manager. You'll need to call Nitro.NitroCode.Compile manually.

Parameters
managerThe security manager which defines what the code can access.
Nitro.NitroCode.NitroCode ( string  code,
NitroDomainManager  manager 
)
inline

Creates a new NitroCode with the given nitro code and security manager.

Parameters
codeThe code to compile.
managerThe security manager which defines what the code can access.
Nitro.NitroCode.NitroCode ( string  code,
Type  baseType,
NitroDomainManager  manager 
)
inline

Creates a new NitroCode with the given nitro code, type to derive from and security manager.

Parameters
codeThe code to compile.
baseTypeThe type that the compiled code will inherit. This is the type to cast Nitro.NitroCode.Instance to.
managerThe security manager which defines what the code can access.
Nitro.NitroCode.NitroCode ( string  code,
Type  baseType,
NitroDomainManager  manager,
string  aotFile,
string  aotAssemblyName 
)
inline

Creates a new NitroCode with the given nitro code, type to derive from and security manager.

Parameters
codeThe code to compile.
baseTypeThe type that the compiled code will inherit. This is the type to cast Nitro.NitroCode.Instance to.
managerThe security manager which defines what the code can access.
aotFileA DLL path to write the compiled code to (For e.g. AOT compilation).

Member Function Documentation

void Nitro.NitroCode.AddReference ( CodeFragment  usingName)
inline

Adds a reference which is named in the given fragment. Using name; is handled here.

Parameters
usingNameThe fragment containing the reference.
bool Nitro.NitroCode.AllowUse ( Type  ofType)
inline

Checks if a type is allowed to be used.

Parameters
ofTypeThe type to check for clearance.
Returns
True if it's allowed, false otherwise.
void Nitro.NitroCode.Compile ( string  code,
Type  baseType 
)
inline

Compiles the given code now deriving from the given object.

Parameters
codeThe code to compile
baseTypeThe type to inherit from. If null, the code will inherit from the default Script type.
void Nitro.NitroCode.Compile ( string  code,
Type  baseType,
string  aotFile,
string  aotAssemblyName 
)
inline

Compiles the given code now deriving from the given object.

Parameters
codeThe code to compile
baseTypeThe type to inherit from. If null, the code will inherit from the default Script type.
aotFileA DLL path to write the compiled code to (For e.g. AOT compilation).
bool Nitro.NitroCode.ContainsField ( string  field)
inline

Checks if this code contains a field with the given name.

Parameters
fieldThe field name to search for.
Returns
True if this code contains the named field.
bool Nitro.NitroCode.ContainsMethod ( string  name)
inline

Checks if this code contains a method with the given name.

Parameters
nameThe method name to search for.
Returns
True if this code contains the named method.
void Nitro.NitroCode.FindClasses ( CodeFragment  frag)
inlineprivate

Finds all classes within the given code fragment, identified with 'class'.

Parameters
fragThe fragment to search.
CompiledClass Nitro.NitroCode.GetClass ( Type  type)
inline

Attempts to get a CompiledClass object from its system type.

Parameters
typeThe system type to look for.
Returns
A compiled class if the type was found; Null otherwise.
CompiledClass Nitro.NitroCode.GetClass ( string  name)
inline

Attempts to get a CompiledClass object from its class name.

Parameters
nameThe name of the class to look for.
Returns
A CompiledClass if the class was found; Null otherwise.
Type Nitro.NitroCode.GetType ( string  name)
inline

Searches for the system type with the given name by first performing an alias lookup.

Parameters
nameThe type name to search for.
Returns
A system type if found; null otherwise.
List<Type> Nitro.NitroCode.GetTypes ( string  name)
inline

Searches for all the types with the given name by first performing an alias lookup.

Parameters
nameThe type name to search for.
Returns
A system type if found; null otherwise.
object Nitro.NitroCode.Instance ( )
inline

Instances this code as an object which can have methods called upon it. If you defined a baseType in the NitroCode objects constructor, cast the result of this to that type. Otherwise, you can cast it to a Nitro.Script object which makes calling the methods easier.

Returns
An instance of the compiled code.
string Nitro.NitroCode.ParseReference ( CodeFragment  usingName)
inlineprivate

Retrieves a section of the reference from the given fragment. This is required as a reference is likely to be a chain of property fragments which must be followed to retrieve the full reference.

Parameters
usingNameThe current fragment to handle.
Returns
The reference as a string, e.g. 'System.Generics'
static void Nitro.NitroCode.Setup ( )
inlinestatic

Sets up the compiler.

Member Data Documentation

bool Nitro.NitroCode.AotMode =true
static

True if variable resolving is done AOT. This generally speeds up development with Nitro, but isn't compatible with typical JS. Flip this with "use aot"; and "use jit";

CompiledClass Nitro.NitroCode.BaseClass
private

The class to derive from.

ModuleBuilder Nitro.NitroCode.Builder

The builder that creates this script.

string Nitro.NitroCode.Code

The raw code to compile.

Type Nitro.NitroCode.CompiledType
private

The fully compiled type. Must call Instance to make use of it.

int Nitro.NitroCode.ModuleCounter
static

A counter for how many scripts have been compiled. Used to generate a unique module name.

AotFileEvent Nitro.NitroCode.OnAotFileExists
static

Called when the AOT file we want to write to already exists.

List<CodeReference> Nitro.NitroCode.References
private

The set of referenced assemblies from the top of this script file.

NitroDomainManager Nitro.NitroCode.ScriptDomainManager
private

The security domain manager which defines what the code can access.

bool Nitro.NitroCode.Started
staticprivate

True if Setup has been called.

Dictionary<string,CompiledClass> Nitro.NitroCode.Types =new Dictionary<string,CompiledClass>()
private

A set of all compiled classes defined within the code.

Property Documentation

CompiledClass Nitro.NitroCode.MainClass
get

The main class of this code.

Type Nitro.NitroCode.OutputType
get

The compiled useable type of the object returned by Instance.