x


How can i use C#'s Conditional Attribute in Unity iPhone?

I'd like to try and make some code debug only, as such i'd like to remove as much of it as possible when i'm making a release build. According to this page

http://weblogs.asp.net/tgraham/archive/2004/03/12/88682.aspx

C# has just such a thing to do this, in its Conditional attributes. Yet i've tried this in unity iPhone and it doesn't seem to compile. I'm not sure whether this works in standard unity or not with its more up to date mono implementation, but i've asked elsewhere what version of mono unity iphone uses to try and track down this problem.

I've tried

#define ENABLED

...

...

[ConditionalAttribute("ENABLED")] // doesn't seem to compile :(

static public void DebugFunc(object val) {}

I've also tried using ConditionalAttribute("ENABLED") and Conditional("ENABLED"), neither working.

Anyone got any idea why this doesn't work? It could be VERY VERY helpful!!!

Cheers

more ▼

asked Jan 11 '10 at 03:44 PM

jimbobuk gravatar image

jimbobuk
1.1k 34 42 54

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Conditionals do work with mono (at least with 2.6.1) but I have never tried with iPhone. #if #endif definitely do work however... not sure if that helps...

more ▼

answered Jan 11 '10 at 06:35 PM

azupko gravatar image

azupko
19 3 3 4

(comments are locked)
10|3000 characters needed characters left

I seem to be able to make this work by doing this

using ConditionalAttribute = System.Diagnostics.ConditionalAttribute;

not sure whether this is since the latest 1.6 version of Unity iPhone or not.

I just can't tell whether this will compile out any calls to the function at the callee point. ie. if you are calculating strings as params will these whole steps be skipped if conditional attribute is used to remove the function you are calling.

more ▼

answered Mar 06 '10 at 12:21 AM

jimbobuk gravatar image

jimbobuk
1.1k 34 42 54

I tested it. So created some simple cases and then inspected the IL code. It turns out that even though I am calling non-constant functions, it will be stripped out. All arguments and any calculations/function calls done in the arguments will be stripped. A bit unexpected, but it's useful.

Jul 29 '12 at 06:38 PM TowerOfBricks
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5069
x1999
x180
x11

asked: Jan 11 '10 at 03:44 PM

Seen: 1962 times

Last Updated: Jul 29 '12 at 06:38 PM