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

Consolidate TwinCollection.ClearMetadata() and ClearAllMetadata() #2901

Merged
merged 3 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 6 additions & 19 deletions iothub/service/src/Twin/Models/TwinCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public IEnumerator GetEnumerator()
///
/// For example a <see cref="List{T}"/> would return a <see cref="TwinCollectionArray"/>, with the metadata intact, when used with
/// a <see cref="TwinCollection"/> returned from a <c>RegistryManager</c> client. If you need this method to always return a
/// <see cref="JToken"/> please see the <see cref="ClearAllMetadata"/> method for more information.
/// <see cref="JToken"/> please see the <see cref="ClearMetadata"/> method for more information.
/// </remarks>
private bool TryGetMemberInternal(string propertyName, out object result)
{
Expand Down Expand Up @@ -284,33 +284,20 @@ private void TryClearMetadata(string propertyName)
}

/// <summary>
/// Clears metadata out of the twin collection.
/// Clears all metadata out of the twin collection as well as the base metadata object.
/// </summary>
/// <remarks>
/// This will only clear the metadata from the twin collection but will not change the base metadata object. This allows you to still use
/// methods such as <see cref="GetMetadata"/>. If you need to remove all metadata, please use <see cref="ClearAllMetadata"/>.
/// This will remove all metadata from the base metadata object as well as the metadata for the twin collection.
/// This will also clear the underlying metadata object which will affect methods such as
/// <see cref="GetMetadata"/> and <see cref="GetLastUpdatedVersion"/>.
/// </remarks>
public void ClearMetadata()
{
TryClearMetadata(MetadataName);
TryClearMetadata(LastUpdatedName);
TryClearMetadata(LastUpdatedVersionName);
TryClearMetadata(VersionName);
}

/// <summary>
/// Clears all metadata out of the twin collection as well as the base metadata object.
/// </summary>
/// <remarks>
/// This will remove all metadata from the base metadata object as well as the metadata for the twin collection. The difference from the
/// <see cref="ClearMetadata"/> method is this will also clear the underlying metadata object which will affect methods such as
/// <see cref="GetMetadata"/> and <see cref="GetLastUpdatedVersion"/>.
/// This method would be useful if you are performing any operations that require <see cref="TryGetMemberInternal(string, out object)"/>
/// to return a <see cref="JToken"/> regardless of the client you are using.
/// </remarks>
public void ClearAllMetadata()
{
ClearMetadata();

// GitHub Issue: https://github.com/Azure/azure-iot-sdk-csharp/issues/1971
// When we clear the metadata from the underlying collection we need to also clear
// the _metadata object so the TryGetMemberInternal will return a JObject instead of a new TwinCollection
Expand Down
25 changes: 6 additions & 19 deletions provisioning/service/src/Twin/TwinCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public IEnumerator GetEnumerator()
///
/// For example a <see cref="List{T}"/> would return a <see cref="TwinCollectionArray"/>, with the metadata intact, when used with
/// a <see cref="TwinCollection"/> returned from a `IotHubServiceClient`.`TwinsClient`. If you need this method to always return a
/// <see cref="JToken"/> please see the <see cref="ClearAllMetadata"/> method for more information.
/// <see cref="JToken"/> please see the <see cref="ClearMetadata"/> method for more information.
/// </remarks>
private bool TryGetMemberInternal(string propertyName, out object result)
{
Expand Down Expand Up @@ -286,33 +286,20 @@ private void TryClearMetadata(string propertyName)
}

/// <summary>
/// Clears metadata out of the twin collection.
/// Clears all metadata out of the twin collection as well as the base metadata object.
/// </summary>
/// <remarks>
/// This will only clear the metadata from the twin collection but will not change the base metadata object. This allows you to still use
/// methods such as <see cref="GetMetadata"/>. If you need to remove all metadata, please use <see cref="ClearAllMetadata"/>.
/// This will remove all metadata from the base metadata object as well as the metadata for the twin collection.
/// This will also clear the underlying metadata object which will affect methods such as
/// <see cref="GetMetadata"/> and <see cref="GetLastUpdatedVersion"/>.
/// </remarks>
public void ClearMetadata()
{
TryClearMetadata(MetadataName);
TryClearMetadata(LastUpdatedName);
TryClearMetadata(LastUpdatedVersionName);
TryClearMetadata(VersionName);
}

/// <summary>
/// Clears all metadata out of the twin collection as well as the base metadata object.
/// </summary>
/// <remarks>
/// This will remove all metadata from the base metadata object as well as the metadata for the twin collection. The difference from the
/// <see cref="ClearMetadata"/> method is this will also clear the underlying metadata object which will affect methods such as
/// <see cref="GetMetadata"/> and <see cref="GetLastUpdatedVersion"/>.
/// This method would be useful if you are performing any operations that require <see cref="TryGetMemberInternal(string, out object)"/>
/// to return a <see cref="JToken"/> regardless of the client you are using.
/// </remarks>
public void ClearAllMetadata()
ngastelum-ms marked this conversation as resolved.
Show resolved Hide resolved
{
ClearMetadata();

// GitHub Issue: https://github.com/Azure/azure-iot-sdk-csharp/issues/1971
// When we clear the metadata from the underlying collection we need to also clear
// the _metadata object so the TryGetMemberInternal will return a JObject instead of a new TwinCollection
Expand Down