/// <summary> /// Initialize /// </summary> public LFunctionType(string name) { this.Name = name; this.FullName = name; this.TypeVal = TypeConstants.Function; this.Parent = null; }
/// <summary> /// Expects the objects type to be of the supplied type. /// </summary> /// <param name="node"></param> /// <param name="result"></param> /// <param name="lType"></param> public static void ExpectType(AstNode node, object result, LType lType) { if(!(result is LObject) || ((LObject)result).Type != lType) { throw new LangException("Runtime Error", "Expected type " + lType.Name, node.Ref.ScriptName, node.Ref.Line, node.Ref.CharPos); } }
/// <summary> /// Registers methods on a specific type if no existing methods implementation are already /// registered for the type. /// </summary> /// <param name="type">The datatype for which the methods implementation are applicable</param> /// <param name="methods">The method implementations</param> public void RegisterIfNotPresent(LType type, ITypeMethods methods) { if (!_typeToMethods.ContainsKey(type)) { _typeToMethods[type] = methods; methods.OnRegistered(); } }
/// <summary> /// Register the type /// </summary> /// <param name="type">The type</param> /// <param name="fullName">The fullname of the type</param> /// <param name="name">The short name of the type</param> public static void RegisterAlias(LType type, string fullName, string name) { _types[fullName] = type; if (type.IsSystemType) { _sysBasicTypes[name] = type; } }
/// <summary> /// Registers methods on a specific type if no existing methods implementation are already /// registered for the type. /// </summary> /// <param name="type">The datatype for which the methods implementation are applicable</param> /// <param name="methods">The method implementations</param> public void RegisterIfNotPresent(LType type, ITypeMethods methods) { if (!_typeToMethods.ContainsKey(type)) { _typeToMethods[type] = methods; methods.OnRegistered(); } }
/// <summary> /// Expects the objects type to be of the supplied type. /// </summary> /// <param name="node"></param> /// <param name="result"></param> /// <param name="lType"></param> public static void NotNullType(AstNode node, object obj, string nullMessage, LType lType) { if (obj == null || obj == LObjects.Null) { throw new LangException("Runtime Error", nullMessage, node.Ref.ScriptName, node.Ref.Line, node.Ref.CharPos); } if (!(obj is LObject) || ((LObject)obj).Type != lType) { throw new LangException("Runtime Error", "Expected type " + lType.Name, node.Ref.ScriptName, node.Ref.Line, node.Ref.CharPos); } }
/// <summary> /// Get the type in the host language that represents the same type in fluentscript. /// </summary> /// <param name="ltype">The LType in fluentscript.</param> /// <returns></returns> public static Type ConvertToHostLangType(LType ltype) { if (ltype == LTypes.Bool) return typeof(bool); if (ltype == LTypes.Date) return typeof(DateTime); if (ltype == LTypes.Number) return typeof(int); if (ltype == LTypes.Number) return typeof(double); if (ltype == LTypes.String) return typeof(string); if (ltype == LTypes.Time) return typeof(TimeSpan); if (ltype == LTypes.Array) return typeof(IList); if (ltype == LTypes.Map) return typeof(IDictionary); if (ltype == LTypes.Null) return typeof(Nullable); return typeof (object); }
/// <summary> /// Is match with the type supplied and the /// </summary> /// <param name="type"></param> /// <param name="obj1"></param> /// <param name="obj2"></param> /// <returns></returns> private static bool IsTypeMatch(LType type, LObject obj1, LObject obj2) { if (obj1.Type == type && obj2.Type == type) return true; return false; }
/// <summary> /// Get the methods implementation for the supplied type. /// </summary> /// <param name="type"></param> public ITypeMethods Get(LType type) { return(_typeToMethods[type]); }
/// <summary> /// Register methods on a specific type. /// </summary> /// <param name="type">The datatype for which the methods implementation are applicable</param> /// <param name="methods">The method implementations</param> public void Register(LType type, ITypeMethods methods) { _typeToMethods[type] = methods; }
/// <summary> /// Register methods on a specific type. /// </summary> /// <param name="type">The datatype for which the methods implementation are applicable</param> /// <param name="methods">The method implementations</param> public void Register(LType type, ITypeMethods methods) { _typeToMethods[type] = methods; }
/// <summary> /// Get the methods implementation for the supplied type. /// </summary> /// <param name="type"></param> public ITypeMethods Get(LType type) { return _typeToMethods[type]; }
/// <summary> /// Whether or not there are methods for the supplied type. /// </summary> /// <param name="type"></param> public bool Contains(LType type) { return _typeToMethods.ContainsKey(type); }
/// <summary> /// Register the type /// </summary> /// <param name="type"></param> public static void Register(LType type) { RegisterAlias(type, type.FullName, type.Name); }
/// <summary> /// Whether or not there are methods for the supplied type. /// </summary> /// <param name="type"></param> public bool Contains(LType type) { return(_typeToMethods.ContainsKey(type)); }
/// <summary> /// Register the type /// </summary> /// <param name="type">The type</param> /// <param name="fullName">The fullname of the type</param> /// <param name="name">The short name of the type</param> public static void RegisterAlias(LType type, string fullName, string name) { _types[fullName] = type; if (type.IsSystemType) _sysBasicTypes[name] = type; }
/// <summary> /// Register the type /// </summary> /// <param name="type"></param> public static void Register(LType type) { RegisterAlias(type, type.FullName, type.Name); }