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

generator method code reduction (all languages) #3651

Closed
baywet opened this issue Nov 3, 2023 · 0 comments · Fixed by #3678
Closed

generator method code reduction (all languages) #3651

baywet opened this issue Nov 3, 2023 · 0 comments · Fixed by #3678
Assignees
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities. WIP
Milestone

Comments

@baywet
Copy link
Member

baywet commented Nov 3, 2023

With the recent code changes, we have an opportunity to significantly reduce the amount of code being generated.
The examples will be in C# but it applies to all languages

the generator method currently looks like this

public RequestInformation ToPostRequestInformation(TodoTaskList body, Action<RequestConfiguration<ListsRequestBuilderPostQueryParameters>>? requestConfiguration = null)
{
	if (body == null)
	{
		throw new ArgumentNullException(nameof(body));
	}
	RequestInformation requestInfo = new RequestInformation
	{
		HttpMethod = Method.POST,
		UrlTemplate = base.UrlTemplate,
		PathParameters = base.PathParameters
	};
	if (requestConfiguration != null)
	{
		RequestConfiguration<DefaultQueryParameters> requestConfig = new RequestConfiguration<DefaultQueryParameters>();
		requestConfiguration(requestConfig);
		requestInfo.AddQueryParameters(requestConfig.QueryParameters);
		requestInfo.AddRequestOptions(requestConfig.Options);
		requestInfo.AddHeaders(requestConfig.Headers);
	}
	requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
	requestInfo.SetContentFromParsable(base.RequestAdapter, "application/json", body);
	return requestInfo;
}

And we could change it to that instead

public RequestInformation ToPostRequestInformation(TodoTaskList body, Action<RequestConfiguration<ListsRequestBuilderPostQueryParameters>>? requestConfiguration = null)
{
	if (body == null)
	{
		throw new ArgumentNullException(nameof(body));
	}
	RequestInformation requestInfo = new RequestInformation(Method.POST, base.UrlTemplate, base.PathParameters);
        // saves about 10 IL instructions
        requestInfo.Configure(requestConfiguration);
        // saves another ~30 IL instructions
        // in all other languages it'll be something like requestInfo.Configure(() => new RequestConfiguration<ListsRequestBuilderPostQueryParameters>(), requestConfiguration);
	requestInfo.Headers.TryAdd("Accept", "application/json;q=1");
	requestInfo.SetContentFromParsable(base.RequestAdapter, "application/json", body);
	return requestInfo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities. WIP
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant