Ejemplo n.º 1
0
        public static MethodInfo GetConsoleMethod(Type[] methodArguments)
        {
#if (NETSTANDARD)
            return(CompatReflectionExtensions.GetRuntimeMethod(typeof(Debug), nameof(Debug.WriteLine), methodArguments));
#else
            return(CompatReflectionExtensions.GetRuntimeMethod(typeof(Console), nameof(Console.WriteLine), methodArguments));
#endif
        }
        private static MethodInfo GetMethodInfoByDelegate <THandler>(THandler @delegate) where THandler : Delegate
        {
            var methodInfo = @delegate == null
                                ? CompatReflectionExtensions.GetRuntimeMethods(typeof(THandler)).FirstOrDefault(d => d.Name == nameof(MethodInfo.Invoke))
                                : CompatReflectionExtensions.GetMethodInfo(@delegate);

            return(methodInfo);
        }
Ejemplo n.º 3
0
        public void Add(THandler @delegate)
        {
            bool lockTaken = false;

            try
            {
                lockTaken = Monitor.TryEnter(_lock);
                if (lockTaken && _invoker == null)
                {
                    _invoker = WeakEventDelegateFactory.Create(@delegate, _handles);
                }
                _handles.Insert(0, new WeakDelegate <THandler>(CompatReflectionExtensions.GetMethodInfo(@delegate), @delegate.Target));
            }
            finally
            {
                if (lockTaken)
                {
                    Monitor.Exit(_lock);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if the handler is equivalent to the contained WeakReferences
        /// </summary>
        /// <param name="delegate">delegate</param>
        /// <returns>true if delegate is matching</returns>
        public bool IsMatch(THandler @delegate)
        {
            if (!_method.TryGetTarget(out var method))
            {
                return(false);
            }

            if (method.IsStatic)
            {
                return(ReferenceEquals(method, CompatReflectionExtensions.GetMethodInfo(@delegate)));
            }
            else
            {
                if (!_target.TryGetTarget(out var target))
                {
                    return(false);
                }

                return(ReferenceEquals(target, @delegate.Target) &&
                       ReferenceEquals(method, CompatReflectionExtensions.GetMethodInfo(@delegate)));
            }
        }
 private static MethodInfo GetMethodInfoInvokeMethod()
 {
     return(CompatReflectionExtensions.GetRuntimeMethod(typeof(MethodInfo), nameof(MethodInfo.Invoke), typeof(object), typeof(object[])));
 }
 private static MethodInfo GetTaskListAddMethod()
 {
     return(CompatReflectionExtensions.GetRuntimeMethod(typeof(List <Task>), nameof(IList.Add), typeof(Task)));
 }
 private static MethodInfo GetDelegateListRemoveAtMethod <THandler>() where THandler : Delegate
 {
     return(CompatReflectionExtensions.GetRuntimeMethod(typeof(List <WeakDelegate <THandler> >), nameof(IList.RemoveAt), typeof(int)));
 }
 private static PropertyInfo GetListItemIndexerProperty <THandler>() where THandler : Delegate
 {
     return(CompatReflectionExtensions.GetRuntimeProperty(typeof(List <WeakDelegate <THandler> >), "Item"));
 }
 private static PropertyInfo GetMethodInfoIsStaticProperty <THandler>() where THandler : Delegate
 {
     return(CompatReflectionExtensions.GetRuntimeProperty(typeof(MethodInfo), nameof(MethodInfo.IsStatic)));
 }
 private static MethodInfo GetListCountGetterMethod <THandler>() where THandler : Delegate
 {
     return(CompatReflectionExtensions.GetRuntimeMethod(typeof(List <WeakDelegate <THandler> >), "get_Count"));
 }
 private static MethodInfo GetWeakDelegateGetHandleInfoMethod <THandler>() where THandler : Delegate
 {
     return(CompatReflectionExtensions.GetRuntimeMethod(typeof(WeakDelegate <THandler>), nameof(WeakDelegate <THandler> .GetHandleInfo), new [] { typeof(MethodInfo).MakeByRefType(), typeof(object).MakeByRefType() }));
 }
 private static MethodInfo GetTaskWhenAllMethod()
 {
     return(CompatReflectionExtensions.GetRuntimeMethod(typeof(TaskExtensions), nameof(TaskExtensions.WhenAll), typeof(IEnumerable <Task>)));
 }
 private static ConstructorInfo GetTaskListConstructorInfo()
 {
     return(CompatReflectionExtensions.GetConstructorInfo(typeof(List <Task>), NoTypes));
 }