Пример #1
0
        internal T MakeUpdateDelegate()
        {
            Type[]     typeArray;
            Type       delegateType = typeof(T);
            MethodInfo method       = delegateType.GetMethod("Invoke");

            if (delegateType.IsGenericType && CallSite <T> .IsSimpleSignature(method, out typeArray))
            {
                MethodInfo info2 = null;
                MethodInfo info3 = null;
                if (method.ReturnType == typeof(void))
                {
                    if (delegateType == DelegateHelpers.GetActionType(typeArray.AddFirst <Type>(typeof(CallSite))))
                    {
                        info2 = typeof(UpdateDelegates).GetMethod("UpdateAndExecuteVoid" + typeArray.Length, BindingFlags.NonPublic | BindingFlags.Static);
                        info3 = typeof(UpdateDelegates).GetMethod("NoMatchVoid" + typeArray.Length, BindingFlags.NonPublic | BindingFlags.Static);
                    }
                }
                else if (delegateType == DelegateHelpers.GetFuncType(typeArray.AddFirst <Type>(typeof(CallSite))))
                {
                    info2 = typeof(UpdateDelegates).GetMethod("UpdateAndExecute" + (typeArray.Length - 1), BindingFlags.NonPublic | BindingFlags.Static);
                    info3 = typeof(UpdateDelegates).GetMethod("NoMatch" + (typeArray.Length - 1), BindingFlags.NonPublic | BindingFlags.Static);
                }
                if (info2 != null)
                {
                    CallSite <T> ._CachedNoMatch = (T)info3.MakeGenericMethod(typeArray).CreateDelegate(delegateType);
                    return((T)info2.MakeGenericMethod(typeArray).CreateDelegate(delegateType));
                }
            }
            CallSite <T> ._CachedNoMatch = this.CreateCustomNoMatchDelegate(method);
            return(this.CreateCustomUpdateDelegate(method));
        }