-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples(adt): add a sample for using a custom twin type for serializa…
…tion
- Loading branch information
David R. Williamson
committed
Jun 2, 2020
1 parent
96f7858
commit e7fa678
Showing
7 changed files
with
181 additions
and
48 deletions.
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
66 changes: 66 additions & 0 deletions
66
...igitaltwins/Azure.DigitalTwins.Core/samples/DigitalTwinsClientSample/CustomDigitalTwin.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,66 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Text.Json.Serialization; | ||
using Azure.DigitalTwins.Core.Serialization; | ||
|
||
namespace Azure.DigitalTwins.Core.Samples | ||
{ | ||
/// <summary> | ||
/// Custom type for a sample illustrating how someone can create their own class to match a digital twin model type | ||
/// for serialization, instead of using <see cref="BasicDigitalTwin"/>. | ||
/// </summary> | ||
internal class CustomDigitalTwin | ||
{ | ||
[JsonPropertyName("$dtId")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("$metadata")] | ||
public CustomDigitalTwinMetadata Metadata { get; set; } | ||
|
||
[JsonPropertyName("Prop1")] | ||
public string Prop1 { get; set; } | ||
|
||
[JsonPropertyName("Prop2")] | ||
public string Prop2 { get; set; } | ||
|
||
[JsonPropertyName("Component1")] | ||
public Component1 Component1 { get; set; } | ||
} | ||
|
||
internal class Component1 | ||
{ | ||
[JsonPropertyName("$metadata")] | ||
public Component1Metadata Metadata { get; set; } | ||
|
||
[JsonPropertyName("ComponentProp1")] | ||
public string ComponentProp1 { get; set; } | ||
|
||
[JsonPropertyName("ComponentProp2")] | ||
public string ComponentProp2 { get; set; } | ||
} | ||
|
||
internal class Metadata | ||
{ | ||
[JsonPropertyName("$model")] | ||
public string ModelId { get; set; } | ||
} | ||
|
||
internal class CustomDigitalTwinMetadata : Metadata | ||
{ | ||
[JsonPropertyName("Prop1")] | ||
public WritableProperty Prop1 { get; set; } | ||
|
||
[JsonPropertyName("Prop2")] | ||
public WritableProperty Prop2 { get; set; } | ||
} | ||
|
||
internal class Component1Metadata : Metadata | ||
{ | ||
[JsonPropertyName("ComponentProp1")] | ||
public WritableProperty ComponentProp1 { get; set; } | ||
|
||
[JsonPropertyName("ComponentProp2")] | ||
public WritableProperty ComponentProp2 { get; set; } | ||
} | ||
} |
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
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
Oops, something went wrong.