Skip to content

Commit

Permalink
chore: create utility method for digital twin properties
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Apr 18, 2023
1 parent b697871 commit da9350c
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023. Smart Operating Block
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
*/

package infrastructure.digitaltwin.presenter

/** Utility module for digital twins operations. */
object PropertyConversion {

/**
* Obtain a Digital Twin property and convert it to its [T] type.
* In case it is null or the conversion is not possible then get a [defaultValue].
*/
inline fun <reified T> Any?.propertyAs(defaultValue: T): T =
when (this) {
is T -> this
else -> defaultValue
}
}

0 comments on commit da9350c

Please sign in to comment.