示例#1
0
        internal static void CacheMethod(
            MethodInformation mi,
            object target,
            string methodName,
            object[] arguments,
            CallsiteCacheEntryFlags flags)
        {
            Type targetType = (flags & (CallsiteCacheEntryFlags.Static | CallsiteCacheEntryFlags.Constructor)) == CallsiteCacheEntryFlags.None ? target.GetType() : (Type)target;

            if (targetType == typeof(PSObject) || targetType == typeof(PSCustomObject))
            {
                return;
            }
            CallsiteSignature  signature = new CallsiteSignature(targetType, arguments, flags);
            CallsiteCacheEntry key       = new CallsiteCacheEntry(methodName, signature);

            lock (Adapter.callsiteCache)
            {
                if (Adapter.callsiteCache.ContainsKey(key))
                {
                    return;
                }
                if (Adapter.callsiteCache.Count > 2048)
                {
                    Adapter.callsiteCache.Clear();
                }
                Adapter.callsiteCache[key] = mi;
            }
        }
示例#2
0
        internal static MethodInformation FindCachedMethod(
            Type targetType,
            string methodName,
            object[] arguments,
            CallsiteCacheEntryFlags flags)
        {
            if (targetType == typeof(PSObject) || targetType == typeof(PSCustomObject))
            {
                return((MethodInformation)null);
            }
            CallsiteSignature  signature         = new CallsiteSignature(targetType, arguments, flags);
            CallsiteCacheEntry key               = new CallsiteCacheEntry(methodName, signature);
            MethodInformation  methodInformation = (MethodInformation)null;

            lock (Adapter.callsiteCache)
                Adapter.callsiteCache.TryGetValue(key, out methodInformation);
            return(methodInformation);
        }
示例#3
0
 public bool Equals(PSMethodInvocationConstraints other)
 {
     if (object.ReferenceEquals(null, other))
     {
         return(false);
     }
     if (!object.ReferenceEquals(this, other))
     {
         if (!object.Equals(other.MethodTargetType, this.MethodTargetType))
         {
             return(false);
         }
         if (!CallsiteSignature.EqualsForCollection <Type>(this.parameterTypes, other.parameterTypes))
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
 internal CallsiteCacheEntry(string methodName, CallsiteSignature signature)
 {
     this.methodName = methodName;
     this.signature  = signature;
 }