Пример #1
0
        private static void SetDynamicCachedCallSite <T>(BinderHash <T> hash, int knownBinderType, CallSite <T> callSite) where T : class
        {
            switch (knownBinderType)
            {
            default:
                BinderCache <T> .Cache[hash] = callSite;
                break;

            case KnownGet:
                BinderGetCache <T> .Cache[hash] = callSite;
                break;

            case KnownSet:
                BinderSetCache <T> .Cache[hash] = callSite;
                break;

            case KnownMember:
                BinderMemberCache <T> .Cache[hash] = callSite;
                break;

            case KnownDirect:
                BinderDirectCache <T> .Cache[hash] = callSite;
                break;

            case KnownConstructor:
                BinderConstructorCache <T> .Cache[hash] = callSite;
                break;
            }
        }
Пример #2
0
        internal static CallSite <T> CreateCallSite <T>(
            Type specificBinderType,
            int knownType,
            LazyBinder binder,
            string name,
            Type context,
            string[] argNames  = null,
            bool staticContext = false,
            bool isEvent       = false
            )
            where T : class
        {
            var tHash = BinderHash <T> .Create(name, context, argNames, specificBinderType, staticContext, isEvent, knownType != Unknown);

            lock (_binderCacheLock)
            {
                CallSite <T> tOut;
                if (!TryDynamicCachedCallSite(tHash, knownType, out tOut))
                {
                    tOut = CallSite <T> .Create(binder());

                    SetDynamicCachedCallSite(tHash, knownType, tOut);
                }
                return(tOut);
            }
        }
Пример #3
0
        public virtual bool Equals(BinderHash other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            var tArgNames      = this.ArgNames;
            var tOtherArgNames = other.ArgNames;
            var tGenArgs       = this.GenericArgs;
            var tOtherGenArgs  = other.GenericArgs;

            return
                (!(tOtherArgNames == null && tArgNames != null) &&
                 !(tArgNames == null && tOtherArgNames != null) &&
                 other.IsEvent == this.IsEvent &&
                 other.StaticContext == this.StaticContext &&
                 other.Context == this.Context &&
                 (this.KnownBinder || other.BinderType == this.BinderType) &&
                 other.DelegateType == this.DelegateType &&
                 Equals(other.Name, this.Name) &&
                 !(other.IsSpecialName ^ this.IsSpecialName) &&
                 !(tOtherGenArgs == null && tGenArgs != null) &&
                 !(tGenArgs == null && tOtherGenArgs != null) &&
                 (tOtherGenArgs == null || tOtherGenArgs.SequenceEqual(tGenArgs)) &&
                 (tOtherArgNames == null || tOtherArgNames.SequenceEqual(tArgNames)));
        }
Пример #4
0
        public virtual bool Equals(BinderHash other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            var tArgNames      = ArgNames;
            var tOtherArgNames = other.ArgNames;
            var tGenArgs       = GenericArgs;
            var tOtherGenArgs  = other.GenericArgs;

            return
                (!(tOtherArgNames == null ^ tArgNames == null) &&
                 other.IsEvent == IsEvent &&
                 other.StaticContext == StaticContext &&
                 Equals(other.Context, Context) &&
                 (KnownBinder || Equals(other.BinderType, BinderType)) &&
                 Equals(other.DelegateType, DelegateType) &&
                 Equals(other.Name, Name) &&
                 !(other.IsSpecialName ^ IsSpecialName) &&
                 !(tOtherGenArgs == null ^ tGenArgs == null) &&
                 (tGenArgs == null ||
                  //Exclusive Or makes sure this doesn't happen
// ReSharper disable AssignNullToNotNullAttribute
                  tGenArgs.SequenceEqual(tOtherGenArgs))
// ReSharper restore AssignNullToNotNullAttribute
                 && (tArgNames == null
                     // ReSharper disable AssignNullToNotNullAttribute
                     //Exclusive Or Makes Sure this doesn't happen

                     || tOtherArgNames.SequenceEqual(tArgNames)));
            // ReSharper restore AssignNullToNotNullAttribute
        }
Пример #5
0
        private static bool TryDynamicCachedCallSite <T>(BinderHash <T> hash, int knownBinderType, out CallSite <T> callSite) where T : class
        {
            switch (knownBinderType)
            {
            default:
                return(BinderCache <T> .Cache.TryGetValue(hash, out callSite));

            case KnownGet:
                return(BinderGetCache <T> .Cache.TryGetValue(hash, out callSite));

            case KnownSet:
                return(BinderSetCache <T> .Cache.TryGetValue(hash, out callSite));

            case KnownMember:
                return(BinderMemberCache <T> .Cache.TryGetValue(hash, out callSite));

            case KnownDirect:
                return(BinderDirectCache <T> .Cache.TryGetValue(hash, out callSite));

            case KnownConstructor:
                return(BinderConstructorCache <T> .Cache.TryGetValue(hash, out callSite));
            }
        }
Пример #6
0
        public virtual bool Equals(BinderHash other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            var tArgNames = ArgNames;
            var tOtherArgNames = other.ArgNames;
            var tGenArgs = GenericArgs;
            var tOtherGenArgs = other.GenericArgs;

            return
                !(tOtherArgNames == null ^ tArgNames == null)
                && other.IsEvent == IsEvent
                && other.StaticContext == StaticContext
                && Equals(other.Context, Context)
                && (KnownBinder || Equals(other.BinderType, BinderType))
                && Equals(other.DelegateType, DelegateType)
                && Equals(other.Name, Name)
                && !(other.IsSpecialName ^ IsSpecialName)
                && !(tOtherGenArgs == null ^ tGenArgs == null)
                && (tGenArgs == null ||
                //Exclusive Or makes sure this doesn't happen
            // ReSharper disable AssignNullToNotNullAttribute
                tGenArgs.SequenceEqual(tOtherGenArgs))
            // ReSharper restore AssignNullToNotNullAttribute
                && (tArgNames == null
                // ReSharper disable AssignNullToNotNullAttribute
                //Exclusive Or Makes Sure this doesn't happen

                                 || tOtherArgNames.SequenceEqual(tArgNames));
            // ReSharper restore AssignNullToNotNullAttribute
        }