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.Extensions SystemLibrary.Common.Framework.Json.dll

    This class contains extension methods on Object

    ObjectExtensions

    public static class ObjectExtensions

    Inheritance
    object
    ObjectExtensions
    Examples
    Arguments
    X

    Methods

    Join multiple arrays of same 'Enum' to an Array of that Enum Type

    public static TEnum[] AsEnumArray<TEnum>(this object[] objects) where TEnum : struct, IComparable, IFormattable, IConvertible

    X
    public enum Colors
    {
        Black, White, Red, Blue
    }
    
    var integers = new object[] { 1, 2, 3, 4 };
    
    var colors = integers.AsEnumArray<Colors>();
    // colors is now an array of 'Colors', with one of each of the values:
    // colors[0] == Black
    // colors[1] == White
    // ...
    // colors[3] == Blue
    public enum Colors
    {
        Black, White, Red, Blue
    }
    
    var texts = new object[] { "Red", "Black", "White" };
    var colors = texts.AsEnumArray<Colors>();
    // colors[1] == Black
    X
    Generic types
    Name Description
    TEnum
    Methods arguments
    Type Name Description
    object[] objects
    X
    Type Description
    TEnum[]

    An array of Enum Type

    Convert object to its json string representation with option to camelCase properties

    Remarks
    X

    Uses built-in custom json converters for int, datetime, Enum, etc.

    • for instance Enum, with an EnumValue attribute, will be outputted as the EnumValue attribute and not the Enum.Key

    public static string Json(this object obj, bool camelCase)

    X
    // Assume camelCase argument true:
    class User {
        public string FirstName { get;set; }
    }
    
    var user = new User();
    user.FirstName = "Hello World";
    var json = user.Json();
    var contains = json.Contains("firstName") && json.Contains("Hello World"); 
    // contains is True, note that Json() has formatted 'FirstName' to 'firstName' when going from C# model to json string
    X
    Methods arguments
    Type Name Description
    object obj
    bool camelCase
    X
    Type Description
    string

    Returns json string representation of input, or null if input was so

    Convert object to its json string representation with option to pass Custom JsonConverters

    Remarks
    X

    Uses built-in custom json converters for int, datetime, Enum, etc.

    • for instance Enum, with an EnumValue attribute, will be outputted as the EnumValue attribute and not the Enum.Key

    public static string Json(this object obj, JsonSerializerOptions options = null, bool translateUnicodeCodepoints = false, params JsonConverter[] jsonConverters)

    X
    class User {
        public string FirstName { get;set; }
    }
    
    class CustomConverter : JsonConverter...
    
    var user = new User();
    user.FirstName = "Hello World";
    var json = user.Json(new CustomConverter());
    var isTrue = json.Contains("FirstName") && json.Contains("Hello World"); 
    // isTrue is 'True' as FirstName is not camelCased by default and 'Hello World' is its value
    X
    Methods arguments
    Type Name Description
    object obj
    JsonSerializerOptions options
    bool translateUnicodeCodepoints
    JsonConverter[] jsonConverters
    X
    Type Description
    string

    Returns json string representation of input, or null if input was so

    Convert object to its json string representation with option to pass Custom JsonConverters

    Remarks
    X

    Uses built-in custom json converters for int, datetime, Enum, etc.

    • for instance Enum, with an EnumValue attribute, will be outputted as the EnumValue attribute and not the Enum.Key

    public static string Json(this object obj, params JsonConverter[] jsonConverters)

    X
    class User {
        public string FirstName { get;set; }
    }
    
    class CustomConverter : JsonConverter...
    
    var user = new User();
    user.FirstName = "Hello World";
    var json = user.Json(new CustomConverter());
    var isTrue = json.Contains("FirstName") && json.Contains("Hello World"); 
    // isTrue is 'True' as FirstName is not camelCased by default and 'Hello World' is its value
    X
    Methods arguments
    Type Name Description
    object obj
    JsonConverter[] jsonConverters
    X
    Type Description
    string

    Returns json string representation of input, or null if input was so

    Convert object to its xml string representation

    public static string Xml(this object obj)

    X
    Methods arguments
    Type Name Description
    object obj
    X
    Type Description
    string

    }

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