CKTIS / C#
System.Reflection.PropertyInfo: odniesienie praktyczne
System.Reflection.PropertyInfo: odniesienie praktyczne: PropertyInfo opisuje właściwość i jej akcesory get/set.
Wersja: .NET API; verified against .NET 10 reference surface
Składnia
System.Reflection.PropertyInfo /* select a documented member or constructor */PropertyInfo opisuje właściwość i jej akcesory get/set.
Stosuj do mapowania danych i narzędzi respektujących dostępność akcesorów.
Właściwość indeksowana wymaga argumentów indeksu; getter może wykonać dowolny kod.
Brak get lub set trzeba sprawdzić, a trimming może usunąć metadane.
Kompletny program rzeczywiście używa System.Reflection.PropertyInfo; oczekiwany stdout to dokładnie 3.
Przykłady
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"));
Wynik
3
Kompletny program rzeczywiście używa `System.Reflection.PropertyInfo`; oczekiwany stdout to dokładnie `3`.