microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
689 stars 246 forks source link

Move to parameter objects in C# #1202

Closed fey101 closed 2 years ago

fey101 commented 2 years ago

Order of parameters is not guaranteed in such a request as this: (Example extracted from documentation page here)

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var recipients = new List<DriveRecipient>()
{
    new DriveRecipient
    {
        Email = "robin@contoso.org"
    }
};

var message = "Here's the file that we're collaborating on.";

var requireSignIn = true;

var sendInvitation = true;

var roles = new List<String>()
{
    "write"
};

var password = "password123";

var expirationDateTime = "2018-07-15T14:00:00Z";

await graphClient.Me.Drive.Items["{driveItem-id}"]
    .Invite(recipients,requireSignIn,roles,sendInvitation,message,expirationDateTime,password)
    .Request()
    .PostAsync();

Moving to parameter objects will eliminate the need for rigid parameter ordering More on this discussed on this PR https://github.com/microsoftgraph/msgraph-metadata/pull/64

zengin commented 2 years ago

@andrueastman is there a duplicate of this issue being tracked for the next version of the .NET SDK?

andrueastman commented 2 years ago

@zengin, The Kiota generator of the SDK already supports this.

I think, we can keep this open for now and close it once we get the preview version out.

andrueastman commented 2 years ago

Closing this for now.

With the Kiota based previews you should be able to do something like using the generated parameter objects.

  var invitePostBody = new InvitePostRequestBody
  {
      Recipients = new List<DriveRecipient>
      {
          new DriveRecipient
          {
              Email = "robin@contoso.org"
          }
      },
      Message = "Welcome",
      RequireSignIn = false,
      SendInvitation = true,
      Roles = new List<string>
      {
          "write"
      }
  };

  await graphServiceClient.Workbooks["workbook-itemId"]
      .Invite
      .PostAsync(invitePostBody);