Правильная запись в StringBuilder - C#

Узнай цену своей работы

Формулировка задачи:

Добрый день, подскажите, как правильно и красиво переделать следующие строки кода:
Листинг программы
  1. fileContent = new StringBuilder();
  2. fileContent.AppendLine("using System.Drawing;");
  3. fileContent.AppendLine("using System;");
  4. fileContent.AppendLine("using System.Reflection;");
  5. fileContent.AppendLine("using System.Windows.Forms;");
  6. fileContent.AppendLine("namespace programm{");
  7. fileContent.AppendLine("\tpublic class Form1 : Form {");
  8. fileContent.AppendFormat("\t\tprivate string fileName = \"{0}\";\n", form.modelTreeView.SelectedNode.Text.ToLower().Equals("standart") ? @"StandartFreeModel.dll" : form.modelTreeView.SelectedNode.Text);
  9. fileContent.AppendLine("\t\tprivate string className = \"BuildForm\";");
  10. fileContent.AppendLine("\t\tprivate string methodName = \"build\";");
  11. fileContent.AppendLine("\t\tprivate object[] param = null;");
  12. fileContent.AppendLine("\t\tpublic Form1(){");
  13. fileContent.AppendLine("\t\t\tSize = new Size(600, 350);");
  14. fileContent.AppendLine("\t\t\trunMethodFromDll();");
  15. fileContent.AppendLine("\t\t}");
  16. fileContent.AppendLine("\t\t[STAThread]");
  17. fileContent.AppendLine("\t\tpublic static void Main(){");
  18. fileContent.AppendLine("\t\t\tApplication.EnableVisualStyles();");
  19. fileContent.AppendLine("\t\t\tApplication.Run(new Form1());");
  20. fileContent.AppendLine("\t\t}");
  21. fileContent.AppendLine("\t\tpublic void runMethodFromDll(){");
  22. fileContent.AppendFormat("\t\t\tobject[] defaultParam = new object[] {{ this.Controls, @\"{0}\", @\"{1}\"}};\n", form.connString, form.databaseType);
  23. fileContent.AppendLine("\t\t\tAssembly asm = Assembly.LoadFrom(fileName);");
  24. fileContent.AppendLine("\t\t\tType classObject = asm.GetType(fileName.Replace(\"dll\", \"\") + className);");
  25. fileContent.AppendLine("\t\t\tdynamic st = Activator.CreateInstance(classObject, defaultParam);");
  26. fileContent.AppendLine("\t\t\tMethodInfo method = classObject.GetMethod(methodName);");
  27. fileContent.AppendLine("\t\t\tmethod.Invoke(st, param);");
  28. fileContent.AppendLine("\t\t}");
  29. fileContent.AppendLine("\t}");
  30. fileContent.AppendLine("}");

Решение задачи: «Правильная запись в StringBuilder»

textual
Листинг программы
  1. fileContent = new StringBuilder();
  2. fileContent.AppendLine(@"
  3. using System.Drawing;
  4. using System;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. namespace programm{....
  8. ");

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 4.091 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы