Hybrid Bridge
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties | Events | List of all members
HybridBridge.ClassBridge< T > Class Template Reference

A generic handler to be used to make C# classes accessible from the Javascript side More...

Inheritance diagram for HybridBridge.ClassBridge< T >:
HybridBridge.IBridgeHandler

Classes

class  InternalParameterInfo
 

Public Member Functions

 ClassBridge ()
 Creates a new instance of this class More...
 
virtual object InterceptRequest (string method, Dictionary< string, object > parameters, out bool hasResult)
 Handles the passed request and returns the result More...
 
virtual bool ShouldInterceptRequest (string handler, string method)
 Checks the request and returns true if this request can be handled by this handler More...
 
virtual void Initialize (BridgeController bridge)
 Initialize the handler and generates the needed Javascript code More...
 
virtual void Dispose ()
 The method to dispose this class More...
 
virtual ClassBridge< T > AddInstance (T instance)
 Registers an instance of the generic type and adds it to the list of registered instances More...
 
virtual ClassBridge< T > AddInstance (T instance, string variableName)
 Registers an instance of the generic type and adds it to the list of registered instances More...
 
virtual ClassBridge< T > RemoveInstance (params string[] variableNames)
 Removes the requested instances by variable name More...
 
virtual ClassBridge< T > RemoveInstance (params T[] instances)
 Removes the requested instances More...
 
virtual ClassBridge< T > RemoveInstance (string variableName, T instance)
 Removed the requested instance and its variable More...
 

Static Public Member Functions

static T GetInstance (string instanceId)
 Returns an instance of the generic type from global pool using instance id More...
 
static T NormalizeVariable< T > (object variable)
 Tries to normalize variable by searching InstancePool and converting of variable to the desired Type More...
 
static object NormalizeVariable (object variable, Type normalizeType, bool throwOnException)
 Tries to normalize variable by searching InstancePool and converting of variable to the desired Type More...
 
static IBridgeHandler FromType (Type genericType)
 Creates a new instance of ClassBridge class with the specified Type as the class's generic type More...
 

Public Attributes

virtual T[] RegisteredInstances => Instances.Keys.Select(o => o as T).Where(t => t != null).ToArray()
 Returns an array containing all registered instances More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 The method to dispose this class More...
 
virtual object RaiseEvent (object instance, string eventName, bool isVoid, object[] eventArgs)
 Handles the events raised by public events of the generic class and its instances More...
 
virtual object OnPushJavascript (PushJavascriptEventArgs eventArgs)
 Raises the PushJavascript event using provided arguments More...
 

Protected Attributes

readonly InstanceDictionary< List< string > > Instances = new InstanceDictionary<List<string>>()
 A list containing all registered instances of the generic type to be accessible from the other side More...
 
readonly Dictionary< T, Dictionary< EventInfo, Delegate > > InstancesEventsDelegates
 A list containing all generated delegates for each instance's events More...
 
readonly Dictionary< EventInfo, Delegate > StaticEventsDelegates = new Dictionary<EventInfo, Delegate>()
 A list containing all generated delegates for each static events More...
 
bool Disposed
 Indicates if the class already disposed More...
 

Static Protected Attributes

static Dictionary< ConstructorInfo, ParameterInfo[]> Constructors
 A cached list of public constructors for this type More...
 
static List< EventInfo > Events
 A cached list of public events for this type More...
 
static List< FieldInfo > Fields
 A cached list of fields for this type More...
 
static readonly object Lock = new object()
 A static object to be used as thread lock when working with other static fields More...
 
static Dictionary< MethodInfo, ParameterInfo[]> Methods
 A cached list of public and non generic methods for this type More...
 
static List< PropertyInfo > Properties
 A cached list of public properties for this type More...
 
static List< IBridgeHandlerSubClasses
 A list of public and not generic sub classes More...
 
static List< IBridgeHandlerSubEnumerations
 A cached list of public sub enumerations types for this type More...
 

Properties

static string Identification [get]
 Returns a string containing the name of the proxy class accessible from the Javascript side More...
 
static Type GenericType = typeof(T).FullName.Replace('+', '.') [get]
 Returns the generic type used to create this class More...
 

Events

PushJavascriptEvent PushJavascript
 Event that gets raised when handler needs to push some Javascript code More...
 
- Events inherited from HybridBridge.IBridgeHandler
PushJavascriptEvent PushJavascript
 Event that gets raised when handler needs to push some Javascript code More...
 

Detailed Description

A generic handler to be used to make C# classes accessible from the Javascript side

Contains static, reusable and non generic methods for the ClassBridge class

Template Parameters
TThe generic class to be reflected on the Javascript side
Type Constraints
T :class 

Definition at line 21 of file ClassBridge'1.cs.

