Beispiel #1
0
        /// <summary>
        /// Returns an empty <see cref="IEnumerable{T}"/> that has the specified type argument.
        /// </summary>
        /// <param name="type">
        /// The <see cref="Type"/> to assign to the type parameter of the returned
        /// generic <see cref="IEnumerable{T}"/>.
        /// </param>
        /// <returns>
        /// The <see cref="object"/> representing the empty enumerable.
        /// </returns>
        public static object Empty(Type type)
        {
            MethodBaseCacheItem key = GetMethodCacheKey(type);

            if (!DelegateCache.TryGetValue(key, out var f))
            {
                f = StaticMethod <object>(EmptyMethod.MakeGenericMethod(type));
                DelegateCache[key] = f;
            }

            return(((Func <object, object>)f)(type));
        }
        /// <summary>
        /// Generic method to find the specified type and cache the result
        /// </summary>
        /// <param name="type">The type</param>
        /// <param name="cacheResult">Whether to cache the result</param>
        /// <param name="specificAssemblies">Specific assemblies to search within</param>
        /// <returns>The <see cref="IEnumerable{Type}"/></returns>
        public static IEnumerable <Type> ResolveTypes(Type type, bool cacheResult = true, IEnumerable <Assembly> specificAssemblies = null)
        {
            MethodBaseCacheItem key = GetMethodCacheKey(type);

            if (!DelegateCache.TryGetValue(key, out var f))
            {
                f = CreateGenericResolveMethod(ResolveMethod.MakeGenericMethod(type));
                DelegateCache[key] = f;
            }

            return(((Func <bool, IEnumerable <Assembly>, IEnumerable <Type> >)f)(cacheResult, specificAssemblies));
        }
Beispiel #3
0
        /// <summary>
        /// Casts the elements of the given <see cref="IEnumerable"/> to the specified type.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to cast to.</param>
        /// <param name="value">
        /// The <see cref="IEnumerable"/> to cast the items of.
        /// </param>
        /// <returns>
        /// The <see cref="object"/> representing the cast enumerable.
        /// </returns>
        public static object Cast(Type type, IEnumerable value)
        {
            MethodBaseCacheItem key = GetMethodCacheKey(type);

            if (!DelegateCache.TryGetValue(key, out var f))
            {
                f = StaticMethodSingleParameter <object>(CastMethod.MakeGenericMethod(type));
                DelegateCache[key] = f;
            }

            return(((Func <object, object>)f)(value));
        }