public void GetBaseConceptInfoTypes() { var tests = new[] { typeof(C1), typeof(C2), typeof(C3), typeof(D1), typeof(D2), typeof(IConceptInfo), typeof(object), }; var results = tests.Select(type => ( In: type, Out: DslSyntaxFromPlugins.GetBaseConceptInfoTypes(type) )).ToList(); var report = string.Join("\r\n", results.Select(r => $"{r.In.Name}: {TestUtility.DumpSorted(r.Out, t => t.Name)}")); Assert.AreEqual( @"C1: C2: C1 C3: C1, C2 D1: D2: IConceptInfo: Object: ", report); }
/// <summary> /// The syntax will also include all related concepts, referenced by the provided concept's members. /// </summary> public static DslSyntax CreateDslSyntax(params Type[] conceptInfoTypes) { var relatedConcepts = GetAllRelatedConceptInfoTypes(conceptInfoTypes); var relatedConceptPrototypes = relatedConcepts.Select(c => (IConceptInfo)Activator.CreateInstance(c)).ToList(); var syntax = new DslSyntaxFromPlugins(relatedConceptPrototypes, new BuildOptions(), new DatabaseSettings()); return(syntax.CreateDslSyntax()); }
public void IncludeAbstractBaseClassWithoutPluginRegistration() { IEnumerable <IConceptInfo> registeredConceptsFromDependencyInjection = new[] { new ConcreteConcept() }; var dslSyntaxFromPlugins = new DslSyntaxFromPlugins( registeredConceptsFromDependencyInjection, new BuildOptions(), new DatabaseSettings()); var dslSyntax = dslSyntaxFromPlugins.CreateDslSyntax(); var report = TestUtility.DumpSorted( dslSyntax.ConceptTypes, ct => $"{ct.TypeName} members:{TestUtility.DumpSorted(ct.Members, m => m.Name)}" + $" base:{TestUtility.DumpSorted(ct.BaseTypes, b => b.TypeName)}"); Assert.AreEqual( "AbstractConcept members:Name base:, ConcreteConcept members:Name base:AbstractConcept", report); }
public static IEnumerable <Type> GetAllRelatedConceptInfoTypes(params Type[] conceptInfoTypes) { var types = new HashSet <Type>(conceptInfoTypes); var addReferencedTypes = new HashSet <Type>(conceptInfoTypes); while (addReferencedTypes.Any()) { var newTypes = new HashSet <Type>(); foreach (Type type in addReferencedTypes) { foreach (var member in ConceptMembers.Get(type)) { if (member.IsConceptInfo && !member.IsConceptInfoInterface) { if (!types.Contains(member.ValueType)) { types.Add(member.ValueType); newTypes.Add(member.ValueType); } } } } addReferencedTypes = newTypes; } foreach (var type in types.ToList()) // Creating a copy to allow modification within the loop. { foreach (var baseType in DslSyntaxFromPlugins.GetBaseConceptInfoTypes(type)) { types.Add(baseType); } } return(types.ToArray()); }