/// <summary> /// The get property ex. /// </summary> /// <param name="type">The type.</param> /// <param name="name">The name.</param> /// <param name="flattenHierarchy">The flatten hierarchy.</param> /// <param name="allowStaticMembers">The allow static members.</param> /// <param name="allowExplicitInterfaceProperties">if set to <c>true</c>, this method will check for explicit interface implementations when the property is not found.</param> /// <returns>PropertyInfo.</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> /// <exception cref="System.ArgumentException">The <paramref name="name" /> is <c>null</c> or whitespace.</exception> public static PropertyInfo GetPropertyEx(this Type type, string name, bool flattenHierarchy = true, bool allowStaticMembers = false, bool allowExplicitInterfaceProperties = true) { BindingFlags bindingFlags = BindingFlagsHelper.GetFinalBindingFlags(flattenHierarchy, allowStaticMembers); return(GetPropertyEx(type, name, bindingFlags, allowExplicitInterfaceProperties)); }
/// <summary> /// The get events ex. /// </summary> /// <param name="type">The type.</param> /// <param name="flattenHierarchy">The flatten Hierarchy.</param> /// <param name="allowStaticMembers">The allow Static Members.</param> /// <returns>EventInfo[][].</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> public static EventInfo[] GetEventsEx(this Type type, bool flattenHierarchy = true, bool allowStaticMembers = false) { Argument.IsNotNull("type", type); var bindingFlags = BindingFlagsHelper.GetFinalBindingFlags(flattenHierarchy, allowStaticMembers); return(type.GetTypeInfo().GetEvents(bindingFlags)); }
/// <summary> /// Creates a delegate for the specified method and target. /// </summary> /// <param name="delegateType">Type of the delegate.</param> /// <param name="target">The target. Cannot be <c>null</c> for this method.</param> /// <param name="methodName">Name of the method.</param> /// <returns>The delegate.</returns> /// <exception cref="ArgumentNullException">The <paramref name="delegateType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="target"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The <paramref name="methodName"/> is <c>null</c> or whitespace.</exception> public static Delegate CreateDelegate(Type delegateType, object target, string methodName) { Argument.IsNotNull("delegateType", delegateType); Argument.IsNotNull("target", target); Argument.IsNotNullOrWhitespace("methodName", methodName); var methodInfo = target.GetType().GetMethodEx(methodName, BindingFlagsHelper.GetFinalBindingFlags(true, true)); return(CreateDelegate(delegateType, target, methodInfo)); }
/// <summary> /// The get events ex. /// </summary> /// <param name="type">The type.</param> /// <param name="flattenHierarchy">The flatten Hierarchy.</param> /// <param name="allowStaticMembers">The allow Static Members.</param> /// <returns>EventInfo[][].</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> public static EventInfo[] GetEventsEx(this Type type, bool flattenHierarchy = true, bool allowStaticMembers = false) { Argument.IsNotNull("type", type); var bindingFlags = BindingFlagsHelper.GetFinalBindingFlags(flattenHierarchy, allowStaticMembers); // Explicitly use Catel.Reflection.TypeInfoExtensions, see https://github.com/Catel/Catel/issues/1617 //return Catel.Reflection.TypeInfoExtensions.GetEvents(type.GetTypeInfo(), bindingFlags); return(type.GetEvents(bindingFlags)); }
/// <summary> /// The get constructor ex. /// </summary> /// <param name="type">The type.</param> /// <param name="types">The types.</param> /// <returns>ConstructorInfo.</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> /// <exception cref="System.ArgumentNullException">The <paramref name="types" /> is <c>null</c>.</exception> public static ConstructorInfo GetConstructorEx(this Type type, Type[] types) { Argument.IsNotNull("type", type); Argument.IsNotNull("types", types); #if UAP_DEFAULT return(type.GetTypeInfo().GetConstructor(types, BindingFlagsHelper.GetFinalBindingFlags(false, false))); #else return(type.GetConstructor(types)); #endif }
/// <summary> /// The get events ex. /// </summary> /// <param name="type">The type.</param> /// <param name="flattenHierarchy">The flatten Hierarchy.</param> /// <param name="allowStaticMembers">The allow Static Members.</param> /// <returns>EventInfo[][].</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> public static EventInfo[] GetEventsEx(this Type type, bool flattenHierarchy = true, bool allowStaticMembers = false) { Argument.IsNotNull("type", type); BindingFlags bindingFlags = BindingFlagsHelper.GetFinalBindingFlags(flattenHierarchy, allowStaticMembers); #if ENABLE_CACHE var cacheKey = new ReflectionCacheKey(type, ReflectionTypes.Event, bindingFlags); return(_eventsCache.GetFromCacheOrFetch(cacheKey, () => type.GetTypeInfo().GetEvents(bindingFlags))); #else return(type.GetTypeInfo().GetEvents(bindingFlags)); #endif }
/// <summary> /// The get constructor ex. /// </summary> /// <param name="type">The type.</param> /// <param name="types">The types.</param> /// <returns>ConstructorInfo.</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> /// <exception cref="System.ArgumentNullException">The <paramref name="types" /> is <c>null</c>.</exception> public static ConstructorInfo GetConstructorEx(this Type type, Type[] types) { Argument.IsNotNull("type", type); Argument.IsNotNull("types", types); #if ENABLE_CACHE var cacheKey = new ReflectionCacheKey(type, ReflectionTypes.Constructor, BindingFlags.Default, types); #if NETFX_CORE || PCL return(_constructorCache.GetFromCacheOrFetch(cacheKey, () => type.GetTypeInfo().GetConstructor(types, BindingFlagsHelper.GetFinalBindingFlags(false, false)))); #else return(_constructorCache.GetFromCacheOrFetch(cacheKey, () => type.GetConstructor(types))); #endif #else #if NETFX_CORE || PCL return(type.GetTypeInfo().GetConstructor(types, BindingFlagsHelper.GetFinalBindingFlags(false, false))); #else return(type.GetConstructor(types)); #endif #endif }
/// <summary> /// The get event ex. /// </summary> /// <param name="type">The type.</param> /// <param name="name">The name.</param> /// <param name="flattenHierarchy">The flatten Hierarchy.</param> /// <param name="allowStaticMembers">The allow Static Members.</param> /// <returns>EventInfo.</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> /// <exception cref="System.ArgumentException">The <paramref name="name" /> is <c>null</c> or whitespace.</exception> public static EventInfo GetEventEx(this Type type, string name, bool flattenHierarchy = true, bool allowStaticMembers = false) { return(GetEventEx(type, name, BindingFlagsHelper.GetFinalBindingFlags(flattenHierarchy, allowStaticMembers))); }
/// <summary> /// The get properties ex. /// </summary> /// <param name="type">The type.</param> /// <param name="flattenHierarchy">The flatten hierarchy.</param> /// <param name="allowStaticMembers">The allow static members.</param> /// <returns>PropertyInfo[][].</returns> /// <exception cref="System.ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> public static PropertyInfo[] GetPropertiesEx(this Type type, bool flattenHierarchy = true, bool allowStaticMembers = false) { return(GetPropertiesEx(type, BindingFlagsHelper.GetFinalBindingFlags(flattenHierarchy, allowStaticMembers))); }