Escribe Antril, ejecútalo en tu navegador y compártelo con un enlace. Los programas se compilan a WebAssembly y se ejecutan en tu equipo, no en el servidor.
Ejecutar programas no está disponible en este momento: the WebAssembly linker (wasm-ld, part of LLVM) is not installed on this server. Aún puedes escribir, compartir y descargar código.
importSystem;
importSystem.Reflection;
publicattributeColumn
{
public:
strName;
i32Width;
boolRequired;
new(str name) { Name = name; }
}
publicattributeNote : Column
{
public:
new() : base("note") { }
}
[Column("people", Width = 40)]
publicclassPerson
{
public:
[Column("full name", Required = true)] strName = "";
[Note] i32Age;
[Column("greet")]
Greet([Column("who")] str other) : str => "hi " + other;
}
Main()
{
Type t = typeof(Person);
loop (any a in t.GetCustomAttributes())
{
if (a isColumnAttribute c)
Console.WriteLine("type: " + c.Name + " " + c.Width);
}
FieldInfo? name = t.GetField("Name");
if (name isFieldInfo f && f.GetCustomAttributes(typeof(ColumnAttribute))[0] isColumnAttribute col)
Console.WriteLine("field: " + col.Name + " " + col.Required);
if (t.GetField("Age") isFieldInfo age)
Console.WriteLine("Age has Note: " + age.IsDefined(typeof(NoteAttribute)));
MethodInfo? greet = t.GetMethod("Greet");
if (greet isMethodInfo m)
{
ParameterInfo p = m.GetParameters()[0];
if (p.GetCustomAttributes()[0] isColumnAttribute pc)
Console.WriteLine("parameter: " + pc.Name);
}
Console.WriteLine(t.IsDefined(typeof(NoteAttribute)));
}
Salida
Pulsa Ejecutar (o Ctrl+Enter) para compilar y ejecutar el programa.
Entrada
Lo que lee Console.ReadLine(), una línea a la vez.
Ctrl+Enter ejecuta. Tab agrega sangría (Shift+Tab la quita); pulsa Esc y luego Tab para salir del editor. Un programa puede ejecutarse durante 10 segundos.