C# 并尝试命名空间
我有一个程序可以做很多事情,其中之一是使用 Oracle.DataAccess.Client;
连接到 Oracle 数据库,现在不需要加载这个命名空间。我不能包含他们的,因为它来自 Oracle db 包。我需要类似尝试但在命名空间上的东西。现在,如果没有此命名空间,应用程序将引发未处理的异常并崩溃。我想捕获此异常并设置一些标志,例如 noOracleClient=true;
。
I have a program which do many things, one of those is connecting to an Oracle db, using Oracle.DataAccess.Client;
Now its not necessary to load this namespace. I can't include theirs because it is from the Oracle db package. I need something like a try but on a namespace. Now without this namespace the app throws an unhandled exception and crashes. I want to catch this exception and set some flag like noOracleClient=true;
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不认为它会按照你想要的方式工作。听起来你真正想要的是一个依赖注入框架,比如 Ninject。
I don't think it's going to work quite how you want. It sounds like what you really want is a dependency injection framework, like Ninject.
我建议将 Oracle 访问代码放在单独的程序集中。然后通过接口公开功能,并为该接口编写代码。
然后你可以使用像Joel C建议的Ninject或MEF(http://stevenhollidge.blogspot.com/2011/04/how-to-use-mef-with-c.html)之类的东西来加载你的程序集作为具体的班级。
I'd suggest putting your Oracle access code in a separate assembly. Then expose the functionality via an interface, and code to that interface.
Then you can use something like Ninject like Joel C suggested or possibly MEF (http://stevenhollidge.blogspot.com/2011/04/how-to-use-mef-with-c.html) to load your assembly as the concrete class.
尝试通过反射使用全名“Oracle.DataAccess.Client”加载程序集
如果 Oracle.DataAccess.Client 位于 GAC 中,则此代码将正确执行,否则将引发异常。您应该指定完整的程序集名称以加载特定版本的 Oracle 客户端
Try to load assembly using full name "Oracle.DataAccess.Client" by reflection
If Oracle.DataAccess.Client is in GAC this code will be executed correctly, otherwise - exception will be raised. You should specify full assembly name for loading specific version of Oracle Client