You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In OrderedItemList.Add(...) the comparison if (typeof(T) == typeof(Thing)) is incorrect because it only checks that the type of the incoming item is directly a Thing, not one of its subtypes.
The correct condition is if (item is Thing) which properly checks that the item is a Thing or any of its subtypes. Alternatively typeof(T).IsSubclassOf(typeof(Thing)) can be used, if you are sure T cannot be Thing but must be one of its subtypes.
Steps to Reproduce
None, found by code inspection.
System Configuration
Any code that uses the C# SDK.
CDP4 version:
CDP4Common: development branch
CDP4JsonSerializer:
CDP4Dal:
CDP4JsonFileDal:
CDP4ServicesDal:
CDP4WspDal:
Other:
Environment (Operating system, version and so on):
.NET Framework version:
Additional information: Please check for other possible occurrences of the same condition.
The text was updated successfully, but these errors were encountered:
While investigating the issue and reviewing the whole OrderedItemList class it might be a good idea to not only fix this issue, but clean-up and refactor the whole class. Some notes:
for the same kind of problematic/erroneous condition, different kinds of exceptions seem the thrown
some cleanup can be achieved by refactoring code into re-usable private methods
It would be best to not change the public API of the class, unless this is absolutely necessary
Prerequisites
Description
At https://github.com/RHEAGROUP/CDP4-SDK-Community-Edition/blob/fce21a2b9bed488be13eac2533f301653a84a9ff/CDP4Common/Types/OrderedItemList.cs#L566
In
OrderedItemList.Add(...)
the comparisonif (typeof(T) == typeof(Thing))
is incorrect because it only checks that the type of the incomingitem
is directly aThing
, not one of its subtypes.The correct condition is
if (item is Thing)
which properly checks that theitem
is aThing
or any of its subtypes. Alternativelytypeof(T).IsSubclassOf(typeof(Thing))
can be used, if you are sureT
cannot beThing
but must be one of its subtypes.Steps to Reproduce
None, found by code inspection.
System Configuration
Any code that uses the C# SDK.
The text was updated successfully, but these errors were encountered: