Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Attribute: odniesienie praktyczne

System.Attribute: odniesienie praktyczne: Attribute jest bazą metadanych dołączanych do typów i składowych, odczytywanych przez refleksję.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

System.Attribute /* select a documented member or constructor */

Attribute jest bazą metadanych dołączanych do typów i składowych, odczytywanych przez refleksję.

Stosuj do deklaratywnej konfiguracji, gdy konsument jawnie interpretuje dany atrybut.

Dziedziczenie i AllowMultiple zależą od AttributeUsage; odczyt może utworzyć instancję atrybutu.

Trimming może usunąć metadane nieznane analizie; kolejność wielu atrybutów nie jest kontraktem.

Kompletny program rzeczywiście używa System.Attribute; oczekiwany stdout to dokładnie True.

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;

Console.WriteLine(Attribute.IsDefined(typeof(Marked), typeof(ObsoleteAttribute)));

[Obsolete]
sealed class Marked { }

Wynik

True

Kompletny program rzeczywiście używa `System.Attribute`; oczekiwany stdout to dokładnie `True`.

Źródła