BasicDigitalTwin.Contents Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
This field will contain properties and components as defined in the contents section of the DTDL definition of the twin.
[System.Text.Json.Serialization.JsonExtensionData]
public System.Collections.Generic.IDictionary<string,object> Contents { get; set; }
[<System.Text.Json.Serialization.JsonExtensionData>]
member this.Contents : System.Collections.Generic.IDictionary<string, obj> with get, set
Public Property Contents As IDictionary(Of String, Object)
Property Value
- Attributes
Examples
Response<BasicDigitalTwin> getBasicDtResponse = await client.GetDigitalTwinAsync<BasicDigitalTwin>(basicDtId);
BasicDigitalTwin basicDt = getBasicDtResponse.Value;
// Must cast Component1 as a JsonElement and get its raw text in order to deserialize it as a dictionary
string component1RawText = ((JsonElement)basicDt.Contents["Component1"]).GetRawText();
var component1 = JsonSerializer.Deserialize<BasicDigitalTwinComponent>(component1RawText);
Console.WriteLine($"Retrieved and deserialized digital twin {basicDt.Id}:\n\t" +
$"ETag: {basicDt.ETag}\n\t" +
$"ModelId: {basicDt.Metadata.ModelId}\n\t" +
$"LastUpdatedOn: {basicDt.LastUpdatedOn}\n\t" +
$"Prop1: {basicDt.Contents["Prop1"]}, last updated on {basicDt.Metadata.PropertyMetadata["Prop1"].LastUpdatedOn}\n\t" +
$"Prop2: {basicDt.Contents["Prop2"]}, last updated on {basicDt.Metadata.PropertyMetadata["Prop2"].LastUpdatedOn} and sourced at {basicDt.Metadata.PropertyMetadata["Prop2"].SourceTime}\n\t" +
$"Component1.LastUpdatedOn: {component1.LastUpdatedOn}\n\t" +
$"Component1.Prop1: {component1.Contents["ComponentProp1"]}, last updated on: {component1.Metadata["ComponentProp1"].LastUpdatedOn}\n\t" +
$"Component1.Prop2: {component1.Contents["ComponentProp2"]}, last updated on: {component1.Metadata["ComponentProp2"].LastUpdatedOn} and sourced at: {component1.Metadata["ComponentProp2"].SourceTime}");
Remarks
If the property is a component, use the BasicDigitalTwinComponent class to deserialize the payload.
Applies to
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應