/// <summary> /// Write to the twin for the given flatten /// </summary> /// <param name="twin">The destination twin</param> /// <param name="flatName">The flat name, e.g. tags.city or properties.desired.TTL</param> /// <param name="value">The tag/property value</param> static public void Set(this Twin twin, string flatName, dynamic value) { // Remove the common prefix "twin." flatName = flatName.TryTrimPrefix(PREFIX_TWIN); if (flatName == DEVICEID) { twin.DeviceId = value.ToString(); } // Pick the selector according to prefix of the flat name, then set the value string name; foreach (var selector in _selectors) { if (flatName.TryTrimPrefix(selector.Key, out name)) { TwinCollectionExtension.Set(selector.Value(twin), name, value); return; } } // Invalid flat name should not cause any exception // Write to reported properties is allowed here }