Is there an equivalent to Python's ImportError in C# -


i'm putting code base unity3d sorts of common patterns. imported project source code not compiled dll.

some of code should compiled specific dependency (also installed source code) present. (in case, networking code should compiled if photon installed in project).

i go through manually delete files aren't required, prefer kind of automated way conditionally compile classes.

if python like:

try:     import mylibrary      class myclass(self):         ...  except importerror:     # library not imported 

i know within class can use reflection work out if class defined, there way @ higher level, i.e. pseudocode:

#if namespace_defined('externaldependency') // <-- how can kind of check? using externaldependency;  public class myclass { ... }  #endif 

in c#, there's no chance include using clause in code file part of project doesn't reference assembly contains imported namespace, thus, won't able perform check.

an using of namespace can't located in of referenced assemblies produce compiler error (i.e. are missing project reference?).

in other words, c# encourages developers sure dependencies available @ compile-time.

actually, if want perform different actions in code depending on configuration, environment or whatever, seems you'll need stick inversion of control design pattern.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -