Esempio n. 1
0
        private static IEnumerable <Type> GetDependencies(Type type, HashSet <Type> dependencies)
        {
            if (type == null || type.IsGenericParameter ||
                (type.FullName != null && type.FullName.StartsWith("System.")) ||
                (type.Namespace != null && type.Namespace.StartsWith("System.")) ||
                dependencies.Contains(type))
            {
                yield break;
            }

            dependencies.Add(type);

            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                foreach (var t in TypeUtilities.GetDependencies(type.GetGenericTypeDefinition(), dependencies))
                {
                    yield return(t);
                }
            }
            else
            {
                yield return(type);
            }

            foreach (var constructor in type.GetConstructors())
            {
                foreach (var parameter in constructor.GetParameters())
                {
                    foreach (var t in TypeUtilities.GetDependencies(parameter.ParameterType, dependencies))
                    {
                        yield return(t);
                    }
                }
            }

            foreach (var method in type.GetMethods(targetFlags))
            {
                if (!method.IsSpecialName)
                {
                    foreach (var t in TypeUtilities.GetDependencies(method.ReturnType, dependencies))
                    {
                        yield return(t);
                    }
                }

                foreach (var parameter in method.GetParameters())
                {
                    foreach (var t in TypeUtilities.GetDependencies(parameter.ParameterType, dependencies))
                    {
                        yield return(t);
                    }
                }
            }

            foreach (var field in type.GetFields(targetFlags))
            {
                foreach (var t in TypeUtilities.GetDependencies(field.FieldType, dependencies))
                {
                    yield return(t);
                }
            }

            foreach (var property in type.GetProperties(targetFlags))
            {
                foreach (var t in TypeUtilities.GetDependencies(property.PropertyType, dependencies))
                {
                    yield return(t);
                }
            }

            foreach (var @interface in type.GetInterfaces())
            {
                foreach (var t in TypeUtilities.GetDependencies(@interface, dependencies))
                {
                    yield return(t);
                }
            }

            foreach (var argument in type.GetGenericArguments())
            {
                foreach (var t in TypeUtilities.GetDependencies(argument, dependencies))
                {
                    yield return(t);
                }
            }

            if (type.BaseType != null)
            {
                foreach (var t in TypeUtilities.GetDependencies(type.BaseType, dependencies))
                {
                    yield return(t);
                }
            }
        }