Question

I'm using VS2010 professional, and I have a project, but i want to have a way that compiles only some of the code in one configuration, and the rest in another. #ifdef is rather clunky, as it must surround said code, and there are lots of fragments. I was thinking like an attribute. And if theres any minecraft modders here, i basically need forge's @SideOnly for C#.

public class Foo{
    [BuildConfig("Config1")]
    public void Bar(){}
    [BuildConfig("Config2")]
    public void Baz(){}
}

compiling this code under Config1 would leave out Baz, and vice versa.

Was it helpful?

Solution

Comments about why intermixing unrelated code is not good aside, you could use the ConditionalAttribute, but only on void methods. This compiles out the code at the callsite as well. For other areas of your code, you'd have to resort back to #ifdef.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top