Skip to content

Commit

Permalink
refactor(iot-device): Rename property add method
Browse files Browse the repository at this point in the history
  • Loading branch information
abhipsaMisra committed Jul 16, 2021
1 parent 50c1d23 commit 058035b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
4 changes: 2 additions & 2 deletions iothub/device/devdoc/Convention-based operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ public class ClientProperties : ClientPropertyCollection {
public class ClientPropertyCollection : PayloadCollection {
public ClientPropertyCollection();
public long Version { get; protected set; }
public void Add(IDictionary<string, object> properties);
public void AddComponentProperties(string componentName, IDictionary<string, object> properties);
public void AddComponentProperty(string componentName, string propertyName, object propertyValue);
public void AddOrUpdate(IDictionary<string, object> properties);
public void AddOrUpdateComponentProperties(string componentName, IDictionary<string, object> properties);
public void AddOrUpdateComponentProperty(string componentName, string propertyName, object propertyValue);
public void AddOrUpdateRootProperties(IDictionary<string, object> properties);
public void AddOrUpdateRootProperty(string propertyName, object propertyValue);
public void AddRootProperties(IDictionary<string, object> properties);
public void AddRootProperty(string propertyName, object propertyValue);
public bool Contains(string componentName, string propertyName);
public virtual bool TryGetValue<T>(string componentName, string propertyName, out T propertyValue);
Expand Down
20 changes: 4 additions & 16 deletions iothub/device/src/ClientPropertyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void AddComponentProperties(string componentName, IDictionary<string, obj
/// <inheritdoc path="/seealso" cref="AddInternal(IDictionary{string, object}, string, bool)" />
/// <inheritdoc path="/exception['ArgumentException']" cref="AddRootProperty(string, object)" />
/// <summary>
/// Adds the values to the collection.
/// Adds the collection of root-level property values to the collection.
/// </summary>
/// <remarks>
/// If the collection already has a key matching a property name supplied this method will throw an <see cref="ArgumentException"/>.
Expand All @@ -69,16 +69,10 @@ public void AddComponentProperties(string componentName, IDictionary<string, obj
/// as an instance of <see cref="PayloadSerializer.CreateWritablePropertyResponse(object, int, long, string)"/>
/// to ensure the correct formatting is applied when the object is serialized.
/// </para>
/// <para>
/// This method directly adds the supplied <paramref name="properties"/> to the collection.
/// For component-level properties, either ensure that you include the component identifier markers {"__t": "c"} as a part of the supplied <paramref name="properties"/>,
/// or use the <see cref="AddComponentProperties(string, IDictionary{string, object})"/> convenience method instead.
/// For more information see <see href="https://docs.microsoft.com/en-us/azure/iot-pnp/concepts-convention#sample-multiple-components-read-only-property"/>.
/// </para>
/// </remarks>
/// <param name="properties">A collection of properties to add.</param>
/// <exception cref="ArgumentNullException"><paramref name="properties"/> is <c>null</c>.</exception>
public void Add(IDictionary<string, object> properties)
public void AddRootProperties(IDictionary<string, object> properties)
{
if (properties == null)
{
Expand Down Expand Up @@ -127,23 +121,17 @@ public void AddOrUpdateComponentProperties(string componentName, IDictionary<str
/// <inheritdoc path="/summary" cref="AddInternal(IDictionary{string, object}, string, bool)" />
/// <inheritdoc path="/seealso" cref="AddInternal(IDictionary{string, object}, string, bool)" />
/// <inheritdoc path="/exception['ArgumentException']" cref="AddInternal(IDictionary{string, object}, string, bool)" />
/// <inheritdoc path="/exception['ArgumentNullException']" cref="Add(IDictionary{string, object})"/>
/// <inheritdoc path="/exception['ArgumentNullException']" cref="AddRootProperties(IDictionary{string, object})"/>
/// <remarks>
/// If the collection has a key that matches this will overwrite the current value. Otherwise it will attempt to add this to the collection.
/// <para>
/// When using this as part of the writable property flow to respond to a writable property update you should pass in the value
/// as an instance of <see cref="PayloadSerializer.CreateWritablePropertyResponse(object, int, long, string)"/>
/// to ensure the correct formatting is applied when the object is serialized.
/// </para>
/// <para>
/// This method directly adds or updates the supplied <paramref name="properties"/> to the collection.
/// For component-level properties, either ensure that you include the component identifier markers {"__t": "c"} as a part of the supplied <paramref name="properties"/>,
/// or use the <see cref="AddOrUpdateComponentProperties(string, IDictionary{string, object})"/> convenience method instead.
/// For more information see <see href="https://docs.microsoft.com/en-us/azure/iot-pnp/concepts-convention#sample-multiple-components-read-only-property"/>.
/// </para>
/// </remarks>
/// <param name="properties">A collection of properties to add or update.</param>
public void AddOrUpdate(IDictionary<string, object> properties)
public void AddOrUpdateRootProperties(IDictionary<string, object> properties)
=> properties
.ToList()
.ForEach(entry => Collection[entry.Key] = entry.Value);
Expand Down

0 comments on commit 058035b

Please sign in to comment.