Click here to Skip to main content
14,270,386 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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:

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

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[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100