Esempio n. 1
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.VirtualMachine.Globals [name] = wrapper;
        }
Esempio n. 2
0
        public static ClassWrapper CreateFromType(TypeRegistry registry, Type type, string name)
        {
            ClassWrapper wrapper = new ClassWrapper(registry, type, name);

            foreach (MemberInfo info in type.GetMembers(BindingFlags.Public | BindingFlags.Static))
            {
                switch (info.MemberType)
                {
                case MemberTypes.Method:
                    if (!wrapper.HasAttribute(info.Name))
                    {
                        wrapper.SetAttribute(info.Name, CreateMultiMethod(registry, type, info.Name));
                    }
                    break;

                case MemberTypes.Field:
                    wrapper.SetAttribute(info.Name, FieldWrapper.Create(registry, (FieldInfo)info));
                    break;

                case MemberTypes.Property:
                    wrapper.SetAttribute(info.Name, PropertyWrapper.Create(registry, (PropertyInfo)info));
                    break;
                }
            }

            registry.AddTypeMapping(type, wrapper, new ObjectTypeMapping(wrapper, registry));

            return(wrapper);
        }
Esempio n. 3
0
        public static ClassWrapper CreateFromType(TypeRegistry registry, Type type, string name)
        {
            ClassWrapper wrapper = new ClassWrapper (registry, type, name);

            foreach (MemberInfo info in type.GetMembers (BindingFlags.Public | BindingFlags.Static)) {
                switch (info.MemberType) {
                case MemberTypes.Method:
                    if (!wrapper.HasAttribute (info.Name)) {

                        wrapper.SetAttribute (info.Name, CreateMultiMethod (registry, type, info.Name));
                    }
                    break;
                case MemberTypes.Field:
                    wrapper.SetAttribute (info.Name, FieldWrapper.Create (registry, (FieldInfo)info));
                    break;
                case MemberTypes.Property:
                    wrapper.SetAttribute (info.Name, PropertyWrapper.Create (registry, (PropertyInfo)info));
                    break;
                }
            }

            registry.AddTypeMapping (type, wrapper, new ObjectTypeMapping (wrapper, registry));

            return wrapper;
        }