Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / C#

System.Reflection.PropertyInfo: riferimento pratico

System.Reflection.PropertyInfo: riferimento pratico: PropertyInfo descrive una proprietà e i relativi accessori get e set.

Versione: .NET API; verified against .NET 10 reference surface

Sintassi

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

PropertyInfo descrive una proprietà e i relativi accessori get e set.

Usalo per la mappatura dei dati e negli strumenti che rispettano la disponibilità degli accessori.

Una proprietà indicizzata richiede argomenti indice e il suo getter può eseguire codice arbitrario.

Controlla l’assenza di get o set; il trimming può rimuovere i metadati.

Il programma completo usa realmente System.Reflection.PropertyInfo; lo stdout esatto atteso è 3.

Esempi

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"));

Risultato

3

Il programma completo usa realmente `System.Reflection.PropertyInfo`; lo stdout esatto atteso è `3`.

Fonti