|
|
@@ -6,9 +6,6 @@ using System.Globalization;
|
|
|
using System.Reflection;
|
|
|
|
|
|
#if HAS_WINRT
|
|
|
-#if CRIPPLED_REFLECTION
|
|
|
-using System.Collections.Generic;
|
|
|
-#endif
|
|
|
using System.Runtime.InteropServices.WindowsRuntime;
|
|
|
#endif
|
|
|
|
|
|
@@ -18,20 +15,12 @@ namespace System.Reactive
|
|
|
{
|
|
|
public static TDelegate CreateDelegate<TDelegate>(object o, MethodInfo method)
|
|
|
{
|
|
|
-#if (CRIPPLED_REFLECTION && HAS_WINRT)
|
|
|
return (TDelegate)(object)method.CreateDelegate(typeof(TDelegate), o);
|
|
|
-#else
|
|
|
- return (TDelegate)(object)Delegate.CreateDelegate(typeof(TDelegate), o, method);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
public static Delegate CreateDelegate(Type delegateType, object o, MethodInfo method)
|
|
|
{
|
|
|
-#if (CRIPPLED_REFLECTION && HAS_WINRT)
|
|
|
return method.CreateDelegate(delegateType, o);
|
|
|
-#else
|
|
|
- return Delegate.CreateDelegate(delegateType, o, method);
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
public static void GetEventMethods<TSender, TEventArgs>(Type targetType, object target, string eventName, out MethodInfo addMethod, out MethodInfo removeMethod, out Type delegateType, out bool isWinRT)
|
|
|
@@ -40,7 +29,7 @@ namespace System.Reactive
|
|
|
|
|
|
if (target == null)
|
|
|
{
|
|
|
- e = targetType.GetEventEx(eventName, true);
|
|
|
+ e = targetType.GetEvent(eventName, BindingFlags.Public | BindingFlags.Static);
|
|
|
if (e == null)
|
|
|
{
|
|
|
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.COULD_NOT_FIND_STATIC_EVENT, eventName, targetType.FullName));
|
|
|
@@ -48,7 +37,7 @@ namespace System.Reactive
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- e = targetType.GetEventEx(eventName, false);
|
|
|
+ e = targetType.GetEvent(eventName, BindingFlags.Public | BindingFlags.Instance);
|
|
|
if (e == null)
|
|
|
{
|
|
|
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Strings_Linq.COULD_NOT_FIND_INSTANCE_EVENT, eventName, targetType.FullName));
|
|
|
@@ -122,48 +111,8 @@ namespace System.Reactive
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static EventInfo GetEventEx(this Type type, string name, bool isStatic)
|
|
|
- {
|
|
|
-#if (CRIPPLED_REFLECTION && HAS_WINRT)
|
|
|
- // TODO: replace in the future by System.Reflection.RuntimeExtensions extension methods
|
|
|
- var q = new Queue<TypeInfo>();
|
|
|
- q.Enqueue(type.GetTypeInfo());
|
|
|
-
|
|
|
- while (q.Count > 0)
|
|
|
- {
|
|
|
- var t = q.Dequeue();
|
|
|
-
|
|
|
- var e = t.GetDeclaredEvent(name);
|
|
|
- if (e != null)
|
|
|
- {
|
|
|
- return e;
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var i in t.ImplementedInterfaces)
|
|
|
- {
|
|
|
- q.Enqueue(i.GetTypeInfo());
|
|
|
- }
|
|
|
-
|
|
|
- if (t.BaseType != null)
|
|
|
- {
|
|
|
- q.Enqueue(t.BaseType.GetTypeInfo());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return null;
|
|
|
-#else
|
|
|
- return type.GetEvent(name, isStatic ? BindingFlags.Public | BindingFlags.Static : BindingFlags.Public | BindingFlags.Instance);
|
|
|
-#endif
|
|
|
- }
|
|
|
-
|
|
|
#if (CRIPPLED_REFLECTION && HAS_WINRT)
|
|
|
public static MethodInfo GetMethod(this Type type, string name) => type.GetTypeInfo().GetDeclaredMethod(name);
|
|
|
-
|
|
|
- public static MethodInfo GetAddMethod(this EventInfo eventInfo) => eventInfo.AddMethod;
|
|
|
-
|
|
|
- public static MethodInfo GetRemoveMethod(this EventInfo eventInfo) => eventInfo.RemoveMethod;
|
|
|
-
|
|
|
- public static bool IsAssignableFrom(this Type type1, Type type2) => type1.GetTypeInfo().IsAssignableFrom(type2.GetTypeInfo());
|
|
|
#endif
|
|
|
}
|
|
|
}
|