C# and try on namespace
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;
.
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.
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.
Try to load assembly using full name "Oracle.DataAccess.Client" by reflection
using System.Reflection;
string fullName = "fully qualified assembly name";
Assembly assembly = Assembly.LoadFrom(fullName);
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
精彩评论