fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. // your code goes here
  8. try
  9. {
  10. switch (new TestFileManage().TempFileCreate("targetPath"))
  11. {
  12. case Ret.OK:
  13. MessageBox.Show("一時ファイルが作成されました。");
  14. break;
  15. case Ret.CANCEL:
  16. MessageBox.Show("一時ファイル作成がキャンセルされました。");
  17. break;
  18. case Ret.ERROR:
  19. MessageBox.Show("一時ファイル作成に失敗しました。");
  20. break;
  21. defalut:
  22. // 予期せぬ値が入ってくる場合
  23. break;
  24. }
  25. }
  26. catch
  27. {
  28. string err = String.Empty;
  29. if(string.IsNullOrEmpty(Common.errMsg))
  30. {
  31. err = Common.errMsg;
  32. }
  33. else
  34. {
  35. err = "予想外のエラーが発生しました。";
  36. }
  37. MessageBox.Show(err);
  38. // ここでエラーメッセージ込みのログ出力処理
  39. }
  40. }
  41. }
  42.  
  43. public class TestFileManage
  44. {
  45. public Ret TempFileCreate(string path)
  46. {
  47. try {
  48. if(MyFile.CreateDir(path) == Ret.OK)
  49. {
  50. return MyFile.CreateFile();
  51. }
  52. return Ret.CANCEL;
  53. } catch {
  54. Common.SetMsg("一時ファイル作成中にエラーが発生しました。");
  55. throw;
  56. }
  57. }
  58. }
  59.  
  60. public class MyFile
  61. {
  62. public MyFile(){}
  63.  
  64. public static Ret CreateDir(string path)
  65. {
  66. if(!Directory.Exists(path))
  67. {
  68. Directory.CreateDirectory(path);
  69. }
  70. return Ret.OK;
  71. }
  72.  
  73. public Ret CreateFile(string path)
  74. {
  75. if (Directory.Exists(path))
  76. {
  77. if(!File.Exists(path))
  78. {
  79. File.Create(path);
  80. return Ret.OK;
  81. } else {
  82. return Ret.CANCEL;
  83. }
  84. } else {
  85. return Ret.ERROR;
  86. }
  87. }
  88.  
  89. }
  90.  
  91. public class Common
  92. {
  93. public static string errMsg {set; get;}
  94.  
  95. public static void SetMsg(string msg)
  96. {
  97. if (String.isNullOrEmpty(errMsg))
  98. {
  99. errMsg = msg;
  100. }
  101. }
  102. }
  103.  
  104. enum Ret : int
  105. {
  106. ERROR = -1, OK, CANCEL
  107. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(45,13): error CS0050: Inconsistent accessibility: return type `Ret' is less accessible than method `TestFileManage.TempFileCreate(string)'
prog.cs(104,6): (Location of the symbol related to previous error)
prog.cs(64,20): error CS0050: Inconsistent accessibility: return type `Ret' is less accessible than method `MyFile.CreateDir(string)'
prog.cs(104,6): (Location of the symbol related to previous error)
prog.cs(73,13): error CS0050: Inconsistent accessibility: return type `Ret' is less accessible than method `MyFile.CreateFile(string)'
prog.cs(104,6): (Location of the symbol related to previous error)
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty