private static List<MethodInfo> GetPluginMethods(IConceptMacro conceptMacro, IConceptInfo conceptInfo) { var methods = conceptMacro.GetType().GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IConceptMacro<>) && i.GetGenericArguments().Single().IsAssignableFrom(conceptInfo.GetType())) .Select(i => i.GetMethod("CreateNewConcepts")) .ToList(); if (methods.Count == 0) throw new FrameworkException(string.Format( "Plugin {0} does not implement generic interface {1} that accepts argument {2}.", conceptMacro.GetType().FullName, typeof(IConceptMacro<>).FullName, conceptInfo.GetType().FullName)); return methods; }
private static List <MethodInfo> GetPluginMethods(IConceptMacro conceptMacro, IConceptInfo conceptInfo) { var methods = conceptMacro.GetType().GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IConceptMacro <>) && i.GetGenericArguments().Single().IsAssignableFrom(conceptInfo.GetType())) .Select(i => i.GetMethod("CreateNewConcepts")) .ToList(); if (methods.Count == 0) { throw new FrameworkException(string.Format( "Plugin {0} does not implement generic interface {1} that accepts argument {2}.", conceptMacro.GetType().FullName, typeof(IConceptMacro <>).FullName, conceptInfo.GetType().FullName)); } return(methods); }
public static IEnumerable <IConceptInfo> CreateNewConcepts(this IConceptMacro conceptMacro, IConceptInfo conceptInfo, IDslModel existingConcepts) { IEnumerable <IConceptInfo> newConcepts = null; foreach (var method in GetPluginMethods(conceptMacro, conceptInfo)) { var pluginCreatedConcepts = (IEnumerable <IConceptInfo>)method.InvokeEx(conceptMacro, new object[] { conceptInfo, existingConcepts }); if (newConcepts == null) { newConcepts = pluginCreatedConcepts; } else if (pluginCreatedConcepts != null) { newConcepts = newConcepts.Concat(pluginCreatedConcepts); } } return(newConcepts); }