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

feat: Added helper methods to Google.Rpc.Status for unpacking the Detail #736

Merged
merged 3 commits into from
Nov 9, 2023

Conversation

tonydnewell
Copy link
Contributor

Add methods to Google.Rpc.Status to help with unpacking the Detail in the Status.

These methods have been moved from the proposed Grpc.StatusProto API in
grpc/grpc-dotnet#2205

@jskeet for review

@tonydnewell tonydnewell requested a review from a team as a code owner November 8, 2023 11:43
Copy link

conventional-commit-lint-gcf bot commented Nov 8, 2023

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@jskeet
Copy link
Collaborator

jskeet commented Nov 8, 2023

Will try to review this later today.

@tonydnewell tonydnewell changed the title Added helper methods to Status feat: Added helper methods to Google.Rpc.Status for unpacking the Detail Nov 8, 2023
Copy link
Collaborator

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically fine, thanks - various style things which are different in our repo, and much easier for me to pick up after submission. Will leave until tomorrow morning UK time just in case my comments suggest any other changes, but otherwise I'll merge and then work with @amanda-tarafa on little style things - then we can release...

using System.Collections.Generic;
using Xunit;

namespace Google.Api.CommonProtos.Tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new code, please use file-scoped namespaces.

var badRequest = new BadRequest()
{
FieldViolations =
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Indentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Although I'm happy to basically go over everything later for style.)


/// <summary>
/// Get the registry
/// Note: experimental API that can change or be removed without any prior notice.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this sort of note in our libraries. Once it's there, it's there.

/// <typeparam name="T"></typeparam>
private static class MessageNameCache<T> where T : class, IMessage<T>, new()
{
public static readonly string FullName = new T().Descriptor.FullName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is private to the class, but let's use a property anyway - just add { get; }

{
return null;
}
return any.Unpack<T>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return any?.Unpack<T>(); and avoid the check above? (Indeed, could do this without the any variable at all.)

foreach (var any in Details)
{
var msg = any.Unpack(registry);
if (!(msg is null))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps just use an expression bodied member of Details.Select(any => any.Unpack(registry)).OfType<IMessage>());?

}

[Fact]
public void UnpackDetailMessageTest()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully expect to refactor this later :)

@jskeet jskeet merged commit 05ebeb2 into googleapis:main Nov 9, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants