mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-29 15:11:53 +08:00
Enhance enum definition handling and validation (#3124)
* Enhance enum definition handling and validation Added a `string enumTypeName` parameter to the `ToEnumDefinition` methods in `ComplexTypeSystem.cs` and `DataTypeDefinitionExtension.cs` to improve enum field name generation, especially when original names are null or empty. Implemented a fallback mechanism to ensure robust naming. In `ComplexTypeBuilder.cs`, added null checks for `typeName` to prevent runtime errors and ensure valid type definitions. Updated logic for defining enum literals to handle empty field names, ensuring unique names are generated based on `typeName` and enum value. * Update Libraries/Opc.Ua.Client.ComplexTypes/TypeBuilder/ComplexTypeBuilder.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Libraries/Opc.Ua.Client.ComplexTypes/DataTypeDefinitionExtension.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix issue from code review --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -899,7 +899,7 @@ namespace Opc.Ua.Client.ComplexTypes
|
||||
if (item is Schema.Binary.EnumeratedType enumeratedObject)
|
||||
{
|
||||
// 1. use Dictionary entry
|
||||
var enumDefinition = enumeratedObject.ToEnumDefinition();
|
||||
var enumDefinition = enumeratedObject.ToEnumDefinition(enumeratedObject.Name);
|
||||
|
||||
// Add EnumDefinition to cache
|
||||
m_dataTypeDefinitionCache[enumType.NodeId] = enumDefinition;
|
||||
@@ -971,12 +971,12 @@ namespace Opc.Ua.Client.ComplexTypes
|
||||
if (enumTypeArray is ExtensionObject[] extensionObject)
|
||||
{
|
||||
// 2. use EnumValues
|
||||
enumDefinition = extensionObject.ToEnumDefinition();
|
||||
enumDefinition = extensionObject.ToEnumDefinition(name.Name);
|
||||
}
|
||||
else if (enumTypeArray is LocalizedText[] localizedText)
|
||||
{
|
||||
// 3. use EnumStrings
|
||||
enumDefinition = localizedText.ToEnumDefinition();
|
||||
enumDefinition = localizedText.ToEnumDefinition(name.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user