Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to use multiple (more then 3) conditional compilation symbols in code i.e.

#if CONSTANT1
//Code
#if CONSTANT2
//Code
#if CONSTANT3
//Code
#if CONSTANT4
//Code
#else
//code
#endif

this block of code will be in a DLL. I need to use this DLL in my application and i need to change the conditional compilation symbol so that respective logic should execute.

Is it possible to change this like we do change the properties settings in C#

What I have tried:

i have tried with only one symbol , so its working
#if CONSTANT1
//Code.
#else
//code
#endif
Posted
Updated 25-Feb-16 19:06pm

You are using wrong tool to achieve this. Conditional compilation symbols are utilized while compilation and not at run time. You probably need a facade here. In the DLL, you should have something like this:

C#
public enum ProcessFlag
{
    Flag1,
    Flag2,
    Flag3,
    Flag4,
    Flag5,
}

public class DLLClass
{
    public void SomeMethod(ProcessFlag flag)
    {
        switch (flag)
        {
            case ProcessFlag.Flag1:
                ProcessFlag1();
                break;
            case ProcessFlag.Flag2:
                ProcessFlag2();
                break;
            case ProcessFlag.Flag3:
                ProcessFlag3();
                break;
            case ProcessFlag.Flag4:
                ProcessFlag4();
                break;
            case ProcessFlag.Flag5:
                ProcessFlag5();
                break;
            default:
                ProcessFlagDefault();
                break;
        }
    }

    private void ProcessFlagDefault()
    {
        throw new NotImplementedException();
    }

    private void ProcessFlag5()
    {
        throw new NotImplementedException();
    }

    private void ProcessFlag4()
    {
        throw new NotImplementedException();
    }

    private void ProcessFlag3()
    {
        throw new NotImplementedException();
    }

    private void ProcessFlag2()
    {
        throw new NotImplementedException();
    }

    private void ProcessFlag1()
    {
        throw new NotImplementedException();
    }
}


In the application you can then provide a particular flag to do specific processing.
 
Share this answer
 
You need to use Builder Design Pattern to solve this problem. It will allow you to control your execution blocks and the order of those blocks for execution. Have a look at the following:

Builder .NET Design Pattern in C# and VB - dofactory.com[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900