示例#1
0
        /// <summary>
        /// Registers an assembly, allowing all classes in this assembly to be
        /// used from Iodine.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        public void RegisterAssembly(Assembly assembly)
        {
            var classes = assembly.GetExportedTypes().Where(p => p.IsClass || p.IsValueType || p.IsInterface);

            foreach (Type type in classes)
            {
                if (type.Namespace != "")
                {
                    string moduleName = type.Namespace.Contains(".") ?
                                        type.Namespace.Substring(type.Namespace.LastIndexOf(".") + 1) :
                                        type.Namespace;
                    IodineModule module = null;
                    if (!modules.ContainsKey(type.Namespace))
                    {
                        #warning This needs fixed
                        //module = new IodineModule (moduleName);
                        modules [type.Namespace] = module;
                    }
                    else
                    {
                        module = modules [type.Namespace];
                    }
                    ClassWrapper wrapper = ClassWrapper.CreateFromType(typeRegistry, type,
                                                                       type.Name);
                    module.SetAttribute(type.Name, wrapper);
                    typeRegistry.AddTypeMapping(type, wrapper, null);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Registers a C# class in Iodine
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="name">Name.</param>
        public void RegisterClass(Type type, string name)
        {
            ClassWrapper wrapper = ClassWrapper.CreateFromType(typeRegistry, type, name);

            typeRegistry.AddTypeMapping(type, wrapper, null);
            Context.Globals [name] = wrapper;
        }
示例#3
0
        /// <summary>
        /// Registers a class in the global namespace, allowing it to be
        /// instantiated in Iodine
        /// </summary>
        /// <param name="name">Name of the class.</param>
        /// <typeparam name="T">The class.</typeparam>
        public void RegisterClass <T> (string name)
            where T : class
        {
            Type         type    = typeof(T);
            ClassWrapper wrapper = ClassWrapper.CreateFromType(typeRegistry, type, name);

            typeRegistry.AddTypeMapping(type, wrapper, null);
            Context.Globals [name] = wrapper;
        }