Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.Reflection.PropertyInfo: referencia práctica

System.Reflection.PropertyInfo: referencia práctica: PropertyInfo describe una propiedad y sus descriptores de acceso get y set.

Versión: .NET API; verified against .NET 10 reference surface

Sintaxis

System.Reflection.PropertyInfo /* select a documented member or constructor */

PropertyInfo describe una propiedad y sus descriptores de acceso get y set.

Úsalo para mapear datos y crear herramientas que respeten la disponibilidad de los descriptores.

Una propiedad indexada necesita argumentos de índice y su getter puede ejecutar código arbitrario.

Comprueba si falta get o set; trimming puede eliminar metadatos.

El programa completo usa realmente System.Reflection.PropertyInfo; su stdout esperado exacto es 3.

Ejemplos

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 property = typeof(string).GetProperty(nameof(string.Length))!;
Console.WriteLine(property.GetValue("abc"));

Resultado

3

El programa completo usa realmente `System.Reflection.PropertyInfo`; su stdout esperado exacto es `3`.

Fuentes