[API Proposal]: ExampleValueAttribute
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 28/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- backend-api-design, tooling
Research direction
The proposal names the System.ComponentModel namespace and ExampleValueAttribute, but no repository files, tests, or entry points. Start by comparing the proposed API with DefaultValueAttribute and reviewing the surrounding System.ComponentModel APIs. Done means the API design is resolved and the proposed attribute is implemented with its documented usage supported.
Written by the indexing model from the issue text.
Description
Background and motivation
Introduction
This proposal introduces a new attribute, ExampleValueAttribute, to the System.ComponentModel namespace. It is designed to mirror the API surface of DefaultValueAttribute, but with the purpose of specifying example values for documentation and tooling scenarios.
Motivation
While DefaultValueAttribute is commonly used to indicate the default value of a property or parameter, there is currently no built-in attribute to indicate an example value. Example values are useful for:
- API documentation generation
- Design-time tooling
- Testing and validation scenarios
- Enhancing developer understanding of expected inputs
Adding ExampleValueAttribute provides a standardized way to annotate members with example values without overloading the semantics of DefaultValueAttribute.
Remarks
- This attribute is intended for use in documentation and tooling contexts.
- It does not affect runtime behavior or serialization.
- Consumers of this attribute (e.g., OpenAPI generators, UI scaffolding tools) can use the
Valueproperty to display or infer example inputs.
API Proposal
namespace System.ComponentModel
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter)]
public sealed class ExampleValueAttribute : Attribute
{
public ExampleValueAttribute(object value)
{
Value = value;
}
public object Value { get; }
}
}
API Usage
Example 1: Property
public class Product
{
[ExampleValue("Widget-123")]
public string SKU { get; set; }
}
Example 2: Parameter
public void Configure([ExampleValue(true)] bool enableFeature)
{
// ...
}
Alternative Designs
Examples can be provided using XML documentation, but providing an attribute gives users that are already familiar with similar attributes like DefaultValueAttribute an alternative that does not require enabling XML doc comments, which is an opt-in feature.
Risks
- Minimal risk, as this is a non-breaking addition.
- Tooling must opt-in to support this attribute.
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·