コード例 #1
0
        private static DynamicMethodHandle GetCachedMethod(object obj, System.Reflection.MethodInfo info, params object[] parameters)
        {
            var key = new MethodCacheKey(obj.GetType().FullName, info.Name, GetParameterTypes(parameters));
            DynamicMethodHandle mh = null;
            var found = false;

            try
            {
                found = _methodCache.TryGetValue(key, out mh);
            }
            catch
            { /* failure will drop into !found block */ }
            if (!found)
            {
                lock (_methodCache)
                {
                    if (!_methodCache.TryGetValue(key, out mh))
                    {
                        mh = new DynamicMethodHandle(info, parameters);
                        _methodCache.Add(key, mh);
                    }
                }
            }
            return(mh);
        }
コード例 #2
0
        private static DynamicMethodHandle GetCachedMethod(object obj, System.Reflection.MethodInfo info, params object[] parameters)
        {
            var key = new MethodCacheKey(obj.GetType().FullName, info.Name, GetParameterTypes(parameters));
            DynamicMethodHandle mh = null;

            if (!_methodCache.TryGetValue(key, out mh))
            {
                lock (_methodCache)
                {
                    if (!_methodCache.TryGetValue(key, out mh))
                    {
                        mh = new DynamicMethodHandle(info, parameters);
                        _methodCache.Add(key, mh);
                    }
                }
            }
            return(mh);
        }
コード例 #3
0
        private static DynamicMethodHandle GetCachedMethod(object obj, string method, bool hasParameters, params object[] parameters)
        {
            var key = new MethodCacheKey(obj.GetType().FullName, method, GetParameterTypes(hasParameters, parameters));
            DynamicMethodHandle mh = null;

            if (!_methodCache.TryGetValue(key, out mh))
            {
                lock (_methodCache)
                {
                    if (!_methodCache.TryGetValue(key, out mh))
                    {
                        var info = GetMethod(obj.GetType(), method, hasParameters, parameters);
                        mh = new DynamicMethodHandle(info, parameters);
                        _methodCache.Add(key, mh);
                    }
                }
            }
            return(mh);
        }
コード例 #4
0
ファイル: MethodCaller.cs プロジェクト: MarimerLLC/csla
 private static DynamicMethodHandle GetCachedMethod(object obj, System.Reflection.MethodInfo info, params object[] parameters)
 {
   var key = new MethodCacheKey(obj.GetType().FullName, info.Name, GetParameterTypes(parameters));
   DynamicMethodHandle mh = null;
   var found = false;
   try
   {
     found = _methodCache.TryGetValue(key, out mh);
   }
   catch
   { /* failure will drop into !found block */ }
   if (!found)
   {
     lock (_methodCache)
     {
       if (!_methodCache.TryGetValue(key, out mh))
       {
         mh = new DynamicMethodHandle(info, parameters);
         _methodCache.Add(key, mh);
       }
     }
   }
   return mh;
 }
コード例 #5
0
ファイル: MethodCaller.cs プロジェクト: MarimerLLC/csla
 private static DynamicMethodHandle GetCachedMethod(object obj, string method, bool hasParameters, params object[] parameters)
 {
   var key = new MethodCacheKey(obj.GetType().FullName, method, GetParameterTypes(hasParameters, parameters));
   DynamicMethodHandle mh = null;
   if (!_methodCache.TryGetValue(key, out mh))
   {
     lock (_methodCache)
     {
       if (!_methodCache.TryGetValue(key, out mh))
       {
         var info = GetMethod(obj.GetType(), method, hasParameters, parameters);
         mh = new DynamicMethodHandle(info, parameters);
         _methodCache.Add(key, mh);
       }
     }
   }
   return mh;
 }
