コード例 #1
0
 public bool TryGetAttr(ICallerContext context, SymbolId name, out object value)
 {
     if (name == SymbolTable.GeneratorNext) {
         // next is the most common call on generators, we optimize that call here.  We get
         // two benefits out of this:
         //      1. Avoid the dictionary lookup for next
         //      2. Avoid the self-check in the method descriptor (because we know we're binding to a generator)
         value = new BoundBuiltinFunction(nextFunction, this);
         return true;
     }
     return generatorType.TryGetAttr(context, this, name, out value);
 }
コード例 #2
0
        public bool TryGetAttr(ICallerContext context, SymbolId name, out object value)
        {
            switch (name.Id) {
                case SymbolTable.NameId: value = __name__; return true;
                case SymbolTable.BasesId: value = BaseClasses; return true;
                case SymbolTable.ClassId: value = ((IDynamicObject)this).GetDynamicType(); return true;
                case SymbolTable.SubclassesId:
                    BuiltinFunction rm = BuiltinFunction.MakeMethod("__subclasses__", typeof(DynamicType).GetMethod("LookupSubclasses"), FunctionType.PythonVisible | FunctionType.Method); ;
                    value = new BoundBuiltinFunction(rm, this);
                    return true;
                case SymbolTable.CallId:
                    //@todo We should provide a method wrapper object rather than directly returning ourselves
                    value = this;
                    return true;
                default:
                    if (TryLookupSlot(context, name, out value)) {
                        value = Ops.GetDescriptor(value, null, this);
                        return true;
                    }
                    break;
            }

            return false;
        }