Throw exceptions on unknown Service or Tool

This commit is contained in:
Sergey Chebotar 2023-05-30 08:23:31 +03:00
parent 65d027179c
commit ab217c9052
3 changed files with 3 additions and 3 deletions

View File

@ -15,7 +15,7 @@ public class ReaderFactory
{ {
"Guess" => (IReader)_serviceProvider.GetService(typeof(GuessReader)), "Guess" => (IReader)_serviceProvider.GetService(typeof(GuessReader)),
"Excel" => (IReader)_serviceProvider.GetService(typeof(ExcelReader)), "Excel" => (IReader)_serviceProvider.GetService(typeof(ExcelReader)),
_ => (IReader)_serviceProvider.GetService(typeof(ExcelReader)) _ => throw new ArgumentException($"Незвестный интерфейс {nameof(IReader)}: {readerName}")
}; };
} }
} }

View File

@ -15,7 +15,7 @@ public class WriterFactory
{ {
"Excel" => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)), "Excel" => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)),
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)), "Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
_ => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)) _ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
}; };
} }
} }

View File

@ -11,7 +11,7 @@ internal class ToolFactory
"merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider), "merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider),
"dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider), "dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider),
"Guessexport" => new GuessTool(RhSolutionsAddIn.ServiceProvider), "Guessexport" => new GuessTool(RhSolutionsAddIn.ServiceProvider),
_ => throw new Exception("Неизвестный инструмент"), _ => throw new Exception($"Неизвестный инструмент {toolName}"),
}; };
return tool; return tool;
} }