-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Update Autorest C# - IOT #13558
Merged
Merged
Update Autorest C# - IOT #13558
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
sdk/iot/Azure.Iot.Hub.Service/src/ExportImportDeviceExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using Azure.Iot.Hub.Service.Models; | ||
|
||
namespace Azure.Iot.Hub.Service | ||
{ | ||
/// <summary> | ||
/// Helper functions for mutating the <see cref="ExportImportDevice"/> instance. | ||
/// </summary> | ||
internal static class ExportImportDeviceExtensions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this class handcrafted, or generated by autorest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handcrafted. |
||
{ | ||
/// <summary> | ||
/// Initializes the <see cref="ExportImportDevice.Tags"/> property using provided values. | ||
/// </summary> | ||
public static ExportImportDevice WithTags(this ExportImportDevice device, IDictionary<string, object> tags) | ||
{ | ||
foreach (var tag in tags) | ||
{ | ||
device.Tags.Add(tag); | ||
} | ||
return device; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes the <see cref="ExportImportDevice.Properties"/> property using provided values. | ||
/// </summary> | ||
public static ExportImportDevice WithPropertiesFrom(this ExportImportDevice device, TwinProperties properties) | ||
{ | ||
|
||
var container = new PropertyContainer(); | ||
if (properties != null) | ||
{ | ||
foreach (var property in properties.Desired) | ||
{ | ||
container.Desired.Add(property); | ||
} | ||
foreach (var property in properties.Reported) | ||
{ | ||
container.Reported.Add(property); | ||
} | ||
} | ||
|
||
device.Properties = container; | ||
|
||
return device; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes the <see cref="ExportImportDevice.ParentScopes"/> property using provided values. | ||
/// </summary> | ||
public static ExportImportDevice WithParentScopes(this ExportImportDevice device, IList<string> parentScopes) | ||
{ | ||
foreach (var parentScope in parentScopes) | ||
{ | ||
device.ParentScopes.Add(parentScope); | ||
} | ||
return device; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per # 1: So this is because these fields, being collections, are readonly by default, and so they need additional helper methods?
https://github.com/pakrym/azure-sdk-for-net/blob/pakrym/update-generator-IOT/sdk/iot/Azure.Iot.Hub.Service/src/Generated/Models/ExportImportDevice.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, what was the driving force behind this change? Should collections not be settable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following guideline:
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/guidelines-for-collections#collection-properties-and-return-values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class can probably be internal. Will check and let you know. If it is internal, we would not need the extensions right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why not. We would still need to create instances of this class and the code-gen for properties doesn't change depending on the class being internal or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I want to add here that this is still work in progress and we are yet to make some classes internal which we do not expose. Just curious, is there something you use to be able to detect these in the API surface?