Пример #1
0
        public override HeronValue Instantiate(VM vm, HeronValue[] args, ModuleInstance m)
        {
            Object[] objs = HeronDotNet.ObjectsToDotNetArray(args);
            Object   o    = GetSystemType().InvokeMember(null, BindingFlags.Instance | BindingFlags.Public
                                                         | BindingFlags.Default | BindingFlags.CreateInstance, null, null, objs);

            if (o == null)
            {
                throw new Exception("Unable to construct " + name);
            }
            return(DotNetObject.Marshal(o));
        }
Пример #2
0
        public static HeronValue Marshal(Object o)
        {
            if (o == null)
            {
                return(HeronValue.Null);
            }

            HeronValue ohv = o as HeronValue;

            if (ohv != null)
            {
                return(ohv);
            }

            Type t = o.GetType();

            switch (o.GetType().Name)
            {
            case "Single":
                return(new FloatValue((float)o));

            case "Double":
                double d = (double)o;
                // TEMP: Downcasts doubles to floats for now.
                return(new FloatValue((float)d));

            case "Int32":
                return(new IntValue((int)o));

            case "Char":
                return(new CharValue((char)o));

            case "String":
                return(new StringValue((string)o));

            case "Boolean":
                return(new BoolValue((bool)o));

            default:
                IList ilist = o as IList;
                if (ilist != null)
                {
                    return(new DotNetList(ilist));
                }
                IEnumerable ie = o as IEnumerable;
                if (ie != null)
                {
                    return(new ListToIterValue(ie, PrimitiveTypes.AnyType));
                }
                return(DotNetObject.CreateDotNetObjectNoMarshal(o));
            }
        }
Пример #3
0
        public override HeronValue GetFieldOrMethod(string name)
        {
            Type type = GetSystemType();

            // We have to first look to see if there are static exposedFields
            FieldInfo[] fis = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField);
            foreach (FieldInfo fi in fis)
            {
                if (fi.Name == name)
                {
                    return(DotNetObject.Marshal(fi.GetValue(obj)));
                }
            }

            // Look for methods
            MethodInfo[] mis = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod);
            if (mis.Length != 0)
            {
                return(new DotNetMethodGroup(this, name));
            }

            return(null);
        }
Пример #4
0
 public HeronValue InternalAt(int n)
 {
     return(DotNetObject.Marshal(list[n]));
 }
Пример #5
0
 public DotNetMethodGroup(DotNetObject self, string name)
 {
     this.self = self;
     this.name = name;
 }
Пример #6
0
 public override void SetValue(HeronValue self, HeronValue x)
 {
     fi.SetValue(self, DotNetObject.Unmarshal(fi.FieldType, x));
 }
Пример #7
0
 public override HeronValue GetValue(HeronValue self)
 {
     return(DotNetObject.Marshal(fi.GetValue(self)));
 }
Пример #8
0
 public DotNetMethodGroup(DotNetObject self, string name)
 {
     this.self = self;
     this.name = name;
 }