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 static InternalMethodCallback Create(TypeRegistry registry,
			IEnumerable<MethodInfo> info,
			object self = null)
        {
            return new InternalMethodCallback (((VirtualMachine vm,
                IodineObject @this, IodineObject[] arguments) => {
                var suitableOverloads = info.Where (p => p.GetParameters ().Length == arguments.Length);

                foreach (MethodInfo overload in suitableOverloads) {
                    var types = overload.GetParameters ().Select (p => p.ParameterType).ToArray ();
                    object[] objects = new object[arguments.Length];
                    bool mappingExists = true;
                    for (int i = 0; i < arguments.Length; i++) {
                        if (!registry.TypeMappingExists (arguments [i].TypeDef, types [i])) {
                            mappingExists = false;
                            break;
                        }
                        objects [i] = registry.ConvertToNativeObject (arguments [i], types [i]);
                    }

                    if (mappingExists) {
                        return registry.ConvertToIodineObject (overload.Invoke (self, objects));
                    }
                }
                // No suitable overload found
                Console.WriteLine ("No suitable overload found!");
                return null;
            }), null);
        }
 private FieldWrapper(TypeRegistry registry, FieldInfo field, object self)
     : base(IodineProperty.TypeDefinition)
 {
     typeRegistry = registry;
     fieldInfo = field;
     this.self = self;
 }
 private PropertyWrapper(TypeRegistry registry, PropertyInfo property, object self)
     : base(IodineProperty.TypeDefinition)
 {
     typeRegistry = registry;
     propertyInfo = property;
     this.self = self;
 }
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     object[] arr = (object[])obj;
     IodineObject[] iodineObjects = new IodineObject[arr.Length];
     for (int i = 0; i < arr.Length; i++) {
         iodineObjects [i] = registry.ConvertToIodineObject (arr [i]);
     }
     return new IodineList (iodineObjects);
 }
        public static InternalMethodCallback Create(TypeRegistry registry, 
			MethodInfo info,
			object self = null)
        {
            return new InternalMethodCallback (((VirtualMachine vm,
                IodineObject @this, IodineObject[] arguments) => {
                Type[] types = info.GetParameters ().Select (p => p.ParameterType).ToArray ();
                int i = 0;
                object[] objects = arguments.Select (p => registry.ConvertToNativeObject (p,
                    types [i++])).ToArray ();
                return registry.ConvertToIodineObject (info.Invoke (self, objects));
            }), null);
        }
 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 override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     return ((IodineFloat)obj).Value;
 }
Exemple #10
0
        public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
        {
            IodineBool boolean = obj as IodineBool;

            return(boolean.Value);
        }
 public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     ObjectWrapper wrapper = obj as ObjectWrapper;
     return wrapper.Object;
 }
 public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     return Convert.ToChar (obj.ToString ());
 }
Exemple #13
0
 public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     return(((IodineInteger)obj).Value);
 }
 IodineDynamicObject(IodineObject obj, VirtualMachine vm, TypeRegistry registry)
 {
     typeRegistry = registry;
     internalObject = obj;
     internalVm = vm;
 }
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return new IodineInteger (Convert.ToInt64 (obj));
 }
Exemple #16
0
 private ClassWrapper(TypeRegistry registry, Type type, string name)
     : base(name)
 {
     typeRegistry = registry;
     this.type = type;
 }
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return ObjectWrapper.CreateFromObject (typeRegistry, classWrapper, obj);
 }
Exemple #18
0
        private static InternalMethodCallback CreateMultiMethod(TypeRegistry registry,
			Type type,
			string name)
        {
            var methods = type.GetMembers (BindingFlags.Public | BindingFlags.Static)
                .Where (p => p.Name == name && p.MemberType == MemberTypes.Method)
                .Select (p => (MethodInfo)p);
            return MethodWrapper.Create (registry, methods, null);
        }
Exemple #19
0
 public abstract object ConvertFrom(TypeRegistry registry, IodineObject obj);
Exemple #20
0
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return(new IodineInteger(Convert.ToInt64(obj)));
 }
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return new IodineFloat (Convert.ToDouble (obj));
 }
 public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     IodineBool boolean = obj as IodineBool;
     return boolean.Value;
 }
 public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     return (Int32)((IodineInteger)obj).Value;
 }
Exemple #24
0
 public override object ConvertFrom(TypeRegistry registry, IodineObject obj)
 {
     return((Single)((IodineFloat)obj).Value);
 }
Exemple #25
0
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return(new IodineFloat(Convert.ToDouble(obj)));
 }
        public static PropertyWrapper Create(TypeRegistry registry, PropertyInfo property,
			object self = null)
        {
            return new PropertyWrapper (registry, property, self);
        }
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return new IodineString (Convert.ToChar (obj).ToString ());
 }
Exemple #28
0
 public static FieldWrapper Create(TypeRegistry registry, FieldInfo field, object self = null)
 {
     return new FieldWrapper (registry, field, self);
 }
 internal static IodineDynamicObject Create(IodineObject obj, VirtualMachine vm, TypeRegistry registry)
 {
     return new IodineDynamicObject (obj, vm, registry);
 }
        private static InternalMethodCallback CreateMultiMethod(TypeRegistry registry,
			Type type,
			object self, 
			string name)
        {
            var methods = type.GetMembers (BindingFlags.Public | BindingFlags.Instance)
                .Where (p => p.Name == name && p.MemberType == MemberTypes.Method)
                .Select (p => (MethodInfo)p);

            if (methods.Count () > 1) {
                return MethodWrapper.Create (registry, methods, self);
            } else {
                return MethodWrapper.Create (registry, methods.First (), self);
            }
        }
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     return ((IodineBool)obj).Value ? IodineBool.True : IodineBool.False;
 }
Exemple #32
0
 public static PropertyWrapper Create(TypeRegistry registry, PropertyInfo property,
                                      object self = null)
 {
     return(new PropertyWrapper(registry, property, self));
 }