dotnetkiteconnect icon indicating copy to clipboard operation
dotnetkiteconnect copied to clipboard

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

Open saivineeth100 opened this issue 7 months ago • 0 comments

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.

saivineeth100 avatar Jul 03 '24 10:07 saivineeth100