Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Attribute: practical reference

System.Attribute: practical reference: Attribute is the base for metadata attached to types and members and read through reflection.

Version: .NET API; verified on .NET 10.0.14

Syntax

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

Attribute is the base for metadata attached to types and members and read through reflection.

Use it for declarative configuration when a consumer explicitly interprets that attribute.

Inheritance and AllowMultiple depend on AttributeUsage; reading metadata can instantiate the attribute.

Trimming can remove metadata unknown to analysis; the order of multiple attributes is not a contract.

The complete program actually uses System.Attribute; its exact expected stdout is True.

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;

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

[Obsolete]
sealed class Marked { }

Result

True

The complete program actually uses `System.Attribute`; its exact expected stdout is `True`.

Sources