Skip to content

Commit eac303e

Browse files
committed
Fixes the issue 226
1 parent 7f678cc commit eac303e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
1010
using AdminShellNS.Extensions;
1111
using Newtonsoft.Json;
1212
using System;
13+
using System.Collections;
1314
using System.Collections.Generic;
1415
using System.IO;
1516
using System.Linq;
@@ -497,8 +498,13 @@ public static ISubmodel FindSubmodel(this AasCore.Aas3_0.Environment environment
497498
return null;
498499
}
499500

500-
var submodels = environment.Submodels.Where(s => s.Id.Equals(key.Value, StringComparison.OrdinalIgnoreCase));
501-
if (submodels.Any())
501+
List<ISubmodel> submodels = null;
502+
if (environment != null && !environment.Submodels.IsNullOrEmpty())
503+
{
504+
submodels = environment.Submodels.Where(s => s.Id.Equals(key.Value, StringComparison.OrdinalIgnoreCase)).ToList();
505+
506+
}
507+
if (!submodels.IsNullOrEmpty())
502508
{
503509
return submodels.First();
504510
}
@@ -1032,6 +1038,7 @@ public static IReference CopySubmodelRefAndCD(this AasCore.Aas3_0.Environment en
10321038
if (dstSub == null && copySubmodel)
10331039
{
10341040
dstSub = srcSub.Copy();
1041+
environment.Submodels ??= new List<ISubmodel>();
10351042
environment.Submodels.Add(dstSub);
10361043
}
10371044
else
@@ -1074,6 +1081,7 @@ private static void CopyConceptDescriptionsFrom(this AasCore.Aas3_0.Environment
10741081
if (cdDest == null)
10751082
{
10761083
// copy new
1084+
environment.ConceptDescriptions ??= new List<IConceptDescription>();
10771085
environment.ConceptDescriptions.Add(cdSrc.Copy());
10781086
}
10791087

0 commit comments

Comments
 (0)