Hi guys,
Any particular reason Debug.Assert() is not allowed in sever side?
Cheers, Paul.
by wildbunny » March 14th, 2011, 6:25 pm
by Oliver » March 18th, 2011, 10:39 am
by wildbunny » March 18th, 2011, 11:17 am
Oliver wrote:Code checking works via a whitelist, not a blacklist. So, only the classes that are explicitly allowed by us -- we just haven't looked at the Debug class.
I did a quick look and it seems debug.assert will try to show message boxes and do something with a global listeners collection, which are things we'd rather not like to have happen in the game code.
Best,
Oliver
by Oliver » March 18th, 2011, 11:42 am
public class Debug {
public static void Assert(bool condition) { Assert(condition, null); }
public static void Assert(bool condition, string caption) {
if(!condition) {
Console.Error.WriteLine("Condition "+ (caption!=null?" [" + caption + "] ":" ") + "failed!");
throw new Exception("Assert Failed");
}
}
}
by TomatoGG » March 30th, 2011, 6:33 am
internal class MyDebug {
[Conditional("DEBUG")]
public static void Assert(bool flag, string text) {
if (!flag) Console.WriteLine(new Exception(text));
}
}
by wildbunny » March 30th, 2011, 9:26 am
TomatoGG wrote:This is the my version of Debug.Assert that I have been using so far
Two things I like about it :
1. It will only be called in the Debug version, not the Release version
2. The output on the console window will show the entire exception, including stack trace
- Code: Select all
internal class MyDebug {
[Conditional("DEBUG")]
public static void Assert(bool flag, string text) {
if (!flag) Console.WriteLine(new Exception(text));
}
}
by Oliver » April 15th, 2011, 11:44 am