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.:
- projecta loads , figures out if has or not possibility load projectb
- if projectb available projecta looks defined entry point (e.g. can have 1 class implementing
iplugin
load
method - if entry point found, projecta calls , stores reference (some kind of variable or adds list if have multiple options.
- 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
Post a Comment