예제 #1
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;
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        public static ObjectWrapper CreateFromObject(TypeRegistry registry, ClassWrapper clazz, object obj)
        {
            Type          type    = obj.GetType();
            ObjectWrapper wrapper = new ObjectWrapper(clazz, obj);

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

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

                case MemberTypes.Property:
                    wrapper.SetAttribute(info.Name, PropertyWrapper.Create(registry, (PropertyInfo)info,
                                                                           obj));
                    break;
                }
            }
            return(wrapper);
        }
예제 #4
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;
		}
예제 #5
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);
        }
예제 #6
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;
        }
예제 #7
0
		public static ObjectWrapper CreateFromObject (TypeRegistry registry, ClassWrapper clazz, object obj)
		{
			Type type = obj.GetType ();
			ObjectWrapper wrapper = new ObjectWrapper (clazz, obj);
			foreach (MemberInfo info in type.GetMembers (BindingFlags.Instance | BindingFlags.Public)) {
				switch (info.MemberType) {
				case MemberTypes.Method:
					if (!wrapper.HasAttribute (info.Name)) {
						wrapper.SetAttribute (info.Name, CreateMultiMethod (registry, type, obj,
							info.Name));
					}
					break;
				case MemberTypes.Field:
					wrapper.SetAttribute (info.Name, FieldWrapper.Create (registry, (FieldInfo)info,
						obj));
					break;
				case MemberTypes.Property:
					wrapper.SetAttribute (info.Name, PropertyWrapper.Create (registry, (PropertyInfo)info,
						obj));
					break;
				}
			}
			return wrapper;
		}
예제 #8
0
		public ObjectWrapper (ClassWrapper clazz, object self)
			: base (clazz)
		{
			Object = self;
		}
예제 #9
0
 public ObjectTypeMapping(ClassWrapper wrapper, TypeRegistry registry)
 {
     classWrapper = wrapper;
     typeRegistry = registry;
 }
예제 #10
0
 public ObjectWrapper(ClassWrapper clazz, object self)
     : base(clazz)
 {
     Object = self;
 }
예제 #11
0
		public ObjectTypeMapping (ClassWrapper wrapper, TypeRegistry registry)
		{
			classWrapper = wrapper;
			typeRegistry = registry;
		}