public IStringTerm Generate(IModuleTerm module) { return(Concat(Factory, Flatten(Factory, Factory.List( Factory.List(Factory.String( "using System;" + Environment.NewLine + Environment.NewLine + "namespace Entities" + Environment.NewLine + "{" + Environment.NewLine)), Map(Factory, module.Definitions, Generate), Factory.List(Factory.String( "}" + Environment.NewLine))) ))); }
/// <summary> /// Builds a new list term. /// </summary> /// <param name="termFactory">The term factory.</param> /// <param name="terms">The terms in the list.</param> /// <returns>The list term.</returns> public static IListTerm <T> List <T>(this ITermFactory termFactory, IEnumerable <T> terms) where T : class, ITerm { #region Contract if (termFactory == null) { throw new ArgumentNullException(nameof(termFactory)); } if (terms == null) { throw new ArgumentNullException(nameof(terms)); } #endregion return(termFactory.List(terms, Enumerable.Empty <ITerm>())); }
private IListTerm <T> Flatten <T>(ITermFactory factory, IListTerm <IListTerm <T> > list) where T : class, ITerm { return(factory.List(list.SelectMany(t => t))); }
private IListTerm <T> Concat <T>(ITermFactory factory, IListTerm <T> list1, IListTerm <T> list2) where T : class, ITerm { return(factory.List(list1.Concat(list2))); }
private IListTerm <U> Map <T, U>(ITermFactory factory, IListTerm <T> list, Func <T, U> f) where T : class, ITerm where U : class, ITerm { return(factory.List(list.Select(t => f(t)))); }
/// <summary> /// Builds a new list term. /// </summary> /// <param name="termFactory">The term factory.</param> /// <param name="terms">The terms in the list.</param> /// <returns>The list term.</returns> public static IListTerm <T> List <T>(this ITermFactory termFactory, params T[] terms) where T : class, ITerm => termFactory.List((IEnumerable <T>)terms);