Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Reflection.PropertyInfo: practical reference

System.Reflection.PropertyInfo: practical reference: PropertyInfo describes a property and its get and set accessors.

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

Syntax

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

PropertyInfo describes a property and its get and set accessors.

Use it for data mapping and tools that respect accessor availability.

An indexed property requires index arguments, and its getter can execute arbitrary code.

Check for a missing get or set accessor; trimming can remove metadata.

The complete program actually uses System.Reflection.PropertyInfo; its exact expected stdout is 3.

Examples

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

Result

3

The complete program actually uses `System.Reflection.PropertyInfo`; its exact expected stdout is `3`.

Sources