public static void AddProcedure(ref List <string> fileContent, string procedureNameToCall, bool addException)
        {
            TestALCodeunit testCodeunit = (TestALCodeunit) new ALTestCodeunitReader().Read(fileContent);

            if (!testCodeunit.Methods.Exists(method => method.Name.ToLower() == procedureNameToCall.ToLower()))
            {
                int lineToInsertProcedure = FindLineToInsertProcedure(testCodeunit, fileContent);
                if (lineToInsertProcedure != 0)
                {
                    List <string> methodContentLinesOnly = new List <string>();
                    if (addException)
                    {
                        methodContentLinesOnly.Add(string.Format("Error('Procedure {0} not yet implemented.');", procedureNameToCall));
                    }
                    List <string> methodContentLines = Library.ALMethodHelper.WriteMethodBody(methodContentLinesOnly);
                    string        methodContent      = String.Join("\r\n", methodContentLines);
                    ALMethod      alMethod           = new ALMethod
                    {
                        IsLocal    = true,
                        Name       = procedureNameToCall,
                        MethodBody = new ALMethodBody {
                            Content = methodContent, ContentLines = methodContentLines
                        },
                        Content = methodContent,
                        ReturnTypeDefinition = new ALReturnTypeDefinition()
                    };

                    fileContent.Insert(lineToInsertProcedure, Library.ALMethodHelper.Write(alMethod));
                }
            }
        }
        //#region Write to Object

        public override void OnWriteObjectHeader(IndentedTextWriter writer, IALObject Target)
        {
            base.OnWriteObjectHeader(writer, Target);
            TestALCodeunit testALCodeunit = (TestALCodeunit)Target;
            ALMethod       aLMethod       = new ALMethod {
                MethodKind = ALMethodKind.Trigger, Name = "OnRun"
            };

            List <string> contentLines = new List <string>();

            foreach (ITestFeature feature in testALCodeunit.Features)
            {
                contentLines.Add(string.Format("[Feature] {0}", feature.Name));
            }
            aLMethod.Content = String.Join("\r\n        ", contentLines);

            writer.Write(OnWriteObjectMethod(Target, aLMethod));
        }
コード例 #3
0
        public void WriteNewObject_FromALObjectClass()
        {
            var alobject = new ALCodeunit
            {
                Id      = 81000,
                Name    = "Test Codeunit",
                Methods = new List <ALMethod>()
            };

            var method = new ALMethod {
                TestMethod = true, Name = "TestMethod", MethodKind = ALMethodKind.Method
            };

            alobject.Methods.Add(method);

            var result = ALParser.Write(alobject);

            Assert.IsNotEmpty(result);
        }
コード例 #4
0
        public static string Write(this ALMethod method)
        {
            var result = "";

            using (var stringWriter = new StringWriter())
            {
                using (var writer = new IndentedTextWriter(stringWriter))
                {
                    writer.Indent++;
                    writer.WriteLine();

                    var parameterTxt = "";
                    if (method.Parameters.Count > 0)
                    {
                        parameterTxt = String.Join(';', method.Parameters.Select(s => $"{(s.IsVar ? "var " : "")}{s.Name}: {s.TypeDefinition.Name}"));
                    }

                    writer.WriteLine($"{(method.IsLocal ? "local " : "")}{(method.MethodKind == ALMethodKind.Method ? "procedure" : "")} {method.Name}({parameterTxt}){(!String.IsNullOrEmpty(method.ReturnTypeDefinition.Name) ? ": " + method.ReturnTypeDefinition.Name : "")}");

                    if (String.IsNullOrEmpty(method.Content))
                    {
                        writer.WriteLine("begin");
                        writer.WriteLine("end;");
                    }
                    else
                    {
                        writer.WriteLine(method.Content);
                    }

                    writer.Indent--;

                    result = stringWriter.ToString().Replace("}", "").TrimEnd();
                }
            }

            return(result);
        }