Ejemplo n.º 1
0
 protected override DynamicMetaObject GetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type instanceType, DynamicMetaObject instance)
 {
     return(new DynamicMetaObject(
                Ast.Call(
                    typeof(PythonOps).GetMethod(nameof(PythonOps.SlotGetValue)),
                    ((PythonOverloadResolverFactory)factory)._codeContext,
                    AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)),
                    AstUtils.Convert(
                        instance.Expression,
                        typeof(object)
                        ),
                    AstUtils.Constant(DynamicHelpers.GetPythonTypeFromType(instanceType))
                    ),
                BindingRestrictions.Empty
                ));
 }
Ejemplo n.º 2
0
            public object InPlaceAdd(CodeContext /*!*/ context, object func)
            {
                if (func == null || !PythonOps.IsCallable(context, func))
                {
                    throw PythonOps.TypeError("event addition expected callable object, got {0}", PythonOps.GetPythonTypeName(func));
                }

                if (_event.Tracker.IsStatic)
                {
                    if (_ownerType != DynamicHelpers.GetPythonTypeFromType(_event.Tracker.DeclaringType))
                    {
                        // mutating static event, only allow this from the type we're mutating, not sub-types
                        return(new BadEventChange(_ownerType, _instance));
                    }
                }

                MethodInfo add = _event.Tracker.GetCallableAddMethod();

                // TODO (tomat): this used to use event.ReflectedType, is it still correct?
                if (_instance != null)
                {
                    add = CompilerHelpers.TryGetCallableMethod(_instance.GetType(), add);
                }

                if (CompilerHelpers.IsVisible(add) ||
                    (add.IsProtected() /*todo: validate current context is in family*/) ||
                    context.LanguageContext.DomainManager.Configuration.PrivateBinding)
                {
                    _event.Tracker.AddHandler(_instance, func, context.LanguageContext.DelegateCreator);
                }
                else
                {
                    throw new TypeErrorException("Cannot add handler to a private event.");
                }

                return(this);
            }
Ejemplo n.º 3
0
 public string /*!*/ __repr__(CodeContext /*!*/ context)
 {
     return(String.Format("<method '{0}' of '{1}' objects>",
                          Template.Name,
                          DynamicHelpers.GetPythonTypeFromType(DeclaringType).Name));
 }
Ejemplo n.º 4
0
 public string /*!*/ __repr__(CodeContext /*!*/ context)
 {
     return(string.Format("<property# {0} on {1}>",
                          __name__,
                          DynamicHelpers.GetPythonTypeFromType(DeclaringType).Name));
 }
Ejemplo n.º 5
0
 internal override bool TryDeleteValue(CodeContext /*!*/ context, object instance, PythonType owner)
 {
     Assert.NotNull(context, owner);
     throw ReadOnlyException(DynamicHelpers.GetPythonTypeFromType(Info.DeclaringType));
 }
Ejemplo n.º 6
0
 public static ReflectedEvent.BoundEvent MakeBoundEvent(ReflectedEvent eventObj, object instance, Type type)
 {
     return(new ReflectedEvent.BoundEvent(eventObj, instance, DynamicHelpers.GetPythonTypeFromType(type)));
 }