Enabling conditional compilation directives based on the references included in a C# Project -


i have projecta , projectb. projecta can work independently without dependency of projectb. now, enable modules/features in projecta if projectb added reference in projecta. how achieve this?

i have tried adding conditional compilation in needed modules/features in projecta below.

#if projb { .. } #endif 

but how can enable these conditional compilation constants checking condition "projectb" referenced "projecta". also, not need "projectb" referenced in "projecta". still "projecta" need work independently in cases.

you can use plugin pattern. e.g.:

  1. projecta loads , figures out if has or not possibility load projectb
  2. if projectb available projecta looks defined entry point (e.g. can have 1 class implementing iplugin load method
  3. if entry point found, projecta calls , stores reference (some kind of variable or adds list if have multiple options.
  4. now in places want conditional compilation check if plugin exists , throw exception need add projectb in order use functionality.

you can define special interface (multiple interfaces) both projects know about. plugin (projectb) provide interface methods want call.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -