Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / C#

reflection and expressions: praktická reference

reflection and expressions: praktická reference: Reflexe čte metadata a dynamicky pracuje s typy a členy.

Verze: C# language and .NET 10 reference runtime

Syntaxe

// reflection

Reflexe čte metadata a dynamicky pracuje s typy a členy.

Použijte na kontrolovaných hranicích frameworku a cachujte drahé hledání.

Ztrácí kontrolu kompilátoru, komplikuje trimming a AOT a může spustit uživatelský kód.

Chybějící členy, přetížení, generics a dostupnost vyžadují jednoznačnou obsluhu.

Úplný program skutečně používá reflection and expressions; přesně očekávaný stdout je Name.

Příklady

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var properties = typeof(Person).GetProperties(); Console.WriteLine(properties.Single().Name); sealed record Person(string Name);

Výsledek

Name

Úplný program skutečně používá `reflection and expressions`; přesně očekávaný stdout je `Name`.

Zdroje