Constructor & Destructor Documentation

Creates a new instance of this class

Exceptions
InvalidGenericTypeExceptionIndicates that the passed generic type is not a valid class

Definition at line 96 of file ClassBridge'1.cs.

Member Function Documentation

virtual ClassBridge<T> HybridBridge.ClassBridge< T >.AddInstance ( instance)
virtual

Registers an instance of the generic type and adds it to the list of registered instances

Parameters
instanceThe instance of the generic type to ad
Returns
Returns instance to be used for other operations

Definition at line 607 of file ClassBridge'1.cs.

virtual ClassBridge<T> HybridBridge.ClassBridge< T >.AddInstance ( instance,
string  variableName 
)
virtual

Registers an instance of the generic type and adds it to the list of registered instances

Parameters
instanceThe instance of the generic type to ad
variableNameThe name of the variable that is accessible from the Javascript side
Returns
Returns instance to be used for other operations

Definition at line 618 of file ClassBridge'1.cs.

virtual void HybridBridge.ClassBridge< T >.Dispose ( )
virtual

The method to dispose this class

Definition at line 503 of file ClassBridge'1.cs.

virtual void HybridBridge.ClassBridge< T >.Dispose ( bool  disposing)
protectedvirtual

The method to dispose this class

Definition at line 520 of file ClassBridge'1.cs.

static IBridgeHandler HybridBridge.ClassBridge< T >.FromType ( Type  genericType)
static

Creates a new instance of ClassBridge class with the specified Type as the class's generic type

Parameters
genericTypeThe type to create a ClassBridge instance for
Returns
Newly created ClassBridge instance

Definition at line 432 of file ClassBridge.cs.

static T HybridBridge.ClassBridge< T >.GetInstance ( string  instanceId)
static

Returns an instance of the generic type from global pool using instance id

Parameters
instanceIdThe identification string of the instance
Returns
The registered instance

Definition at line 549 of file ClassBridge'1.cs.

virtual void HybridBridge.ClassBridge< T >.Initialize ( BridgeController  bridge)
virtual

Initialize the handler and generates the needed Javascript code

Parameters
bridgeThe BridgeController object requesting initialization

Implements HybridBridge.IBridgeHandler.

Definition at line 412 of file ClassBridge'1.cs.

virtual object HybridBridge.ClassBridge< T >.InterceptRequest ( string  method,
Dictionary< string, object >  parameters,
out bool  hasResult 
)
virtual

Handles the passed request and returns the result

Parameters
methodThe method name to handle
parametersThe method parameters
hasResultA boolean value indicting if the handling process resulted in a value
Returns
Returns the value that created from the handling of the request

Implements HybridBridge.IBridgeHandler.

Definition at line 215 of file ClassBridge'1.cs.

static object HybridBridge.ClassBridge< T >.NormalizeVariable ( object  variable,
Type  normalizeType,
bool  throwOnException 
)
static

Tries to normalize variable by searching InstancePool and converting of variable to the desired Type

Parameters
variableThe variable to normalize
normalizeTypeThe Type to convert variable to
throwOnExceptionA boolean value indicating if the method should throw an exception or just returns in case of errors
Returns
New created or casted from the variable in the desired Type, or
Exceptions
InvalidCastExceptionThe passed variable can not be converted to the desired Type

Definition at line 381 of file ClassBridge.cs.

static T HybridBridge.ClassBridge< T >.NormalizeVariable< T > ( object  variable)
static

Tries to normalize variable by searching InstancePool and converting of variable to the desired Type

Parameters
variableThe variable to normalize
Returns
New created or casted from the variable in the desired Type, or

Definition at line 360 of file ClassBridge.cs.

virtual object HybridBridge.ClassBridge< T >.OnPushJavascript ( PushJavascriptEventArgs  eventArgs)
protectedvirtual

Raises the PushJavascript event using provided arguments

Parameters
eventArgsThe arguments to be used to raise PushJavascript event
Returns
Returns the result of raising PushJavascript event

Definition at line 597 of file ClassBridge'1.cs.

virtual object HybridBridge.ClassBridge< T >.RaiseEvent ( object  instance,
string  eventName,
bool  isVoid,
object[]  eventArgs 
)
protectedvirtual

Handles the events raised by public events of the generic class and its instances

Parameters
instanceThe instance that raised the event
eventNameThe name of the raised event
isVoidIndicates if the raised event has a return value
eventArgsAn array containing the parameters of the raised event
Returns
Returns the result of raising registered delegates

Definition at line 562 of file ClassBridge'1.cs.

virtual ClassBridge<T> HybridBridge.ClassBridge< T >.RemoveInstance ( params string[]  variableNames)
virtual

Removes the requested instances by variable name

