Пример #1
0
        /// <summary>
        /// Returns all constructed generic types from a type. Also yields the definition.
        /// </summary>
        /// <param name="def">The type definition.</param>
        /// <param name="args">The possible type arguments.</param>
        public IEnumerable <Type> AllGenericItself(Type def, IEnumerable <Type> args)
        {
            yield return(def);

            if (!def.IsGenericTypeDefinition)
            {
                yield break;
            }
            if (GenericParameters)
            {
                var tparams = def.GetGenericArguments();
                foreach (Type t in tparams)
                {
                    yield return(t);
                }
                args = SequenceTools.SelectManyOuter(args, tparams);
            }
            foreach (Type t in AllGeneric(def, args))
            {
                yield return(t);
            }
        }
Пример #2
0
        private IEnumerable <Type> AllDerivedBase(Type type)
        {
            if (
                !type.IsByRef && (!type.IsGenericTypeDefinition || DerivedFromOpenGeneric) &&
                (DerivedFromStatic || (!type.IsAbstract || !type.IsSealed))
                )
            {
                IEnumerable <Type> byrefs   = Type.EmptyTypes;
                IEnumerable <Type> pointers = Type.EmptyTypes;
                if (Pointers)
                {
                    if (ReferenceTypePointers || (type.IsValueType || type.IsPointer))
                    {
                        try{
                            pointers = AllDerivedRecursive(type.MakePointerType());
                        }catch (TypeLoadException)
                        {
                        }
                    }
                }
                if (ByRefs)
                {
                    try{
                        byrefs = AllDerivedRecursive(type.MakeByRefType());
                    }catch (TypeLoadException)
                    {
                    }
                }

                var arrays = AllArrays(type).Select(t => AllDerivedRecursive(t));

                return(SequenceTools.SelectManyOuter(new[] { byrefs, pointers }.Concat(arrays)));
            }
            else
            {
                return(Type.EmptyTypes);
            }
        }