Ejemplo n.º 1
0
        private List <FluentInterfaceFile> CreateInterfaceFiles(InterfaceLocation interfaceLocation)
        {
            List <FluentInterfaceFile> interfaces = new List <FluentInterfaceFile>();

            foreach (InterfaceData interfaceData in _project.Interfaces)
            {
                FluentInterfaceFile builder =
                    new FluentInterfaceFile($"{interfaceData.Name}.{_project.OutputLanguage.FileExtension}");

                if (interfaceLocation == InterfaceLocation.IndividualFiles)
                {
                    AddRequiredUsingStatements(builder, interfaceData.NamespacesNeeded());

                    // Start namespace
                    builder.AddLine(0, $"namespace {_project.FactoryClassNamespace}");
                    builder.AddLine(0, "{");
                }

                builder.AddLine(1, $"public interface {interfaceData.Name}");

                builder.AddLine(1, "{");

                foreach (Method callableMethod in
                         interfaceData.CallableMethods.Where(cm => cm.Group.IsChainStartingMethod()))
                {
                    InterfaceData returnInterface =
                        _project.Interfaces
                        .FirstOrDefault(i => i.CalledByMethods.Exists(cm => cm.Name == callableMethod.Name));

                    builder.AddLine(2, $"{returnInterface?.Name} {callableMethod.Signature};");
                }

                foreach (Method callableMethod in
                         interfaceData.CallableMethods
                         .Where(cm => cm.Group == Method.MethodGroup.Executing))
                {
                    builder.AddLine(2, $"{callableMethod.ReturnDatatype.Name} {callableMethod.Signature};");
                }

                builder.AddLine(1, "}");

                if (interfaceLocation == InterfaceLocation.IndividualFiles)
                {
                    builder.AddLine(0, "}");
                }

                interfaces.Add(builder);
            }

            return(interfaces);
        }
Ejemplo n.º 2
0
        private FluentInterfaceFile CreateBuilderFile(InterfaceLocation interfaceLocation)
        {
            FluentInterfaceFile builder =
                new FluentInterfaceFile($"{_project.FactoryClassName}.{_project.OutputLanguage.FileExtension}");

            AddRequiredUsingStatements(builder, _project.NamespacesNeeded());

            builder.AddLine(0, $"namespace {_project.FactoryClassNamespace}");
            builder.AddLine(0, "{");

            builder.AddLine(1, $"public class {_project.FactoryClassName} : {_project.InterfaceListAsCommaSeparatedString}");
            builder.AddLine(1, "{");

            AddInstantiatingFunctions(builder);
            AddChainingFunctions(builder);
            AddExecutingFunctions(builder);

            // Close class
            builder.AddLine(1, "}");

            // Append interfaces, if single file output
            if (interfaceLocation == InterfaceLocation.BuilderFile)
            {
                builder.AddLineAfterBlankLine(1, "// Interfaces");

                foreach (FluentInterfaceFile interfaceFile in
                         CreateInterfaceFiles(InterfaceLocation.BuilderFile))
                {
                    builder.AddLineAfterBlankLine(0, interfaceFile.FormattedText());
                }
            }

            // Close namespace
            builder.AddLine(0, "}");

            return(builder);
        }