コード例 #6
0
ファイル: MethodCaller.cs プロジェクト: MarimerLLC/csla
    private static object CallMethod(object obj, DynamicMethodHandle methodHandle, bool hasParameters, params object[] parameters)
    {
      object result = null;
      var method = methodHandle.DynamicMethod;

      object[] inParams = null;
      if (parameters == null)
        inParams = new object[] { null };
      else
        inParams = parameters;

      if (methodHandle.HasFinalArrayParam)
      {
        // last param is a param array or only param is an array
        var pCount = methodHandle.MethodParamsLength;
        var inCount = inParams.Length;
        if (inCount == pCount - 1)
        {
          // no paramter was supplied for the param array
          // copy items into new array with last entry null
          object[] paramList = new object[pCount];
          for (var pos = 0; pos <= pCount - 2; pos++)
            paramList[pos] = parameters[pos];
          paramList[paramList.Length - 1] = hasParameters && inParams.Length == 0 ? inParams : null;

          // use new array
          inParams = paramList;
        }
        else if ((inCount == pCount && inParams[inCount - 1] != null && !inParams[inCount - 1].GetType().IsArray) || inCount > pCount)
        {
          // 1 or more params go in the param array
          // copy extras into an array
          var extras = inParams.Length - (pCount - 1);
          object[] extraArray = GetExtrasArray(extras, methodHandle.FinalArrayElementType);
          Array.Copy(inParams, pCount - 1, extraArray, 0, extras);

          // copy items into new array
          object[] paramList = new object[pCount];
          for (var pos = 0; pos <= pCount - 2; pos++)
            paramList[pos] = parameters[pos];
          paramList[paramList.Length - 1] = extraArray;

          // use new array
          inParams = paramList;
        }
      }
      try
      {
        result = methodHandle.DynamicMethod(obj, inParams);
      }
      catch (Exception ex)
      {
        throw new CallMethodException(obj.GetType().Name + "." + methodHandle.MethodName + " " + Resources.MethodCallFailed, ex);
      }
      return result;
    }
コード例 #7
0
        private static object CallMethod(object obj, DynamicMethodHandle methodHandle, bool hasParameters, params object[] parameters)
        {
            object result = null;
            var    method = methodHandle.DynamicMethod;

            object[] inParams = null;
            if (parameters == null)
            {
                inParams = new object[] { null }
            }
            ;
            else
            {
                inParams = parameters;
            }

            if (methodHandle.HasFinalArrayParam)
            {
                // last param is a param array or only param is an array
                var pCount  = methodHandle.MethodParamsLength;
                var inCount = inParams.Length;
                if (inCount == pCount - 1)
                {
                    // no paramter was supplied for the param array
                    // copy items into new array with last entry null
                    object[] paramList = new object[pCount];
                    for (var pos = 0; pos <= pCount - 2; pos++)
                    {
                        paramList[pos] = parameters[pos];
                    }
                    paramList[paramList.Length - 1] = hasParameters && inParams.Length == 0 ? inParams : null;

                    // use new array
                    inParams = paramList;
                }
                else if ((inCount == pCount && inParams[inCount - 1] != null && !inParams[inCount - 1].GetType().IsArray) || inCount > pCount)
                {
                    // 1 or more params go in the param array
                    // copy extras into an array
                    var      extras     = inParams.Length - (pCount - 1);
                    object[] extraArray = GetExtrasArray(extras, methodHandle.FinalArrayElementType);
                    Array.Copy(inParams, pCount - 1, extraArray, 0, extras);

                    // copy items into new array
                    object[] paramList = new object[pCount];
                    for (var pos = 0; pos <= pCount - 2; pos++)
                    {
                        paramList[pos] = parameters[pos];
                    }
                    paramList[paramList.Length - 1] = extraArray;

                    // use new array
                    inParams = paramList;
                }
            }
            try
            {
                result = methodHandle.DynamicMethod(obj, inParams);
            }
            catch (Exception ex)
            {
                throw new CallMethodException(obj.GetType().Name + "." + methodHandle.MethodName + " " + Resources.MethodCallFailed, ex);
            }
            return(result);
        }