Skip to content

Instantly share code, notes, and snippets.

@tany3
Last active August 29, 2015 13:56
Show Gist options
  • Save tany3/9068853 to your computer and use it in GitHub Desktop.
Save tany3/9068853 to your computer and use it in GitHub Desktop.
そのDEBUGディレクティブは要らない

そのDEBUGディレクティブは要らない

System.Diagnostics.Debugクラスは、ConditionalAttributeが付与されている。

###変更前

#if DEBUG
  System.Diagnostics.Debug.WriteLine("デバッグの時だけ出したい");
#endif

###変更後

  System.Diagnostics.Debug.WriteLine("デバッグの時だけ出したい");

###参考 System.Diagnostics.Debug.WriteLineメソッド

[Conditional("DEBUG")] 
[__DynamicallyInvokable]
public static void WriteLine(object value)
{
  TraceInternal.WriteLine(value);
}

Conditional属性が付いているのがミソ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment