Minor fixes with dependency injection mechanisms
now full support for API controllers that can be added at runtime
Conversion added from classes to submodels resp. submodel elements
Packages updated accordingly
diff --git a/sdks/dotnet/basyx-core/BaSyx.Models/Extensions/SubmodelElementExtensions.cs b/sdks/dotnet/basyx-core/BaSyx.Models/Extensions/SubmodelElementExtensions.cs
index 0d8f668..398ff17 100644
--- a/sdks/dotnet/basyx-core/BaSyx.Models/Extensions/SubmodelElementExtensions.cs
+++ b/sdks/dotnet/basyx-core/BaSyx.Models/Extensions/SubmodelElementExtensions.cs
@@ -8,7 +8,14 @@
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
+using BaSyx.Models.Core.AssetAdministrationShell.Generics;
+using BaSyx.Models.Core.AssetAdministrationShell.Generics.SubmodelElementTypes;
using BaSyx.Models.Core.AssetAdministrationShell.Identification;
+using BaSyx.Models.Core.AssetAdministrationShell.Implementations.SubmodelElementTypes;
+using BaSyx.Models.Core.Common;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
namespace BaSyx.Models.Extensions
{
@@ -18,5 +25,52 @@
{
return referable as T;
}
+
+ public static ISubmodelElementCollection CreateSubmodelElementCollection<T>(this IEnumerable<T> enumerable, string idShort)
+ {
+ SubmodelElementCollection smCollection = new SubmodelElementCollection()
+ {
+ IdShort = idShort
+ };
+ Type type = typeof(T);
+ foreach (var item in enumerable)
+ {
+ foreach (var property in type.GetProperties())
+ {
+ ISubmodelElement smElement = CreateSubmodelElement(property, item);
+ smCollection.Value.Add(smElement);
+ }
+ }
+ return smCollection;
+ }
+
+ public static ISubmodelElement CreateSubmodelElement(this PropertyInfo property, object target)
+ {
+ if (DataType.IsSimpleType(property.PropertyType))
+ {
+ DataType dataType = DataType.GetDataTypeFromSystemType(property.PropertyType);
+ Property smProp = new Property(dataType)
+ {
+ IdShort = property.Name,
+ Value = property.GetValue(target)
+ };
+ return smProp;
+ }
+ else
+ {
+ SubmodelElementCollection smCollection = new SubmodelElementCollection()
+ {
+ IdShort = property.Name
+ };
+ object value = property.GetValue(target);
+ Type valueType = value.GetType();
+ foreach (var subProperty in valueType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ ISubmodelElement smElement = CreateSubmodelElement(subProperty, value);
+ smCollection.Value.Add(smElement);
+ }
+ return smCollection;
+ }
+ }
}
}