Esempio n. 1
0
        /// <summary>
        /// Returns module, which provides access to clr-namespace
        /// </summary>
        /// <param name="namespace">Namespace</param>
        /// <returns></returns>
        public static Module ClrNamespace(string @namespace)
        {
            var result = new Module();

            foreach (var type in NamespaceProvider.GetTypesByPrefix(@namespace))
            {
                try
                {
                    if (type.Namespace == @namespace)
                    {
                        result.Exports[type.Name] = Context.CurrentGlobalContext.GetConstructor(type);
                    }
                    else if (type.Namespace.StartsWith(@namespace) && type.Namespace[@namespace.Length] == '.')
                    {
                        var nextSegment = type.Namespace.Substring(@namespace.Length).Split('.')[1];
                        result.Exports[nextSegment] = new NamespaceProvider($"{@namespace}.{nextSegment}");
                    }
                }
                catch
                { }
            }

            return(result);
        }
Esempio n. 2
0
        internal protected override JSValue GetProperty(JSValue key, bool forWrite, PropertyScope memberScope)
        {
            if (memberScope < PropertyScope.Super && key._valueType != JSValueType.Symbol)
            {
                var     name = key.ToString();
                JSValue res  = null;
                if (childs != null && childs.TryGetValue(name, out res))
                {
                    return(res);
                }
                string reqname   = Namespace + "." + name;
                var    selection = types.StartedWith(reqname).GetEnumerator();

                Type        resultType = null;
                List <Type> ut         = null;

                while (selection.MoveNext())
                {
                    if (selection.Current.Value.FullName.Length > reqname.Length &&
                        selection.Current.Value.FullName[reqname.Length] == '`')
                    {
                        string fn = selection.Current.Value.FullName;
                        for (var i = fn.Length - 1; i > reqname.Length; i--)
                        {
                            if (!Tools.IsDigit(fn[i]))
                            {
                                fn = null;
                                break;
                            }
                        }

                        if (fn != null)
                        {
                            if (resultType == null)
                            {
                                resultType = selection.Current.Value;
                            }
                            else
                            {
                                if (ut == null)
                                {
                                    ut = new List <Type> {
                                        resultType
                                    }
                                }
                                ;

                                ut.Add(selection.Current.Value);
                            }
                        }
                    }
                    else if (selection.Current.Value.Name != name)
                    {
                        break;
                    }
                    else
                    {
                        resultType = selection.Current.Value;
                    }
                }

                if (ut != null)
                {
                    res = Proxy.GetGenericTypeSelector(ut);

                    if (childs == null)
                    {
                        childs = new BinaryTree <JSValue>();
                    }

                    childs[name] = res;
                    return(res);
                }

                if (resultType != null)
                {
                    return(Context.CurrentBaseContext.GetConstructor(resultType));
                }

                selection = types.StartedWith(reqname).GetEnumerator();
                if (selection.MoveNext() && selection.Current.Key[reqname.Length] == '.')
                {
                    res = new NamespaceProvider(reqname);

                    if (childs == null)
                    {
                        childs = new BinaryTree <JSValue>();
                    }

                    childs.Add(name, res);
                    return(res);
                }
            }

            return(undefined);
        }