간단 - 메타 데이터 태그 [조건]과 디버그 기능 (들)을 태그 할 수 있습니다
#define DEBUG1
...
public static void PrintText1(string txt) {
Console.Write("This is PrintText2\n");
}
[Conditional("DEBUG1")]
public static void PrintText2(string txt) {
Console.Write("This is PrintText2\n");
}
[STAThread]
static void Main(string[] args) {
PrintText1("This is the unconditional method");
PrintText2("This function will be called only if 'DEBUG1' is defined");
}
그것을 시도!
또한 내가 알기로는 #define
은 정의 된 파일의 컨텍스트 내에 존재하며, 다른 파일에서 PrintText2를 호출하는 경우에는 디버그가 정의되지 않은 경우 실행되지 않습니다. 이것은 또한 주변의 다른 방법으로 작동합니다
이
[Conditional("DEBUG1")]
public static void ConditionedPrint(string txt) {
Console.Write("This is PrintText2\n");
}
public static void UnconditionedPrint(string txt) {
ConditionedFunc(txt);
}
UnconditionedFunc 인쇄됩니다 #DEFINE의 DEBUG1이 이 파일을 정의 (의 경우에만) IFF에 관계없이 다른 파일의 "이것은 PrintText2 \ n은".
System.Diagnostics.Debug도 있는데, 나는 그것이 무엇을하는지 잘 모르겠습니다.
이 동작의 예를 보려면 두 개의 AssemblyVersion 특성을 정의하고 하나를 조건부 "#if 디버그"블록 안에 넣으십시오. –
전 처리기 지시문이라고하고 C#에서는 실제로 컴파일러에서 처리합니다. – VVS
"#if DEBUG"블록 안에 두 개의 AssemblyVersion 속성이 있으면 "# else"와 "#endif"사이에 다른 하나가 있기를 바랍니다. –