开发者

Monotouch Compiler Directive if debug

开发者 https://www.devze.com 2023-01-26 23:59 出处:网络
In my MonoTouch app, how can I put in a # compiler directive to include code only if in debug mode开发者_如何学C?MonoDevelop by default sets the DEBUG define when you create a solution, so you can use

In my MonoTouch app, how can I put in a # compiler directive to include code only if in debug mode开发者_如何学C?


MonoDevelop by default sets the DEBUG define when you create a solution, so you can use two things: you can use [Conditional ("DEBUG")] attributes on methods that you use to instrument your code and you can use standard if #DEBUGs in your source.

Like this:

[Conditional ("DEBUG")]
void Log (string msg)
{
    Console.WriteLine (msg);
}

void Foo ()
{
    Log ("Start");
    ..
    Log ("End");
}

What is nice about the Conditional attribute is that the compiler will remove the calls at compile time if the switch is not set, and it is prettier than littering your source code with:

#if DEBUG
Console.WriteLine ("start");
#endif
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号