@@ -39,10 +39,8 @@ public static IEnumerable<LocatedReference> FindAllReferences(this IAssetAdminis
39
39
// yield return new LocatedReference(assetAdministrationShell, assetAdministrationShell.AssetInformation);
40
40
// dead-csharp on
41
41
// Submodel references
42
- if ( assetAdministrationShell . Submodels != null )
43
- foreach ( var r in assetAdministrationShell . Submodels )
44
- yield return new LocatedReference ( assetAdministrationShell , r ) ;
45
-
42
+ foreach ( var r in assetAdministrationShell . AllSubmodels ( ) )
43
+ yield return new LocatedReference ( assetAdministrationShell , r ) ;
46
44
}
47
45
48
46
#endregion
@@ -52,7 +50,7 @@ public static IReference FindSubmodelReference(this IAssetAdministrationShell aa
52
50
if ( aas ? . Submodels == null || smRef == null )
53
51
return null ;
54
52
55
- foreach ( var smr in aas . Submodels )
53
+ foreach ( var smr in aas . AllSubmodels ( ) )
56
54
if ( smr . Matches ( smRef ) )
57
55
return smr ;
58
56
@@ -64,6 +62,40 @@ public static bool HasSubmodelReference(this IAssetAdministrationShell aas, Refe
64
62
return aas . FindSubmodelReference ( smRef ) != null ;
65
63
}
66
64
65
+ /// <summary>
66
+ /// Enumerates any references to Submodels in the AAS. Will not return <c>null</c>.
67
+ /// Is tolerant, if the list is <c>null</c>.
68
+ /// </summary>
69
+ public static IEnumerable < IReference > AllSubmodels ( this IAssetAdministrationShell aas )
70
+ {
71
+ if ( aas ? . Submodels != null )
72
+ foreach ( var sm in aas . Submodels )
73
+ if ( sm != null )
74
+ yield return sm ;
75
+ }
76
+
77
+ /// <summary>
78
+ /// Returns the number of references to Submodels.
79
+ /// Is tolerant, if the list is <c>null</c>.
80
+ /// </summary>
81
+ public static int SubmodelCount ( this IAssetAdministrationShell aas )
82
+ {
83
+ if ( aas ? . Submodels != null )
84
+ return aas . Submodels . Count ;
85
+ return 0 ;
86
+ }
87
+
88
+
89
+ /// <summary>
90
+ /// Returns the <c>index</c>-th Submodel, if exists. Returns <c>null</c> in any other case.
91
+ /// </summary>
92
+ public static IReference SubmodelByIndex ( this IAssetAdministrationShell aas , int index )
93
+ {
94
+ if ( aas ? . Submodels == null || index < 0 || index >= aas . Submodels . Count )
95
+ return null ;
96
+ return aas . Submodels [ index ] ;
97
+ }
98
+
67
99
/// <summary>
68
100
/// Adds. Might create the list.
69
101
/// </summary>
@@ -78,7 +110,7 @@ public static void Add(this IAssetAdministrationShell aas, IReference newSmRef)
78
110
}
79
111
80
112
/// <summary>
81
- /// Removes. Might set the list to <c>null</c> !!
113
+ /// Removes the reference, if contained in list . Might set the list to <c>null</c> !!
82
114
/// Note: <c>smRef</c> must be the exact object, not only match it!
83
115
/// </summary>
84
116
public static void Remove ( this IAssetAdministrationShell aas , IReference smRef )
@@ -166,8 +198,7 @@ public static AssetAdministrationShell ConvertFromV10(this AssetAdministrationSh
166
198
Console . WriteLine ( $ "KeyType value { refKey . type } not found.") ;
167
199
}
168
200
}
169
- assetAdministrationShell . Submodels ??= new List < IReference > ( ) ;
170
- assetAdministrationShell . Submodels . Add ( new Reference ( ReferenceTypes . ModelReference , keyList ) ) ;
201
+ assetAdministrationShell . Add ( new Reference ( ReferenceTypes . ModelReference , keyList ) ) ;
171
202
}
172
203
}
173
204
}
@@ -254,8 +285,7 @@ public static AssetAdministrationShell ConvertFromV20(this AssetAdministrationSh
254
285
Console . WriteLine ( $ "KeyType value { refKey . type } not found.") ;
255
286
}
256
287
}
257
- assetAdministrationShell . Submodels ??= new List < IReference > ( ) ;
258
- assetAdministrationShell . Submodels . Add ( new Reference ( ReferenceTypes . ModelReference , keyList ) ) ;
288
+ assetAdministrationShell . Add ( new Reference ( ReferenceTypes . ModelReference , keyList ) ) ;
259
289
}
260
290
}
261
291
}
0 commit comments