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; } }
internal static CallSite <T> CreateCallSite <T>( Type specificBinderType, int knownType, LazyBinder binder, InvokeMemberName 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); } }
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 }
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)); } }