private static BuiltInType GetBuiltInType(object value)
{
if (value == null)
{
return BuiltInType.Null;
}
// return the type of the element for array values.
Type systemType = value.GetType();
if (value is Array)
{
systemType = systemType.GetElementType();
}
if (systemType == typeof(bool)) { return BuiltInType.Boolean; }
if (systemType == typeof(sbyte)) { return BuiltInType.SByte; }
if (systemType == typeof(byte)) { return BuiltInType.Byte; }
if (systemType == typeof(short)) { return BuiltInType.Int16; }
if (systemType == typeof(ushort)) { return BuiltInType.UInt16; }
if (systemType == typeof(int)) { return BuiltInType.Int32; }
if (systemType == typeof(uint)) { return BuiltInType.UInt32; }
if (systemType == typeof(long)) { return BuiltInType.Int64; }
if (systemType == typeof(ulong)) { return BuiltInType.UInt64; }
if (systemType == typeof(float)) { return BuiltInType.Float; }
if (systemType == typeof(double)) { return BuiltInType.Double; }
if (systemType == typeof(string)) { return BuiltInType.String; }
if (systemType == typeof(DateTime)) { return BuiltInType.DateTime; }
if (systemType == typeof(Guid)) { return BuiltInType.Guid; }
if (systemType == typeof(Uuid)) { return BuiltInType.Guid; }
if (systemType == typeof(byte[])) { return BuiltInType.ByteString; }
if (systemType == typeof(XmlElement)) { return BuiltInType.XmlElement; }
if (systemType == typeof(NodeId)) { return BuiltInType.NodeId; }
if (systemType == typeof(ExpandedNodeId)) { return BuiltInType.ExpandedNodeId; }
if (systemType == typeof(StatusCode)) { return BuiltInType.StatusCode; }
if (systemType == typeof(DiagnosticInfo)) { return BuiltInType.DiagnosticInfo; }
if (systemType == typeof(QualifiedName)) { return BuiltInType.QualifiedName; }
if (systemType == typeof(LocalizedText)) { return BuiltInType.LocalizedText; }
if (systemType == typeof(ExtensionObject)) { return BuiltInType.ExtensionObject; }
if (systemType == typeof(DataValue)) { return BuiltInType.DataValue; }
if (systemType == typeof(Variant)) { return BuiltInType.Variant; }
if (systemType == typeof(object)) { return BuiltInType.Variant; }
if (systemType.GetTypeInfo().IsEnum)
{
return BuiltInType.Enumeration;
}
// not a recognized type.
return BuiltInType.Null;
}