Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saivineeth100 opened this issue Jul 3, 2024 · 0 comments

Comments

@saivineeth100
Copy link

saivineeth100 commented Jul 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant