Beispiel #1
0
        public Work AddOrUpdate(IndirectionInfo info, Work method)
        {
            var holder = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <BodyOfNonPublicMethod, Dictionary <string, Work> > > >();

            if (holder.Source.Value == null)
            {
                holder.Source = TaggedBagFactory <BodyOfNonPublicMethod> .Make(new Dictionary <string, Work>());
            }

            var dict = holder.Source.Value;

            lock (dict)
            {
                using (InstanceGetters.DisableProcessing())
                {
                    var key = info + "";
                    holder.Source.Value[key] = method;

                    var wrapAndInvoke = CreateWrapAndInvokeMethod(IndirectionDelegate, key);
                    m_holder.AddOrUpdate(info, wrapAndInvoke);

                    dict[key] = method;
                    return(method);
                }
            }
        }
Beispiel #2
0
        public bool TryRemove(IndirectionInfo info, out Work method)
        {
            method = default(Work);

            var holder = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <BodyOfNonPublicMethod, Dictionary <string, Work> > > >();

            if (holder.Source.Value == null)
            {
                return(false);
            }

            var dict = holder.Source.Value;

            lock (dict)
            {
                using (InstanceGetters.DisableProcessing())
                {
                    var _ = default(Delegate);
                    if (!m_holder.TryRemove(info, out _))
                    {
                        return(false);
                    }

                    var key = info + "";
                    if (!dict.ContainsKey(key))
                    {
                        return(false);
                    }

                    method = dict[key];
                    dict.Remove(key);
                    return(true);
                }
            }
        }
Beispiel #3
0
        protected void SetTargetInstanceBody <TBehaviorPreparableImpl, TBody>(
            object target, TBody value, Func <TBody> getBodyOfDefaultBehavior, Action <TBody, Dictionary <object, TargetSettingValue <TBody> > > setBodyExecutingDefaultOr)
            where TBehaviorPreparableImpl : BehaviorPreparableImpl
            where TBody : class
        {
            if (!typeof(Delegate).IsAssignableFrom(typeof(TBody)))
            {
                throw new ArgumentException("The generic parameter must be a delegate type.", "TBody");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            RuntimeHelpers.PrepareDelegate(value as Delegate);

            var holder = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <TBehaviorPreparableImpl, Dictionary <object, TargetSettingValue <TBody> > > > >();

            if (holder.Source.Value == null)
            {
                holder.Source = TaggedBagFactory <TBehaviorPreparableImpl> .Make(new Dictionary <object, TargetSettingValue <TBody> >());
            }

            var dic = holder.Source.Value;

            if (!dic.ContainsKey(target))
            {
                var behavior = getBodyOfDefaultBehavior();
                RuntimeHelpers.PrepareDelegate(behavior as Delegate);
                dic[target] = new TargetSettingValue <TBody>(behavior, value);
                {
                    // Prepare JIT
                    var original    = dic[target].Original;
                    var indirection = dic[target].Indirection;
                }

                setBodyExecutingDefaultOr(behavior, dic);
            }
            else
            {
                var before = dic[target];
                dic[target] = new TargetSettingValue <TBody>(before.Original, value);
            }
        }
Beispiel #4
0
        protected void RemoveTargetInstanceBody <TBehaviorPreparableImpl, TBody>(object target, Action <TBody> setBodyToOriginal)
            where TBehaviorPreparableImpl : BehaviorPreparableImpl
            where TBody : class
        {
            if (!typeof(Delegate).IsAssignableFrom(typeof(TBody)))
            {
                throw new ArgumentException("The generic parameter must be a delegate type.", "TBody");
            }

            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            var holder = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <TBehaviorPreparableImpl, Dictionary <object, TargetSettingValue <TBody> > > > >();

            if (holder.Source.Value == null)
            {
                return;
            }

            var dic = holder.Source.Value;

            if (dic.Count == 0)
            {
                return;
            }

            var before = default(TargetSettingValue <TBody>);

            if (dic.ContainsKey(target))
            {
                before = dic[target];
                dic.Remove(target);
            }
            if (dic.Count == 0)
            {
                setBodyToOriginal(before.Original);
            }
        }
        public static IndirectionHolderUntyped GetOrRegister(Type indDlgt)
        {
            var holder = LooseCrossDomainAccessor.GetOrRegister <IndirectionHolder <Delegate> >();

            return(new IndirectionHolderUntyped(holder, indDlgt));
        }