Beispiel #1
0
        public override void SelectByTwoColumns()
        {
            foreach (var firstColumn in Table.Columns)
            {
                if (String.Compare(firstColumn.Value.DatabaseType, "ntext", StringComparison.OrdinalIgnoreCase) == 0 ||
                    String.Compare(firstColumn.Value.DatabaseType, "image", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                foreach (var secondColumn in Table.Columns)
                {
                    if (secondColumn.Equals(firstColumn))
                    {
                        continue;
                    }

                    Code.AppendFormat("\t\tpublic System.Collections.Generic.List<{0}> SelectBy{3}And{6}({1}{2} {3}, {4}{5} {6})",
                                      Table.ClassName,
                                      firstColumn.Value.ManagedType,
                                      firstColumn.Value.ManagedType.IsValueType ? "?" : "",
                                      firstColumn.Value.FieldName,
                                      secondColumn.Value.ManagedType,
                                      secondColumn.Value.ManagedType.IsValueType ? "?" : "",
                                      secondColumn.Value.FieldName);

                    Code.AppendLine();
                    Code.AppendLine("\t\t{"); Code.AppendLine("\t\t\tif (!FakeDataSource.Any(c => c." + firstColumn.Value.FieldName + " == " + firstColumn.Value.FieldName + " && c." + secondColumn.Value.FieldName + " == " + secondColumn.Value.FieldName + ")) return null;");
                    Code.AppendLine("\t\t\treturn FakeDataSource.Where(c => c." + firstColumn.Value.FieldName + " == " + firstColumn.Value.FieldName + " && c." + secondColumn.Value.FieldName + " == " + secondColumn.Value.FieldName + ").ToList();");
                    Code.AppendLine("\t\t}");
                    Code.AppendLine();
                }
            }
        }
Beispiel #2
0
        public override void GenerateDeleteBy()
        {
            foreach (var column in Table.Columns)
            {
                if (System.String.Compare(column.Value.DatabaseType, "ntext", System.StringComparison.OrdinalIgnoreCase) == 0 ||
                    System.String.Compare(column.Value.DatabaseType, "image", System.StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                Code.AppendFormat("\t\tpublic int DeleteBy{1}({0}{2} {1})\n", column.Value.ManagedType, column.Value.FieldName,
                                  column.Value.ManagedType.IsValueType ? "?" : string.Empty);

                Code.AppendLine("\t\t{");
                Code.AppendLine("\t\t\tvar items = FakeDataSource.Where(c => c." + column.Value.FieldName + " == " + column.Value.FieldName + ");");
                Code.AppendLine("\t\t\tvar count = 0;");
                Code.AppendLine("\t\t\tforeach (var item in new System.Collections.Generic.List<" + Table.ClassName + ">(items))");
                Code.AppendLine("\t\t\t{");
                Code.AppendLine("\t\t\t\tFakeDataSource.Remove(item);");
                Code.AppendLine("\t\t\t\tcount++;");
                Code.AppendLine("\t\t\t}");
                Code.AppendLine("\t\t\treturn count;");
                Code.AppendLine("\t\t}");
                Code.AppendLine();
            }
        }
        public override void GenerateSelectBy()
        {
            foreach (var column in Table.Columns)
            {
                if (string.Compare(column.Value.DatabaseType, "ntext", true) == 0 || string.Compare(column.Value.DatabaseType, "image", true) == 0)
                {
                    continue;
                }

                Code.AppendLine("\t\t#region SELECT .... WHERE " + column.Value.FieldName + "=?");
                Code.AppendLine();

                GenerateXmlDoc(2, "Retrieves a collection of items by " + column.Value.FieldName, new KeyValuePair <string, string>(column.Value.FieldName, column.Value.FieldName + " value"));
                Code.AppendFormat(
                    column.Value.ManagedType.IsValueType
                        ? "\t\tpublic System.Collections.Generic.List<{0}> SelectBy{2}({1}? {2})"
                        : "\t\tpublic System.Collections.Generic.List<{0}> SelectBy{2}({1} {2})",
                    Table.ClassName, column.Value.ManagedType, column.Value.FieldName);

                Code.AppendLine();
                Code.AppendLine("\t\t{");
                Code.AppendLine("\t\t\treturn DataContext." + Table.ClassName + ".Where(c => c." + column.Value.FieldName + "== " + column.Value.FieldName + ").ToList();");
                Code.AppendLine("\t\t}");
                Code.AppendLine();
                Code.AppendLine("\t\t#endregion");
                Code.AppendLine();
            }
        }
        public override void GenerateSelectByWithTop()
        {
            foreach (var column in Table.Columns)
            {
                if (string.Compare(column.Value.DatabaseType, "ntext", true) == 0 || string.Compare(column.Value.DatabaseType, "image", true) == 0)
                {
                    continue;
                }

                Code.AppendLine("\t\t#region SELECT TOP(?).... WHERE " + column.Value.FieldName + "=?");
                Code.AppendLine();

                GenerateXmlDoc(2, "Retrieves the first set of items specified by count by " + column.Value.FieldName, new KeyValuePair <string, string>(column.Value.FieldName, column.Value.FieldName + " value"), new KeyValuePair <string, string>("count", "Number of records to be retrieved"));
                Code.AppendFormat(
                    column.Value.ManagedType.IsValueType
                        ? "\t\tpublic System.Collections.Generic.List<{0}> SelectBy{2}({1}? {2}, int count)"
                        : "\t\tpublic System.Collections.Generic.List<{0}> SelectBy{2}({1} {2}, int count)",
                    Table.ClassName, column.Value.ManagedType, column.Value.FieldName);

                Code.AppendLine();
                Code.AppendLine("\t\t{");
                Code.AppendLine("\t\t\treturn DataContext." + Table.ClassName + ".Where(c => c." + column.Value.FieldName + "== " + column.Value.FieldName + ").Take(count).ToList();");
                Code.AppendLine("\t\t}");
                Code.AppendLine();
                Code.AppendLine("\t\t#endregion");
                Code.AppendLine();
            }
        }
Beispiel #5
0
 public void Emit(string label = "", string opcode = "", string comment = "")
 {
     if (IgnoreEmit)
     {
         return;
     }
     if (string.IsNullOrWhiteSpace(label))
     {
         label = TAB;
     }
     if (!string.IsNullOrWhiteSpace(comment))
     {
         comment = "//" + comment;
     }
     Code.AppendFormat("{0,-8}{1,-32}{2}\n", label, opcode, comment);
 }
        public override void GenerateDeleteBy()
        {
            foreach (var column in Table.Columns)
            {
                if (string.Compare(column.Value.DatabaseType, "ntext", true) == 0 || string.Compare(column.Value.DatabaseType, "image", true) == 0)
                {
                    continue;
                }

                Code.AppendLine("\t\t#region DELETE BY " + column.Value.FieldName);
                Code.AppendLine();
                GenerateXmlDoc(2, "Delete records by " + column.Value.FieldName,
                               new KeyValuePair <string, string>(column.Value.FieldName, column.Value.FieldName + " value"));
                Code.AppendFormat("\t\tpublic int DeleteBy{1}({0}{2} {1})", column.Value.ManagedType, column.Value.FieldName, column.Value.ManagedType.IsValueType ? "?" : string.Empty);
                Code.AppendLine("\n\t\t{");
                Code.AppendLine("\t\t\tthrow new System.NotImplementedException();");
                Code.AppendLine("\t\t}");
                Code.AppendLine();
                Code.AppendLine("\t\t#endregion");
                Code.AppendLine();
            }
        }
Beispiel #7
0
        public override void GenerateSelectBy()
        {
            foreach (var column in Table.Columns)
            {
                if (System.String.Compare(column.Value.DatabaseType, "ntext", System.StringComparison.OrdinalIgnoreCase) == 0 ||
                    System.String.Compare(column.Value.DatabaseType, "image", System.StringComparison.OrdinalIgnoreCase) == 0)
                {
                    continue;
                }

                Code.AppendFormat(
                    column.Value.ManagedType.IsValueType
                        ? "\t\tpublic System.Collections.Generic.List<{0}> SelectBy{2}({1}? {2})"
                        : "\t\tpublic System.Collections.Generic.List<{0}> SelectBy{2}({1} {2})",
                    Table.ClassName, column.Value.ManagedType, column.Value.FieldName);

                Code.AppendLine();
                Code.AppendLine("\t\t{");
                Code.AppendLine("\t\t\tif (!FakeDataSource.Any(c => c." + column.Value.FieldName + " == " + column.Value.FieldName + ")) return null;");
                Code.AppendLine("\t\t\treturn FakeDataSource.Where(c => c." + column.Value.FieldName + " == " + column.Value.FieldName + ").ToList();");
                Code.AppendLine("\t\t}");
                Code.AppendLine();
            }
        }
Beispiel #8
0
 protected void AppendLine(string format, params string[] args)
 {
     Code.AppendFormat(format, args);
     AppendLine();
 }
Beispiel #9
0
 protected void Append(string format, params string[] args) =>
 Code.AppendFormat(format, args);
 public override void VisitParameterDeclaration(ParameterDeclaration pd)
 {
     Code.AppendFormat("{1} As {0}", pd.ParameterType, pd.ParameterName);
 }
 private void AppendIndentedLine(string format, params string[] args)
 {
     Indent();
     Code.AppendFormat(format, args);
     Code.AppendLine();
 }