Parameters
variableNamesThe variable name of the instances to be removed from Javascript side
Returns
Returns instance to be used for other operations

Definition at line 693 of file ClassBridge'1.cs.

virtual ClassBridge<T> HybridBridge.ClassBridge< T >.RemoveInstance ( params T[]  instances)
virtual

Removes the requested instances

Parameters
instancesThe instances to be removed from the Javascript side
Returns
Returns instance to be used for other operations

Definition at line 713 of file ClassBridge'1.cs.

virtual ClassBridge<T> HybridBridge.ClassBridge< T >.RemoveInstance ( string  variableName,
instance 
)
virtual

Removed the requested instance and its variable

Parameters
variableNameThe variable name of the instance to be removed from Javascript side
instanceThe instance to be removed from the Javascript side
Returns
Returns instance to be used for other operations

Definition at line 743 of file ClassBridge'1.cs.

virtual bool HybridBridge.ClassBridge< T >.ShouldInterceptRequest ( string  handler,
string  method 
)
virtual

Checks the request and returns true if this request can be handled by this handler

Parameters
handlerThe name of requested handler
methodThe method name to handle
Returns
true, if this handler can handle this request, false otherwise

Implements HybridBridge.IBridgeHandler.

Definition at line 398 of file ClassBridge'1.cs.

Member Data Documentation

Dictionary<ConstructorInfo, ParameterInfo[]> HybridBridge.ClassBridge< T >.Constructors
staticprotected

A cached list of public constructors for this type

Definition at line 27 of file ClassBridge'1.cs.

bool HybridBridge.ClassBridge< T >.Disposed
protected

Indicates if the class already disposed

Definition at line 90 of file ClassBridge'1.cs.

List<EventInfo> HybridBridge.ClassBridge< T >.Events
staticprotected

A cached list of public events for this type

Definition at line 33 of file ClassBridge'1.cs.

List<FieldInfo> HybridBridge.ClassBridge< T >.Fields
staticprotected

A cached list of fields for this type

Definition at line 39 of file ClassBridge'1.cs.

readonly InstanceDictionary<List<string> > HybridBridge.ClassBridge< T >.Instances = new InstanceDictionary<List<string>>()
protected

A list containing all registered instances of the generic type to be accessible from the other side

Definition at line 74 of file ClassBridge'1.cs.

readonly Dictionary<T, Dictionary<EventInfo, Delegate> > HybridBridge.ClassBridge< T >.InstancesEventsDelegates
protected
Initial value:
=
new Dictionary<T, Dictionary<EventInfo, Delegate>>()

A list containing all generated delegates for each instance's events

Definition at line 79 of file ClassBridge'1.cs.

readonly object HybridBridge.ClassBridge< T >.Lock = new object()
staticprotected

A static object to be used as thread lock when working with other static fields

Definition at line 45 of file ClassBridge'1.cs.

Dictionary<MethodInfo, ParameterInfo[]> HybridBridge.ClassBridge< T >.Methods
staticprotected

A cached list of public and non generic methods for this type

Definition at line 51 of file ClassBridge'1.cs.

List<PropertyInfo> HybridBridge.ClassBridge< T >.Properties
staticprotected

A cached list of public properties for this type

Definition at line 57 of file ClassBridge'1.cs.

virtual T [] HybridBridge.ClassBridge< T >.RegisteredInstances => Instances.Keys.Select(o => o as T).Where(t => t != null).ToArray()

Returns an array containing all registered instances

Definition at line 195 of file ClassBridge'1.cs.

readonly Dictionary<EventInfo, Delegate> HybridBridge.ClassBridge< T >.StaticEventsDelegates = new Dictionary<EventInfo, Delegate>()
protected

A list containing all generated delegates for each static events

Definition at line 85 of file ClassBridge'1.cs.

List<IBridgeHandler> HybridBridge.ClassBridge< T >.SubClasses
staticprotected

A list of public and not generic sub classes

Definition at line 63 of file ClassBridge'1.cs.

List<IBridgeHandler> HybridBridge.ClassBridge< T >.SubEnumerations
staticprotected

A cached list of public sub enumerations types for this type

Definition at line 69 of file ClassBridge'1.cs.

Property Documentation

Type HybridBridge.ClassBridge< T >.GenericType = typeof(T).FullName.Replace('+', '.')
staticget

Returns the generic type used to create this class

Definition at line 205 of file ClassBridge'1.cs.

string HybridBridge.ClassBridge< T >.Identification
staticget

Returns a string containing the name of the proxy class accessible from the Javascript side

Definition at line 200 of file ClassBridge'1.cs.

Event Documentation

Event that gets raised when handler needs to push some Javascript code

Definition at line 406 of file ClassBridge'1.cs.


The documentation for this class was generated from the following files: