コード例 #1
0
        private string GenerateSQLCode(TableAnnotation tabAnn)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append($"CREATE TABLE {tabAnn.Attributes["name"]} (");

            for (int i = 0; i < tabAnn.MemberAnnotations.Count; i++)
            {
                string attrCode = GenerateSQLCode(tabAnn.MemberAnnotations[i]);
                if (string.IsNullOrEmpty(attrCode) && strBuilder.Length >= 2)
                {
                    strBuilder.Remove(strBuilder.Length - 2, 2);
                }
                else
                {
                    strBuilder.Append(attrCode);
                }

                if (i < tabAnn.MemberAnnotations.Count - 1)
                {
                    strBuilder.Append(", ");
                }
            }

            strBuilder.Append(");");
            return(strBuilder.ToString());
        }
コード例 #2
0
        private string GenerateInterfaceCode(TableAnnotation tabAnn)
        {
            var strBuilder = new StringBuilder();

            strBuilder.Append(
                $"using System.Collections.Generic; namespace CodeGeneration {{" +
                $"{tabAnn.InterfaceModifier} class {tabAnn.InterfaceName} {{"
                );

            foreach (var membAnn in tabAnn.MemberAnnotations)
            {
                strBuilder.Append(GenerateInterfaceCode(membAnn));
            }

            strBuilder.Append("}}");
            return(strBuilder.ToString());
        }
コード例 #3
0
        private TableAnnotation sdec()
        {
            string nameAttribute     = table();
            string interfaceModifier = mod();

            Expect(Token.WHITESPACE, Token.INTERFACE, Token.WHITESPACE);
            string interfaceName = str();

            Expect(Token.WHITESPACE);
            var memberAnnotations = members();

            var tableAnnotation = new TableAnnotation(
                "Table", interfaceModifier, interfaceName
                );

            tableAnnotation.Attributes.Add("name", nameAttribute);
            tableAnnotation.MemberAnnotations.AddRange(memberAnnotations);

            return(tableAnnotation);
        }