Ejemplo n.º 1
0
        public static void Main()
        {
            PublicMethods.Test();
            ProtectedMethods.Test();
            PrivateMethods.Test();

            Expression.Call(typeof(Derived), "PublicOnBase", Type.EmptyTypes);
            Expression.Call(typeof(Derived), "ProtectedOnBase", Type.EmptyTypes);
            Expression.Call(typeof(Derived), "PrivateOnBase", Type.EmptyTypes);

            // Keep all methods on type UnknownNameMethodClass
            Expression.Call(typeof(UnknownNameMethodClass), GetUnknownString(), Type.EmptyTypes);

            TestUnknownType.Test();

            TestGenericMethods.Test();
        }
Ejemplo n.º 2
0
        public ScriptContext Init()
        {
            if (HasInit)
            {
                return(this);
            }
            HasInit = true;

            if (InsertScriptMethods.Count > 0)
            {
                ScriptMethods.InsertRange(0, InsertScriptMethods);
            }
            if (InsertScriptBlocks.Count > 0)
            {
                ScriptBlocks.InsertRange(0, InsertScriptBlocks);
            }
            if (InsertPlugins.Count > 0)
            {
                Plugins.InsertRange(0, InsertPlugins);
            }

            foreach (var assembly in ScanAssemblies.Safe())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (typeof(IScriptPlugin).IsAssignableFrom(type))
                    {
                        if (Plugins.All(x => x.GetType() != type))
                        {
                            Container.AddSingleton(type);
                            var plugin = (IScriptPlugin)Container.Resolve(type);
                            Plugins.Add(plugin);
                        }
                    }
                }
            }

            Args[ScriptConstants.Debug] = DebugMode;

            Container.AddSingleton(() => this);
            Container.AddSingleton(() => Pages);

            ScriptLanguagesArray = ScriptLanguages.Distinct().ToArray();
            foreach (var scriptLanguage in ScriptLanguagesArray)
            {
                scriptLanguagesMap[scriptLanguage.Name] = scriptLanguage;

                if (scriptLanguage is IConfigureScriptContext init)
                {
                    init.Configure(this);
                }
            }

            var beforePlugins = Plugins.OfType <IScriptPluginBefore>();

            foreach (var plugin in beforePlugins)
            {
                plugin.BeforePluginsLoaded(this);
            }
            foreach (var plugin in Plugins)
            {
                plugin.Register(this);
            }

            OnAfterPlugins?.Invoke(this);

            foreach (var type in ScanTypes)
            {
                ScanType(type);
            }

            foreach (var assembly in ScanAssemblies.Safe())
            {
                foreach (var type in assembly.GetTypes())
                {
                    ScanType(type);
                }
            }

            foreach (var method in ScriptMethods)
            {
                InitMethod(method);
            }

            foreach (var block in ScriptBlocks)
            {
                InitBlock(block);
                blocksMap[block.Name] = block;
            }

            ScriptNamespaces = ScriptNamespaces.Distinct().ToList();

            var allTypes = new List <Type>(ScriptTypes);

            foreach (var asm in ScriptAssemblies)
            {
                allTypes.AddRange(asm.GetTypes());
            }

            foreach (var type in allTypes)
            {
                if (!ScriptTypeNameMap.ContainsKey(type.Name))
                {
                    ScriptTypeNameMap[type.Name] = type;
                }

                var qualifiedName = ProtectedMethods.typeQualifiedName(type);
                if (!ScriptTypeQualifiedNameMap.ContainsKey(qualifiedName))
                {
                    ScriptTypeQualifiedNameMap[qualifiedName] = type;
                }
            }

            var afterPlugins = Plugins.OfType <IScriptPluginAfter>();

            foreach (var plugin in afterPlugins)
            {
                plugin.AfterPluginsLoaded(this);
            }

            return(this);
        }