/// <summary> /// Creates a new instance of the <see cref="SeedInfoTree"/> that describes the seed build upon the <paramref name="seedTypes"/>. /// </summary> internal static SeedInfoTree Create(IEnumerable <Type> seedTypes) { Assert(seedTypes != null); Assert(seedTypes.All(type => type.IsSeedType())); SeedInfoTree result = new SeedInfoTree(); foreach (var seedType in seedTypes) { result.GetOrCreateSeedInfoFor(seedType); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="SeedInfo"/> that describes the seed /// represented by the <paramref name="seedType"/>. /// </summary> internal static SeedInfo CreateFor(Type seedType, SeedInfoTree seedInfoTree) { Debug.Assert(seedType != null); Debug.Assert(seedType.IsSeedType()); Debug.Assert(seedInfoTree != null); var seedOutputProperties = GetSeedOutputProperty(); // TODO: Check that we do not have any circular dependencies. // TODO: Check all other things as well :-) return(new SeedInfo(seedType, seedOutputProperties, GetExplicitDependencies().Concat(GetImplicitDependencies()).ToList())); PropertyInfo[] GetSeedOutputProperty() { return(seedType .GetProperties(BindingFlags.Instance | BindingFlags.Public) .Where(property => property.IsSeedOutputProperty()) .ToArray()); } IEnumerable <SeedInfo> GetImplicitDependencies() { return(seedOutputProperties .Select(property => seedInfoTree.GetOrCreateSeedInfoFor(property.PropertyType.DeclaringType))); } IEnumerable <SeedInfo> GetExplicitDependencies() { // TODO: Add checks: SeedType != null. SeedType.IsSeedType(). return(seedType .GetCustomAttributes(typeof(RequiresAttribute), false) .Cast <RequiresAttribute>() .Select(attribute => attribute.SeedOrScenarioType) .Select(seedInfoTree.GetOrCreateSeedInfoFor)); } }