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); }
public void RegisterClass(Type type, string name) { ClassWrapper wrapper = ClassWrapper.CreateFromType(typeRegistry, type, name); typeRegistry.AddTypeMapping(type, wrapper, null); Context.VirtualMachine.Globals [name] = wrapper; }
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; }
/// <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); 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)) { module = new IodineModule(moduleName); modules [type.Namespace] = module; } else { module = modules [type.Namespace]; } module.SetAttribute(type.Name, ClassWrapper.CreateFromType(typeRegistry, type, type.Name)); } } }
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); }
/// <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; }
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; }
public ObjectTypeMapping(ClassWrapper wrapper, TypeRegistry registry) { classWrapper = wrapper; typeRegistry = registry; }
public ObjectWrapper(ClassWrapper clazz, object self) : base(clazz) { Object = self; }