private static DrawMethod GetDrawMethod(Type type)
    {
        DrawMethod drawMethod;

        if (!DrawMethods.TryGetValue(type, out drawMethod))
        {
            DrawMethods.Add(type, (drawMethod = (DrawMethod)Delegate.CreateDelegate(CachedType <DrawMethod> .Type, DrawMethodInfo.MakeGenericMethod(new[] { type }))));
        }
        return(drawMethod);
    }
Пример #2
0
        public ComputeDataSetter(ComputeBuffer buffer)
        {
            var method = typeof(ComputeBuffer).GetMethod
                             ("InternalSetNativeData",
                             BindingFlags.InvokeMethod |
                             BindingFlags.NonPublic |
                             BindingFlags.Instance);

            _setData = (SetDataDelegate)Delegate.CreateDelegate
                           (typeof(SetDataDelegate), buffer, method);
        }
 public static Delegate ReplaceWith(Delegate d, Type delegateType)
 {
     return(Delegate.CreateDelegate(delegateType, d.Target, d.Method));
 }
Пример #4
0
        private static List <AttachDetach> GetCached(object pub, object sub)
        {
            var subType    = sub.GetType();
            var subMethods = subType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            var pubType    = pub.GetType();
            var pubEvents  = pubType.GetEvents();
            var cacheKey   = ExampleLibrary.StaticTuple.Create(pubType, subType);
            List <AttachDetach> cacheValue;

            if (!cache.TryGetValue(cacheKey, out cacheValue))
            {
                cacheValue = new List <AttachDetach>();
                foreach (var pubEvent in pubEvents)
                {
                    var addMethod        = pubEvent.GetAddMethod();
                    var addMethodName    = addMethod.Name;
                    var removeMethod     = pubEvent.GetRemoveMethod();
                    var removeMethodName = removeMethod.Name;
                    var targetMethodName = "Handle" + pubType.Name + pubEvent.Name;
                    var handlerMethod    = subType.GetMethod(targetMethodName, BindingFlags.Instance | BindingFlags.NonPublic);
                    if (addMethod != null &&
                        removeMethod != null &&
                        handlerMethod != null &&
                        handlerMethod.ReturnType == typeof(void))
                    {
                        var delegateParameters = addMethod.GetParameters().Select(x => x.ParameterType.GetMethod("Invoke")).Single(x => x != null).GetParameters();
                        var parameters         = handlerMethod.GetParameters();
                        if (parameters.Length == delegateParameters.Length &&
                            parameters.Zip(delegateParameters, (a, b) => (a.ParameterType == b.ParameterType) ? a : null).All(x => x != null))
                        {
                            cacheValue.Add(
                                new AttachDetach(
                                    new Action <object, object>((p, s) => addMethod.Invoke(p, new object[] { Delegate.CreateDelegate(pubEvent.EventHandlerType, s, handlerMethod) })),
                                    new Action <object, object>((p, s) => removeMethod.Invoke(p, new object[] { Delegate.CreateDelegate(pubEvent.EventHandlerType, s, handlerMethod) }))));
                        }
                    }
                }

                var newCache = cache.ToList().ToDictionary(x => x.Key, x => x.Value);
                if (!newCache.ContainsKey(cacheKey))
                {
                    newCache[cacheKey] = cacheValue;
                    cache = newCache;
                }
            }

            return(cacheValue);
        }
        // Token: 0x0600025F RID: 607 RVA: 0x000061D0 File Offset: 0x000043D0
        private static bool SetupDelegate()
        {
            Type type = typeof(object).Assembly.GetType("System.AppContext");

            if (type == null)
            {
                return(false);
            }
            MethodInfo method = type.GetMethod("TryGetSwitch", BindingFlags.Static | BindingFlags.Public, null, new Type[]
            {
                typeof(string),
                typeof(bool).MakeByRefType()
            }, null);

            if (method == null)
            {
                return(false);
            }
            LocalAppContext.TryGetSwitchFromCentralAppContext = (LocalAppContext.TryGetSwitchDelegate)Delegate.CreateDelegate(typeof(LocalAppContext.TryGetSwitchDelegate), method);
            return(true);
        }