Exemplo n.º 1
0
 private void DoSet(object instance, object val)
 {
     PerfTrack.NoteEvent(PerfTrack.Categories.Properties, this);
     if (setter == null)
     {
         throw Ops.TypeError("readonly attribute");
     }
     setter.Invoke(instance,
                   new object[] { Ops.ConvertTo(val, info.PropertyType) });
 }
Exemplo n.º 2
0
        public override object Call(ICallerContext context, object[] args)
        {
            if (optCtor != null && args.Length == 1)
            {
                return(optCtor(args[0]));
            }
            if (optCtor2 != null && args.Length == 1)
            {
                return(optCtor2(context, args[0]));
            }

            PerfTrack.NoteEvent(PerfTrack.Categories.Methods, "TypeInvoke " + this.__name__ + args.Length);
            return(base.Call(context, args));
        }
Exemplo n.º 3
0
 public object GetAttribute(object instance, object context)
 {
     PerfTrack.NoteEvent(PerfTrack.Categories.Fields, this);
     if (instance == null)
     {
         if (info.IsStatic)
         {
             return(Ops.ToPython(info.GetValue(null)));
         }
         else
         {
             return(this);
         }
     }
     else
     {
         return(Ops.ToPython(info.GetValue(instance))); //.toObject(info.DeclaringType, "get ")));
     }
 }
Exemplo n.º 4
0
        private static object[] MakeItems(object o)
        {
            var t = o.GetType();

            // Only use fast paths if we have an exact tuple/list, otherwise use iter
            if (t == typeof(PythonTuple))
            {
                return(((PythonTuple)o)._data);
            }
            else if (t == typeof(PythonList))
            {
                return(((PythonList)o).GetObjectArray());
            }
            else if (o is string)
            {
                string   s   = (string)o;
                object[] res = new object[s.Length];
                for (int i = 0; i < res.Length; i++)
                {
                    res[i] = ScriptingRuntimeHelpers.CharToString(s[i]);
                }
                return(res);
            }
            else if (o is object[] arr)
            {
                return(ArrayOps.CopyArray(arr, arr.Length));
            }
            else
            {
                PerfTrack.NoteEvent(PerfTrack.Categories.OverAllocate, "TupleOA: " + PythonTypeOps.GetName(o));

                List <object> l = new List <object>();
                IEnumerator   i = PythonOps.GetEnumerator(o);
                while (i.MoveNext())
                {
                    l.Add(i.Current);
                }

                return(l.ToArray());
            }
        }
Exemplo n.º 5
0
        private static object[] MakeItems(object o)
        {
            object[] arr;
            if (o is PythonTuple)
            {
                return(((PythonTuple)o)._data);
            }
            else if (o is string)
            {
                string   s   = (string)o;
                object[] res = new object[s.Length];
                for (int i = 0; i < res.Length; i++)
                {
                    res[i] = ScriptingRuntimeHelpers.CharToString(s[i]);
                }
                return(res);
            }
            else if (o is List)
            {
                return(((List)o).GetObjectArray());
            }
            else if ((arr = o as object[]) != null)
            {
                return(ArrayOps.CopyArray(arr, arr.Length));
            }
            else
            {
                PerfTrack.NoteEvent(PerfTrack.Categories.OverAllocate, "TupleOA: " + PythonTypeOps.GetName(o));

                List <object> l = new List <object>();
                IEnumerator   i = PythonOps.GetEnumerator(o);
                while (i.MoveNext())
                {
                    l.Add(i.Current);
                }

                return(l.ToArray());
            }
        }
Exemplo n.º 6
0
 public object GetAttribute(object instance, object context)
 {
     PerfTrack.NoteEvent(PerfTrack.Categories.Properties, this);
     if (getter == null)
     {
         throw Ops.TypeError("writeonly attribute");
     }
     if (instance == null)
     {
         if (getter.IsStatic)
         {
             return(Ops.ToPython(getter.Invoke(null, new object[0])));
         }
         else
         {
             return(this);
         }
     }
     else
     {
         return(Ops.ToPython(getter.Invoke(instance, new object[0])));
     }
 }