ES CSharp Directive Error - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Error de compilación obvio
Detiene la compilación con un error de autor si la directiva pertenece a la rama activa. Los ejemplos muestran condiciones para el rechazo intencional.
Ejemplo sencillo (Example.cs)
Guarde este ejemplo por separado como Example.cs. Ejecútelo independientemente de los demás ejemplos de esta página.
Example.cs:
// PROJECT-EXAMPLE
#define CONFIGURED
#if !CONFIGURED
#error Missing configuration
#endif
System.Console.WriteLine("Configured");
Este ejemplo compila: CONFIGURED está definido, por lo que la rama #error está inactiva. Los ejemplos que fallan deliberadamente más abajo siguen indicados.
Resultado:
Configured
Sintaxis
#error message
Estos ejemplos no se compilan intencionalmente. Después de establecer la configuración deseada, elimine el error o muévalo a una rama inactiva.
Estado: Error de compilación deliberado.
Ejemplo 1
#error Missing required configuration
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine("Never reached");
}
}
Ejemplo 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
#if !CONFIGURED
#error Define CONFIGURED before compiling
#endif
Console.WriteLine("Configured");
}
}
Fuente oficial: Microsoft Aprender.