Skip to content

Return Typed data instead of dynamic for Request Method in Kite class #42

@saivineeth100

Description

@saivineeth100

In Kite class Request Method should return typed instance instead of a dynamic as it involves boxing which is expensive and also removes manual assignment in constructors

image

Ex:

public class BaseServerResponse<T> where T : class
{
    public ServerResponseStatus Status { get; set; }

    public T Data { get; set; } = default!;

    public string? Message { get; set; }
    public string?  ErrorType { get; set; }
}

public Profile GetProfile()
{
    return Get<Profile>("user.profile");
}
private T Get<T>(string Route, Dictionary<string, dynamic> Params = null, Dictionary<string, dynamic> QueryParams = null) where T : class
 =>  Request<T>(Route, "GET", Params, QueryParams);

private T Request<T>(string Route, string Method, dynamic Params = null, Dictionary<string, dynamic> QueryParams = null, bool json = false) where T : class
{
     //......
     var baseServerResponse = response.Content.ReadFromJsonAsync<BaseServerResponse<T>>().Result;
     //......
     return baseServerResponse .Data;
}

Generally, wherever 'dynamic' is used, it is advisable to use a specific type.

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