Skip to content

Commit

Permalink
Add built-in types to TypeLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
awcullen committed Mar 7, 2021
1 parent effc53e commit d737a76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 8 additions & 0 deletions UaClient.UnitTests/UnitTests/TypeLibraryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@ public void FindTypeByBinaryEncodingId()
.Should().Be(typeof(ReadRequest));
}

[Fact]
public void FindTypeByDataTypeId()
{
TypeLibrary.TryGetTypeFromDataTypeId(ExpandedNodeId.Parse("i=1"), out Type type)
.Should().BeTrue();
type
.Should().Be(typeof(Boolean));
}
}
}
32 changes: 30 additions & 2 deletions UaClient/ServiceModel/Ua/TypeLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;

namespace Workstation.ServiceModel.Ua
{
Expand Down Expand Up @@ -43,8 +44,35 @@ public class TypeLibrary

private TypeLibrary()
{
_typeByDataTypeId = new Dictionary<ExpandedNodeId, Type>();
_dataTypeIdByType = new Dictionary<Type, ExpandedNodeId>();
_typeByDataTypeId = new Dictionary<ExpandedNodeId, Type>()
{
[ExpandedNodeId.Parse(DataTypeIds.Boolean)] = typeof(bool),
[ExpandedNodeId.Parse(DataTypeIds.SByte)] = typeof(sbyte),
[ExpandedNodeId.Parse(DataTypeIds.Byte)] = typeof(byte),
[ExpandedNodeId.Parse(DataTypeIds.Int16)] = typeof(short),
[ExpandedNodeId.Parse(DataTypeIds.UInt16)] = typeof(ushort),
[ExpandedNodeId.Parse(DataTypeIds.Int32)] = typeof(int),
[ExpandedNodeId.Parse(DataTypeIds.UInt32)] = typeof(uint),
[ExpandedNodeId.Parse(DataTypeIds.Int64)] = typeof(long),
[ExpandedNodeId.Parse(DataTypeIds.UInt64)] = typeof(ulong),
[ExpandedNodeId.Parse(DataTypeIds.Float)] = typeof(float),
[ExpandedNodeId.Parse(DataTypeIds.Double)] = typeof(double),
[ExpandedNodeId.Parse(DataTypeIds.String)] = typeof(string),
[ExpandedNodeId.Parse(DataTypeIds.DateTime)] = typeof(DateTime),
[ExpandedNodeId.Parse(DataTypeIds.Guid)] = typeof(Guid),
[ExpandedNodeId.Parse(DataTypeIds.ByteString)] = typeof(byte[]),
[ExpandedNodeId.Parse(DataTypeIds.XmlElement)] = typeof(XElement),
[ExpandedNodeId.Parse(DataTypeIds.NodeId)] = typeof(NodeId),
[ExpandedNodeId.Parse(DataTypeIds.ExpandedNodeId)] = typeof(ExpandedNodeId),
[ExpandedNodeId.Parse(DataTypeIds.StatusCode)] = typeof(StatusCode),
[ExpandedNodeId.Parse(DataTypeIds.QualifiedName)] = typeof(QualifiedName),
[ExpandedNodeId.Parse(DataTypeIds.LocalizedText)] = typeof(LocalizedText),
[ExpandedNodeId.Parse(DataTypeIds.Structure)] = typeof(ExtensionObject),
[ExpandedNodeId.Parse(DataTypeIds.DataValue)] = typeof(DataValue),
[ExpandedNodeId.Parse(DataTypeIds.BaseDataType)] = typeof(Variant),
[ExpandedNodeId.Parse(DataTypeIds.DiagnosticInfo)] = typeof(DiagnosticInfo),
};
_dataTypeIdByType = _typeByDataTypeId.ToDictionary(x => x.Value, x => x.Key);
_binaryEncodingIdByType = new Dictionary<Type, ExpandedNodeId>();
_typeByBinaryEncodingId = new Dictionary<ExpandedNodeId, Type>();
foreach (var assembly in from assembly in AppDomain.CurrentDomain.GetAssemblies()
Expand Down

0 comments on commit d737a76

Please sign in to comment.