Example #1
0
        internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value)
        {
            IWeakReferenceable reference = instance as IWeakReferenceable;

            if (reference != null)
            {
                return(reference.SetWeakRef(new WeakRefTracker(value, instance)));
            }
            return(false);
        }
Example #2
0
            public static WeakRefTracker InitializeWeakRef(PythonContext context, object self, object target, object callback)
            {
                IWeakReferenceable iwr = ConvertToWeakReferenceable(context, target);

                WeakRefTracker wrt = iwr.GetWeakRef();

                if (wrt == null)
                {
                    if (!iwr.SetWeakRef(wrt = new WeakRefTracker(iwr)))
                    {
                        throw PythonOps.TypeError("cannot create weak reference to '{0}' object", PythonOps.GetPythonTypeName(target));
                    }
                }

                wrt.ChainCallback(callback, self);
                return(wrt);
            }
Example #3
0
            public static void InitializeWeakRef(object self, object target, object callback)
            {
                IWeakReferenceable iwr = target as IWeakReferenceable;

                if (iwr == null)
                {
                    throw Ops.TypeError("cannot create weak reference to '{0}' object", Ops.GetDynamicType(target).__name__);
                }

                WeakRefTracker wrt = iwr.GetWeakRef();

                if (wrt == null)
                {
                    iwr.SetWeakRef(new WeakRefTracker(callback, self));
                }
                else
                {
                    wrt.ChainCallback(callback, self);
                }
            }