System Library Common Framework
Search Results for

    *.Benchmark*,*.Tests*,*.ApiTests*,*.BaseTest*,DelegateJsonConverter,CalleeCancelledRequestException,ClientResponse,ContentType,OutputCachePolicy
    Show / Hide Table of Contents Show / Hide Table of Contents
    NamespaceSystemLibrary.Common.Framework SystemLibrary.Common.Framework.Net.dll

    Decorate the enum key with a value.

    Remarks
    X

    The string extension Json() will try matching a value in a json-string to the EnumValue specified first, and fall back to normal behavior if no match

    The string extension Json() will output the EnumValue if specified, when converting a class to json-string

    EnumValueAttribute

    [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] public class EnumValueAttribute : Attribute

    Inheritance
    object
    Attribute
    EnumValueAttribute
    Examples
    X
    enum Color 
    {
        [EnumValue("#000")]
        [EnumText("Hello Black")]
        Black,
    
        [EnumText("Hello White")]
        White,
    
        Pink
    }
    
    var black = Color.Black;
    var value = black.ToValue();
    // 'value' is now "#000"
    
    var value = Color.White.ToValue();
    // 'value' is now "White"
    
    var value = Color.Pink.ToValue();
    // 'value' is now 'Pink'
    
    // Note: ToValue() falls back to "ToString()" on the enum key
    
    var value = Color.Pink.GetEnumValue();
    // 'value' is now null, as Pink does not have a EnumValueAttribute
    
    var value = Color.Black.GetEnumValue();
    // 'value' is now an object with value "#000", so it is castable to string
    // Note: GetEnumValue() returns null if the enum key does not have the attribute declared, or if the actual value of the EnumValueAttribute is null.
    Arguments
    X

    Constructors

    Decorate the enum key with a value.

    Remarks
    X

    The string extension Json() will try matching a value in a json-string to the EnumValue specified first, and fall back to normal behavior if no match

    The string extension Json() will output the EnumValue if specified, when converting a class to json-string

    public EnumValueAttribute(object value)

    X
    enum Color 
    {
        [EnumValue("#000")]
        [EnumText("Hello Black")]
        Black,
    
        [EnumText("Hello White")]
        White,
    
        Pink
    }
    
    var black = Color.Black;
    var value = black.ToValue();
    // 'value' is now "#000"
    
    var value = Color.White.ToValue();
    // 'value' is now "White"
    
    var value = Color.Pink.ToValue();
    // 'value' is now 'Pink'
    
    // Note: ToValue() falls back to "ToString()" on the enum key
    
    var value = Color.Pink.GetEnumValue();
    // 'value' is now null, as Pink does not have a EnumValueAttribute
    
    var value = Color.Black.GetEnumValue();
    // 'value' is now an object with value "#000", so it is castable to string
    // Note: GetEnumValue() returns null if the enum key does not have the attribute declared, or if the actual value of the EnumValueAttribute is null.
    X
    Methods arguments
    Type Name Description
    object value

    Fields

    Decorate the enum key with a value.

    Remarks
    X

    The string extension Json() will try matching a value in a json-string to the EnumValue specified first, and fall back to normal behavior if no match

    The string extension Json() will output the EnumValue if specified, when converting a class to json-string

    public object Value

    X
    enum Color 
    {
        [EnumValue("#000")]
        [EnumText("Hello Black")]
        Black,
    
        [EnumText("Hello White")]
        White,
    
        Pink
    }
    
    var black = Color.Black;
    var value = black.ToValue();
    // 'value' is now "#000"
    
    var value = Color.White.ToValue();
    // 'value' is now "White"
    
    var value = Color.Pink.ToValue();
    // 'value' is now 'Pink'
    
    // Note: ToValue() falls back to "ToString()" on the enum key
    
    var value = Color.Pink.GetEnumValue();
    // 'value' is now null, as Pink does not have a EnumValueAttribute
    
    var value = Color.Black.GetEnumValue();
    // 'value' is now an object with value "#000", so it is castable to string
    // Note: GetEnumValue() returns null if the enum key does not have the attribute declared, or if the actual value of the EnumValueAttribute is null.
    X
    Field Value
    Type Description
    object

    Extension Methods

    ObjectExtensions.Json(object, bool)
    ObjectExtensions.Json(object, JsonSerializerOptions, bool, params JsonConverter[])
    ObjectExtensions.Json(object, params JsonConverter[])
    ObjectExtensions.Xml(object)

    }

    In This Article
    Package: nuget
    Source: github
    Website: System Library Common Framework