Solution-wide #define

前端 未结 11 2303
予麋鹿
予麋鹿 2020-12-05 09:29

Is there a way to globally declare a #define?

Like I want to have a file that has for instance,

#define MONO

and I want all source-

11条回答
  •  孤城傲影
    2020-12-05 09:35

    There is one more workaround, correct me if i'm wrong:

    For example, ProjectA references ProjectB, and ProjectsCommon contains base static variable. Both projects refernece ProjectsCommon.

    Code in ProjectsCommon:

    [assembly: InternalsVisibleTo("ProjectA")]
    
    ------------------------------------------
    
    public class ConditionVariables
    {
        public static bool IsABC { get; internal set; } = false;
    }
    

    Code in ProjectA:

    #if ABC
        ProjectsCommon.ConditionVariables.IsABC = true;
    #endif
    

    Code in ProjectB:

    if (ProjectsCommon.ConditionVariables.IsABC )
    {
        // first scenario
    }
    else
    {
        // second one
    }
    

    However, code in ProjectA should run first. This is probably good when ProjectA is a bootstarapper project.

提交回复
热议问题