Skip to main content
Version: Preview (0.3.0-preview.205)

Class KnownValueAttribute

Namespace: AdCodicem.ValueObjects.Annotations
Assembly: AdCodicem.ValueObjects.Abstractions.dll

Declares a named constant of a value object, exposed as a static property on the generated type.

[AttributeUsage(AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
public sealed class KnownValueAttribute : Attribute

Inheritance​

object ← Attribute ← KnownValueAttribute

Inherited Members​

Attribute.Equals(object?), Attribute.GetCustomAttribute(Assembly, Type), Attribute.GetCustomAttribute(Assembly, Type, bool), Attribute.GetCustomAttribute(MemberInfo, Type), Attribute.GetCustomAttribute(MemberInfo, Type, bool), Attribute.GetCustomAttribute(Module, Type), Attribute.GetCustomAttribute(Module, Type, bool), Attribute.GetCustomAttribute(ParameterInfo, Type), Attribute.GetCustomAttribute(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(Assembly), Attribute.GetCustomAttributes(Assembly, bool), Attribute.GetCustomAttributes(Assembly, Type), Attribute.GetCustomAttributes(Assembly, Type, bool), Attribute.GetCustomAttributes(MemberInfo), Attribute.GetCustomAttributes(MemberInfo, bool), Attribute.GetCustomAttributes(MemberInfo, Type), Attribute.GetCustomAttributes(MemberInfo, Type, bool), Attribute.GetCustomAttributes(Module), Attribute.GetCustomAttributes(Module, bool), Attribute.GetCustomAttributes(Module, Type), Attribute.GetCustomAttributes(Module, Type, bool), Attribute.GetCustomAttributes(ParameterInfo), Attribute.GetCustomAttributes(ParameterInfo, bool), Attribute.GetCustomAttributes(ParameterInfo, Type), Attribute.GetCustomAttributes(ParameterInfo, Type, bool), Attribute.GetHashCode(), Attribute.IsDefaultAttribute(), Attribute.IsDefined(Assembly, Type), Attribute.IsDefined(Assembly, Type, bool), Attribute.IsDefined(MemberInfo, Type), Attribute.IsDefined(MemberInfo, Type, bool), Attribute.IsDefined(Module, Type), Attribute.IsDefined(Module, Type, bool), Attribute.IsDefined(ParameterInfo, Type), Attribute.IsDefined(ParameterInfo, Type, bool), Attribute.Match(object?), Attribute.TypeId, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

[KnownValue("France", "FR")] on a CountryCode value object generates CountryCode.France, adds the value to CountryCode.KnownValues, and surfaces it in the OpenAPI schema. Combined with the declared values also become the validation rule of the type.

Constructors​

KnownValueAttribute(string, object)​

Initializes a new instance of the class.

public KnownValueAttribute(string name, object value)

Parameters​

name string

Name of the generated static property. Must be a valid C# identifier, not a keyword, and a name the type does not already have: neither a member it declares nor one the generated code uses, the metadata names of its operators and the getters of its properties included, nor the name of another known value. The property's own getter, get_ followed by the name, must be free too: no field, nested type or method without parameters of the type takes it. Any other name is reported with the rule it breaks.

value object

The underlying value. Types that cannot appear as an attribute argument, such as , or , are written as text and parsed at compile time, in the one form of the type that a bound is written in (). A constant of a C# type is held to the same form through its invariant text. A type, an enum member, an array and null are not values, and are reported.

Properties​

Description​

Gets or sets the documentation of the generated static property.

public string? Description { get; set; }

Property Value​

string?

Name​

Gets the name of the generated static property.

public string Name { get; }

Property Value​

string

Value​

Gets the underlying value.

public object Value { get; }

Property Value​

object