Skip to content

Feature: Validation using System.ComponentModel.Annotations #34

@HavenDV

Description

@HavenDV

System.ComponentModel.Annotations provides attributes and classes for adding metadata to your data models. Common uses include:

1.	Validation: Attributes like [Required], [StringLength], and [Range] for data validation.
2.	Display: Attributes like [Display] to specify display names and formats.
3.	Metadata: Attributes like [MetadataType] for associating metadata with types.

https://swagger.io/docs/specification/data-models/data-types/ -> Minimum and Maximum

using System.ComponentModel.DataAnnotations;

public class Person
{
    [Required] // Marks this property as required
    [StringLength(100)] // Sets the maximum length
    public string Name { get; set; }

    [Range(0, 120)] // Specifies acceptable range for the age
    public int Age { get; set; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions