ctrlX Data Layer .NET API  6.0.1
Loading...
Searching...
No Matches
Variant.cs
1
2
3using comm.datalayer;
4using Datalayer.Internal;
5using Google.FlatBuffers;
6using System;
7using System.Collections;
8using System.Diagnostics;
9using System.Linq;
10using System.Runtime.InteropServices;
11
12namespace Datalayer
13{
17 [DebuggerDisplay("{Value}")]
18 public class Variant : IVariant, INative
19 {
20 // Fields
21 private readonly bool _skipDelete;
22 private unsafe void* _nativePtr;
23
24 #region Internal Ctors
25
37 internal unsafe Variant(void* nativePtr)
38 {
39 _nativePtr = nativePtr;
40 _skipDelete = true;
41 }
42
43 #endregion
44
45 #region Internal Properties
46
50 internal unsafe bool IsNullPtr => _nativePtr == null;
51
55 unsafe void* INative.NativePtr => _nativePtr;
56
57 #endregion
58
59 #region Disposing
60
64 public bool IsDisposed { get; private set; }
65
70 protected virtual void Dispose(bool disposing)
71 {
72 if (!IsDisposed)
73 {
74 if (disposing)
75 {
76 // dispose managed state (managed objects)
77 }
78
79 // free unmanaged resources (unmanaged objects) and override finalizer
80 Delete();
81 // set large fields to null
82 IsDisposed = true;
83 }
84 }
85
89 private void Delete()
90 {
91 unsafe
92 {
93 if (_skipDelete)
94 {
95 _nativePtr = null;
96 return;
97 }
98
99 NativeMethods.Datalayer.DLR_variantDelete(_nativePtr);
100 _nativePtr = null;
101 }
102 }
103
107 ~Variant()
108 {
109 // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
110 Dispose(disposing: false);
111 }
112
116 public void Dispose()
117 {
118 // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
119 Dispose(disposing: true);
120 GC.SuppressFinalize(this);
121 }
122
123 #endregion
124
125 #region Public Ctors
126
130 public Variant()
131 {
132 unsafe
133 {
134 _nativePtr = NativeMethods.Datalayer.DLR_variantCreate();
135 }
136 }
137
143 public Variant(IVariant other)
144 : this()
145 {
146 if (other == null)
147 {
148 throw new ArgumentNullException(nameof(other));
149 }
150
151 unsafe
152 {
153 if (NativeMethods.Datalayer.DLR_variantCopy(_nativePtr, other.ToNativePtr()).IsBad())
154 {
155 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
156 }
157 }
158 }
159
165 public Variant(bool value)
166 : this()
167 {
168 if (SetBool(value).IsBad())
169 {
170 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
171 }
172 }
173
180 public Variant(string value)
181 : this()
182 {
183 if (SetString(value).IsBad())
184 {
185 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
186 }
187 }
188
194 public Variant(sbyte value)
195 : this()
196 {
197 if (SetInt8(value).IsBad())
198 {
199 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
200 }
201 }
202
208 public Variant(short value)
209 : this()
210 {
211 if (SetInt16(value).IsBad())
212 {
213 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
214 }
215 }
216
222 public Variant(int value)
223 : this()
224 {
225 if (SetInt32(value).IsBad())
226 {
227 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
228 }
229 }
230
236 public Variant(long value)
237 : this()
238 {
239 if (SetInt64(value).IsBad())
240 {
241 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
242 }
243 }
244
250 public Variant(DateTime value)
251 : this()
252 {
253 if (SetTimestamp(value).IsBad())
254 {
255 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
256 }
257 }
258
264 public Variant(byte value)
265 : this()
266 {
267 if (SetUInt8(value).IsBad())
268 {
269 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
270 }
271 }
272
278 public Variant(ushort value)
279 : this()
280 {
281 if (SetUInt16(value).IsBad())
282 {
283 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
284 }
285 }
286
292 public Variant(uint value)
293 : this()
294 {
295 if (SetUInt32(value).IsBad())
296 {
297 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
298 }
299 }
300
306 public Variant(ulong value)
307 : this()
308 {
309 if (SetUInt64(value).IsBad())
310 {
311 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
312 }
313 }
314
320 public Variant(float value)
321 : this()
322 {
323 if (SetFloat32(value).IsBad())
324 {
325 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
326 }
327 }
328
334 public Variant(double value)
335 : this()
336 {
337 if (SetFloat64(value).IsBad())
338 {
339 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
340 }
341 }
342
349 public Variant(bool[] value)
350 : this()
351 {
352 if (SetArrayOfBool(value).IsBad())
353 {
354 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
355 }
356 }
357
364 public Variant(string[] value)
365 : this()
366 {
367 if (SetArrayOfString(value).IsBad())
368 {
369 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
370 }
371 }
372
379 public Variant(sbyte[] value)
380 : this()
381 {
382 if (SetArrayOfInt8(value).IsBad())
383 {
384 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
385 }
386 }
387
394 public Variant(short[] value)
395 : this()
396 {
397 if (SetArrayOfInt16(value).IsBad())
398 {
399 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
400 }
401 }
402
409 public Variant(int[] value)
410 : this()
411 {
412 if (SetArrayOfInt32(value).IsBad())
413 {
414 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
415 }
416 }
417
424 public Variant(long[] value)
425 : this()
426 {
427 if (SetArrayOfInt64(value).IsBad())
428 {
429 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
430 }
431 }
432
440 public Variant(byte[] value, bool raw = false)
441 : this()
442 {
443 if (raw)
444 {
445 if (SetArrayOfRawBytes(value).IsBad())
446 {
447 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
448 }
449 }
450 else
451 {
452 if (SetArrayOfUInt8(value).IsBad())
453 {
454 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
455 }
456 }
457 }
458
465 public Variant(ushort[] value)
466 : this()
467 {
468 if (SetArrayOfUInt16(value).IsBad())
469 {
470 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
471 }
472 }
473
480 public Variant(uint[] value)
481 : this()
482 {
483 if (SetArrayOfUInt32(value).IsBad())
484 {
485 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
486 }
487 }
488
495 public Variant(ulong[] value)
496 : this()
497 {
498 if (SetArrayOfUInt64(value).IsBad())
499 {
500 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
501 }
502 }
503
510 public Variant(float[] value)
511 : this()
512 {
513 if (SetArrayOfFloat32(value).IsBad())
514 {
515 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
516 }
517 }
518
525 public Variant(double[] value)
526 : this()
527 {
528 if (SetArrayOfFloat64(value).IsBad())
529 {
530 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
531 }
532 }
533
534
541 public Variant(DateTime[] value)
542 : this()
543 {
544 if (SetArrayOfTimestamp(value).IsBad())
545 {
546 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
547 }
548 }
549
556 public Variant(ByteBuffer flatBuffers)
557 : this()
558 {
559 if (SetFlatbuffers(flatBuffers).IsBad())
560 {
561 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
562 }
563 }
564
571 public Variant(FlatBufferBuilder builder)
572 : this()
573 {
574 if (builder == null)
575 {
576 throw new ArgumentNullException(nameof(builder));
577 }
578
579 if (SetFlatbuffers(builder.DataBuffer).IsBad())
580 {
581 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
582 }
583 }
584
591 public Variant(MetadataT metadata)
592 : this()
593 {
594 var builder = new FlatBufferBuilder(DefaultFlatbuffersInitialSize);
595 Metadata.FinishMetadataBuffer(builder, Metadata.Pack(builder, metadata));
596
597 if (SetFlatbuffers(builder.DataBuffer).IsBad())
598 {
599 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCreatable);
600 }
601 }
602
603 #endregion
604
605 #region Public Overrides
606
612 public override bool Equals(object obj)
613 {
614 return Equals(obj as Variant);
615 }
616
623 public bool Equals(Variant other)
624 {
625 if (other is null)
626 {
627 return false;
628 }
629
630 if (ReferenceEquals(this, other))
631 {
632 return true;
633 }
634
635 var dataType = DataType;
636 if (dataType != other.DataType)
637 {
638 return false;
639 }
640
641 //Arrays
642 if (Utils.IsArray(dataType))
643 {
644 return StructuralComparisons.StructuralEqualityComparer.Equals(Value, other.Value);
645 }
646
647 //Flatbuffers
648 if (dataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLATBUFFERS)
649 {
650 return StructuralComparisons.StructuralEqualityComparer.Equals(ToFlatbuffers().ToSizedArray(), other.ToFlatbuffers().ToSizedArray());
651 }
652
653 //Scalars
654 return Equals(Value, other.Value);
655 }
656
661 public override int GetHashCode()
662 {
663 var v = Value;
664 return v != null ? base.GetHashCode() ^ v.GetHashCode() : base.GetHashCode();
665 }
666
672 public override string ToString()
673 {
674 if (IsNull)
675 {
676 return string.Empty;
677 }
678
679 unsafe
680 {
681 var length = Convert.ToInt32(GetSize().ToUInt32()) - 1;
682 if (length <= 0)
683 {
684 return string.Empty;
685 }
686
687 var stringBuffer =
688 StringBuffer.FromNativePtr(NativeMethods.Datalayer.DLR_variantGetSTRING(_nativePtr), length);
689 return stringBuffer.ToString();
690 }
691 }
692
699 public static bool operator ==(Variant l, Variant r)
700 {
701 //x not null
702 if (l is Variant)
703 {
704 return l.Equals(r);
705 }
706
707 //y not null
708 if (r is Variant)
709 {
710 return r.Equals(l);
711 }
712
713 //Both null
714 return true;
715 }
716
723 public static bool operator !=(Variant l, Variant r)
724 {
725 //x not null
726 if (l is Variant)
727 {
728 return !l.Equals(r);
729 }
730
731 //y not null
732 if (r is Variant)
733 {
734 return !r.Equals(l);
735 }
736
737 //Both null
738 return false;
739 }
740
741 #endregion
742
743 #region Public Statics
744
748 public static readonly int DefaultFlatbuffersInitialSize = 1024;
749
753 public static readonly Variant Null = new Variant();
754
758 public static readonly Variant Zero = new Variant(0);
759
763 public static readonly Variant One = new Variant(1);
764
768 public static readonly Variant Empty = new Variant(string.Empty);
769
773 public static readonly Variant True = new Variant(true);
774
778 public static readonly Variant False = new Variant(false);
779
780 #endregion
781
782 #region Public Getters
783
788 public object Value
789 {
790 get
791 {
792 switch (DataType)
793 {
794 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_BOOL8:
795 return ToBool();
796 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT8:
797 return ToSByte();
798 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT8:
799 return ToByte();
800 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT16:
801 return ToInt16();
802 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT16:
803 return ToUInt16();
804 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT32:
805 return ToInt32();
806 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT32:
807 return ToUInt32();
808 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT64:
809 return ToInt64();
810 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT64:
811 return ToUInt64();
812 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLOAT32:
813 return ToFloat();
814 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLOAT64:
815 return ToDouble();
816 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_STRING:
817 return ToString();
818 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_TIMESTAMP:
819 return ToDateTime();
820 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_BOOL8:
821 return ToBoolArray();
822 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT8:
823 return ToSByteArray();
824 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT8:
825 return ToByteArray();
826 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT16:
827 return ToInt16Array();
828 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT16:
829 return ToUInt16Array();
830 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT32:
831 return ToInt32Array();
832 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT32:
833 return ToUInt32Array();
834 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT64:
835 return ToInt64Array();
836 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT64:
837 return ToUInt64Array();
838 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_FLOAT32:
839 return ToFloatArray();
840 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_FLOAT64:
841 return ToDoubleArray();
842 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_STRING:
843 return ToStringArray();
844 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_TIMESTAMP:
845 return ToDateTimeArray();
846 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_RAW:
847 return ToRawByteArray();
848 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLATBUFFERS:
849 return ToFlatbuffers();
850 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UNKNOWN:
851 default:
852 return null;
853 }
854 }
855 }
856
861 public bool IsNull => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UNKNOWN;
862
867 public bool IsString => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_STRING;
868
873 public bool IsBool => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_BOOL8;
874
879 public bool IsFlatbuffers => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLATBUFFERS;
880
885 public bool IsArray
886 {
887 get
888 {
889 if (IsDisposed)
890 {
891 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
892 }
893
894 return Utils.IsArray(DataType);
895 }
896 }
897
903 public bool IsNumber
904 {
905 get
906 {
907 if (IsDisposed)
908 {
909 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
910 }
911
912 return Utils.IsNumber(DataType);
913 }
914 }
915
921 public bool ToBool()
922 {
923 if (IsNull)
924 {
925 return false;
926 }
927
928 unsafe
929 {
930 return NativeMethods.Datalayer.DLR_variantGetBOOL8(_nativePtr);
931 }
932 }
933
939 public sbyte ToSByte()
940 {
941 if (IsNull)
942 {
943 return 0;
944 }
945
946 unsafe
947 {
948 return NativeMethods.Datalayer.DLR_variantGetINT8(_nativePtr);
949 }
950 }
951
957 public byte ToByte()
958 {
959 if (IsNull)
960 {
961 return 0;
962 }
963
964 unsafe
965 {
966 return NativeMethods.Datalayer.DLR_variantGetUINT8(_nativePtr);
967 }
968 }
969
975 public short ToInt16()
976 {
977 if (IsNull)
978 {
979 return 0;
980 }
981
982 unsafe
983 {
984 return NativeMethods.Datalayer.DLR_variantGetINT16(_nativePtr);
985 }
986 }
987
993 public ushort ToUInt16()
994 {
995 if (IsNull)
996 {
997 return 0;
998 }
999
1000 unsafe
1001 {
1002 return NativeMethods.Datalayer.DLR_variantGetUINT16(_nativePtr);
1003 }
1004 }
1005
1011 public int ToInt32()
1012 {
1013 if (IsNull)
1014 {
1015 return 0;
1016 }
1017
1018 unsafe
1019 {
1020 return NativeMethods.Datalayer.DLR_variantGetINT32(_nativePtr);
1021 }
1022 }
1023
1029 public uint ToUInt32()
1030 {
1031 if (IsNull)
1032 {
1033 return 0;
1034 }
1035
1036 unsafe
1037 {
1038 return NativeMethods.Datalayer.DLR_variantGetUINT32(_nativePtr);
1039 }
1040 }
1041
1047 public long ToInt64()
1048 {
1049 if (IsNull)
1050 {
1051 return 0;
1052 }
1053
1054 unsafe
1055 {
1056 return NativeMethods.Datalayer.DLR_variantGetINT64(_nativePtr);
1057 }
1058 }
1059
1065 public ulong ToUInt64()
1066 {
1067 if (IsNull)
1068 {
1069 return 0;
1070 }
1071
1072 unsafe
1073 {
1074 return NativeMethods.Datalayer.DLR_variantGetUINT64(_nativePtr);
1075 }
1076 }
1077
1082 public DateTime ToDateTime()
1083 {
1084 //uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC) -> long -> DateTime
1085 return DateTime.FromFileTimeUtc(Convert.ToInt64(ToUInt64()));
1086 }
1087
1093 public float ToFloat()
1094 {
1095 if (IsNull)
1096 {
1097 return 0;
1098 }
1099
1100 unsafe
1101 {
1102 return NativeMethods.Datalayer.DLR_variantGetFLOAT32(_nativePtr);
1103 }
1104 }
1105
1111 public double ToDouble()
1112 {
1113 if (IsNull)
1114 {
1115 return 0;
1116 }
1117
1118 unsafe
1119 {
1120 return NativeMethods.Datalayer.DLR_variantGetFLOAT64(_nativePtr);
1121 }
1122 }
1123
1129 public bool[] ToBoolArray()
1130 {
1131 if (IsNull)
1132 {
1133 return null;
1134 }
1135
1136 unsafe
1137 {
1138 bool* p = NativeMethods.Datalayer.DLR_variantGetArrayOfBOOL8(_nativePtr);
1139 if (p == null)
1140 {
1141 return Array.Empty<bool>();
1142 }
1143
1144 // memcopy not available: we have to iterate
1145
1146 //var array = new bool[GetCount().ToUInt32()];
1147 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1148
1149 var count = GetCount().ToUInt32();
1150 var array = new bool[count];
1151 for (var i = 0; i < count; i++)
1152 {
1153 array[i] = p[i];
1154 }
1155 return array;
1156 }
1157 }
1158
1164 public sbyte[] ToSByteArray()
1165 {
1166 if (IsNull)
1167 {
1168 return null;
1169 }
1170
1171 unsafe
1172 {
1173 sbyte* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT8(_nativePtr);
1174 if (p == null)
1175 {
1176 return Array.Empty<sbyte>();
1177 }
1178
1179 // memcopy not available: we have to iterate
1180
1181 //var array = new sbyte[GetCount().ToUInt32()];
1182 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1183
1184 var count = GetCount().ToUInt32();
1185 var array = new sbyte[count];
1186 for (var i = 0; i < count; i++)
1187 {
1188 array[i] = p[i];
1189 }
1190 return array;
1191 }
1192 }
1193
1199 public byte[] ToByteArray()
1200 {
1201 if (IsNull)
1202 {
1203 return null;
1204 }
1205
1206 unsafe
1207 {
1208 byte* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT8(_nativePtr);
1209 if (p == null)
1210 {
1211 return Array.Empty<byte>();
1212 }
1213
1214 var array = new byte[GetCount().ToUInt32()];
1215 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1216 return array;
1217 }
1218 }
1219
1225 public short[] ToInt16Array()
1226 {
1227 if (IsNull)
1228 {
1229 return null;
1230 }
1231
1232 unsafe
1233 {
1234 short* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT16(_nativePtr);
1235 if (p == null)
1236 {
1237 return Array.Empty<short>();
1238 }
1239
1240 var array = new short[GetCount().ToUInt32()];
1241 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1242 return array;
1243 }
1244 }
1245
1251 public ushort[] ToUInt16Array()
1252 {
1253 if (IsNull)
1254 {
1255 return null;
1256 }
1257
1258 unsafe
1259 {
1260 ushort* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT16(_nativePtr);
1261 if (p == null)
1262 {
1263 return Array.Empty<ushort>();
1264 }
1265 // memcopy not available: we have to iterate
1266
1267 //var array = new ushort[GetCount().ToUInt32()];
1268 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1269
1270 var count = GetCount().ToUInt32();
1271 var array = new ushort[count];
1272 for (var i = 0; i < count; i++)
1273 {
1274 array[i] = p[i];
1275 }
1276 return array;
1277 }
1278 }
1279
1285 public int[] ToInt32Array()
1286 {
1287 if (IsNull)
1288 {
1289 return null;
1290 }
1291
1292 unsafe
1293 {
1294 int* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT32(_nativePtr);
1295 if (p == null)
1296 {
1297 return Array.Empty<int>();
1298 }
1299
1300 var array = new int[GetCount().ToUInt32()];
1301 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1302 return array;
1303 }
1304 }
1305
1311 public uint[] ToUInt32Array()
1312 {
1313 if (IsNull)
1314 {
1315 return null;
1316 }
1317
1318 unsafe
1319 {
1320 uint* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT32(_nativePtr);
1321 if (p == null)
1322 {
1323 return Array.Empty<uint>();
1324 }
1325
1326 // memcopy not available: we have to iterate
1327
1328 //var array = new uint[GetCount().ToUInt32()];
1329 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1330
1331 var count = GetCount().ToUInt32();
1332 var array = new uint[count];
1333 for (var i = 0; i < count; i++)
1334 {
1335 array[i] = p[i];
1336 }
1337 return array;
1338 }
1339 }
1340
1346 public long[] ToInt64Array()
1347 {
1348 if (IsNull)
1349 {
1350 return null;
1351 }
1352
1353 unsafe
1354 {
1355 long* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT64(_nativePtr);
1356 if (p == null)
1357 {
1358 return Array.Empty<long>();
1359 }
1360
1361 var array = new long[GetCount().ToUInt32()];
1362 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1363 return array;
1364 }
1365 }
1366
1372 public ulong[] ToUInt64Array()
1373 {
1374 if (IsNull)
1375 {
1376 return null;
1377 }
1378
1379 unsafe
1380 {
1381 ulong* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT64(_nativePtr);
1382 if (p == null)
1383 {
1384 return Array.Empty<ulong>();
1385 }
1386
1387 // memcopy not available: we have to iterate
1388
1389 //var array = new ulong[GetCount().ToUInt32()];
1390 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1391
1392 var count = GetCount().ToUInt32();
1393 var array = new ulong[count];
1394 for (var i = 0; i < count; i++)
1395 {
1396 array[i] = p[i];
1397 }
1398 return array;
1399 }
1400 }
1401
1407 public float[] ToFloatArray()
1408 {
1409 if (IsNull)
1410 {
1411 return null;
1412 }
1413
1414 unsafe
1415 {
1416 float* p = NativeMethods.Datalayer.DLR_variantGetArrayOfFLOAT32(_nativePtr);
1417 if (p == null)
1418 {
1419 return Array.Empty<float>();
1420 }
1421
1422 var array = new float[GetCount().ToUInt32()];
1423 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1424 return array;
1425 }
1426 }
1427
1433 public double[] ToDoubleArray()
1434 {
1435 if (IsNull)
1436 {
1437 return null;
1438 }
1439
1440 unsafe
1441 {
1442 double* p = NativeMethods.Datalayer.DLR_variantGetArrayOfFLOAT64(_nativePtr);
1443 if (p == null)
1444 {
1445 return Array.Empty<double>();
1446 }
1447
1448 var array = new double[GetCount().ToUInt32()];
1449 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1450 return array;
1451 }
1452 }
1453
1459 public string[] ToStringArray()
1460 {
1461 if (IsNull)
1462 {
1463 return null;
1464 }
1465
1466 unsafe
1467 {
1468 sbyte** p = NativeMethods.Datalayer.DLR_variantGetArrayOfSTRING(_nativePtr);
1469 if (p == null)
1470 {
1471 return Array.Empty<string>();
1472 }
1473
1474 var count = GetCount().ToUInt32();
1475 var stringBufferArray = StringBufferArray.FromNativePtr(p, count);
1476 return stringBufferArray.ToStringArray();
1477 }
1478 }
1479
1485 public DateTime[] ToDateTimeArray()
1486 {
1487 //uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC) -> long -> DateTime
1488 return ToUInt64Array()?.Select(v => DateTime.FromFileTimeUtc(Convert.ToInt64(v))).ToArray();
1489 }
1490
1496 {
1497 get
1498 {
1499 if (IsDisposed)
1500 {
1501 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1502 }
1503
1504 if (IsNullPtr)
1505 {
1506 return DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UNKNOWN;
1507 }
1508
1509 unsafe
1510 {
1511 return NativeMethods.Datalayer.DLR_variantGetType(_nativePtr);
1512 }
1513 }
1514 }
1515
1520 public string JsonDataType
1521 {
1522 get
1523 {
1524 if (IsDisposed)
1525 {
1526 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1527 }
1528
1529 return Utils.ToJsonDataType(DataType);
1530 }
1531 }
1532
1538 public ByteBuffer ToFlatbuffers()
1539 {
1540 if (IsNull)
1541 {
1542 return null;
1543 }
1544
1545 if (!IsFlatbuffers)
1546 {
1547 return null;
1548 }
1549
1550 unsafe
1551 {
1552 byte* p = NativeMethods.Datalayer.DLR_variantGetData(_nativePtr);
1553 if (p == null)
1554 {
1555 return null;
1556 }
1557
1558 var array = new byte[GetCount().ToUInt32()];
1559 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1560 return new ByteBuffer(array);
1561 }
1562 }
1563
1569 public byte[] ToRawByteArray()
1570 {
1571 if (IsNull)
1572 {
1573 return null;
1574 }
1575
1576 unsafe
1577 {
1578 byte* p = NativeMethods.Datalayer.DLR_variantGetData(_nativePtr);
1579 if (p == null)
1580 {
1581 return Array.Empty<byte>();
1582 }
1583
1584 var array = new byte[GetCount().ToUInt32()];
1585 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1586 return array;
1587 }
1588 }
1589
1590 #endregion
1591
1592 #region Public Methods
1593
1602 public (DLR_RESULT result, IVariant value) GetDataFromFlatbuffers(IVariant typeFlatbuffers, string query)
1603 {
1604 if (typeFlatbuffers == null)
1605 {
1606 throw new ArgumentNullException(nameof(typeFlatbuffers));
1607 }
1608
1609 if (query == null)
1610 {
1611 throw new ArgumentNullException(nameof(query));
1612 }
1613
1614 if (IsNull)
1615 {
1616 return (DLR_RESULT.DL_INVALID_VALUE, Null);
1617 }
1618
1619 var dataValue = new Variant();
1620 var queryBuffer = StringBuffer.FromString(query);
1621
1622 unsafe
1623 {
1624 return (NativeMethods.Datalayer.DLR_getDataFromFlatbuffers(
1625 this.ToNativePtr(),
1626 typeFlatbuffers.ToNativePtr(),
1627 queryBuffer.ToNativePtr(),
1628 dataValue.ToNativePtr()), dataValue);
1629 }
1630 }
1631
1638 {
1639 if (IsDisposed)
1640 {
1641 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1642 }
1643
1644 if (IsNullPtr)
1645 {
1646 return new Variant();
1647 }
1648
1649 unsafe
1650 {
1651 var clone = new Variant();
1652 if (NativeMethods.Datalayer.DLR_variantCopy(clone.ToNativePtr(), this.ToNativePtr()).IsBad())
1653 {
1654 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCloneable);
1655 }
1656
1657 return clone;
1658 }
1659 }
1660
1668 {
1669 if (IsNull)
1670 {
1671 return DLR_RESULT.DL_TYPE_MISMATCH;
1672 }
1673
1674 unsafe
1675 {
1676 return NativeMethods.Datalayer.DLR_variantCheckConvert(_nativePtr, type);
1677 }
1678 }
1679
1680 #endregion
1681
1682 #region Public Implicit Operators
1683
1688 public static implicit operator Variant(bool source)
1689 {
1690 return new Variant(source);
1691 }
1692
1697 public static implicit operator Variant(bool[] source)
1698 {
1699 return new Variant(source);
1700 }
1701
1706 public static implicit operator Variant(sbyte source)
1707 {
1708 return new Variant(source);
1709 }
1710
1714 public static implicit operator Variant(sbyte[] source)
1715 {
1716 return new Variant(source);
1717 }
1718
1723 public static implicit operator Variant(byte source)
1724 {
1725 return new Variant(source);
1726 }
1727
1731 public static implicit operator Variant(byte[] source)
1732 {
1733 return new Variant(source);
1734 }
1735
1740 public static implicit operator Variant(short source)
1741 {
1742 return new Variant(source);
1743 }
1744
1748 public static implicit operator Variant(short[] source)
1749 {
1750 return new Variant(source);
1751 }
1756 public static implicit operator Variant(ushort source)
1757 {
1758 return new Variant(source);
1759 }
1760
1764 public static implicit operator Variant(ushort[] source)
1765 {
1766 return new Variant(source);
1767 }
1768
1773 public static implicit operator Variant(int source)
1774 {
1775 return new Variant(source);
1776 }
1777
1782 public static implicit operator Variant(int[] source)
1783 {
1784 return new Variant(source);
1785 }
1786
1791 public static implicit operator Variant(uint source)
1792 {
1793 return new Variant(source);
1794 }
1795
1800 public static implicit operator Variant(uint[] source)
1801 {
1802 return new Variant(source);
1803 }
1804
1809 public static implicit operator Variant(long source)
1810 {
1811 return new Variant(source);
1812 }
1813
1818 public static implicit operator Variant(long[] source)
1819 {
1820 return new Variant(source);
1821 }
1822
1827 public static implicit operator Variant(ulong source)
1828 {
1829 return new Variant(source);
1830 }
1831
1835 public static implicit operator Variant(ulong[] source)
1836 {
1837 return new Variant(source);
1838 }
1839
1844 public static implicit operator Variant(float source)
1845 {
1846 return new Variant(source);
1847 }
1848
1852 public static implicit operator Variant(float[] source)
1853 {
1854 return new Variant(source);
1855 }
1856
1861 public static implicit operator Variant(double source)
1862 {
1863 return new Variant(source);
1864 }
1865
1869 public static implicit operator Variant(double[] source)
1870 {
1871 return new Variant(source);
1872 }
1873
1878 public static implicit operator Variant(string source)
1879 {
1880 return new Variant(source);
1881 }
1882
1887 public static implicit operator Variant(string[] source)
1888 {
1889 return new Variant(source);
1890 }
1891
1896 public static implicit operator Variant(DateTime source)
1897 {
1898 return new Variant(source);
1899 }
1900
1905 public static implicit operator Variant(DateTime[] source)
1906 {
1907 return new Variant(source);
1908 }
1909
1914 public static implicit operator Variant(FlatBufferBuilder source)
1915 {
1916 return new Variant(source);
1917 }
1918
1923 public static implicit operator Variant(ByteBuffer source)
1924 {
1925 return new Variant(source);
1926 }
1927
1932 public static implicit operator Variant(MetadataT source)
1933 {
1934 return new Variant(source);
1935 }
1936
1937 #endregion
1938
1939 #region Private Setter
1940
1946 private DLR_RESULT SetBool(bool value)
1947 {
1948 unsafe
1949 {
1950 return NativeMethods.Datalayer.DLR_variantSetBOOL8(_nativePtr, Convert.ToByte(value));
1951 }
1952 }
1953
1959 private DLR_RESULT SetInt8(sbyte value)
1960 {
1961 unsafe
1962 {
1963 return NativeMethods.Datalayer.DLR_variantSetINT8(_nativePtr, value);
1964 }
1965 }
1966
1972 private DLR_RESULT SetUInt8(byte value)
1973 {
1974 unsafe
1975 {
1976 return NativeMethods.Datalayer.DLR_variantSetUINT8(_nativePtr, value);
1977 }
1978 }
1979
1985 private DLR_RESULT SetInt16(short value)
1986 {
1987 unsafe
1988 {
1989 return NativeMethods.Datalayer.DLR_variantSetINT16(_nativePtr, value);
1990 }
1991 }
1992
1998 private DLR_RESULT SetUInt16(ushort value)
1999 {
2000 unsafe
2001 {
2002 return NativeMethods.Datalayer.DLR_variantSetUINT16(_nativePtr, value);
2003 }
2004 }
2005
2011 private DLR_RESULT SetInt32(int value)
2012 {
2013 unsafe
2014 {
2015 return NativeMethods.Datalayer.DLR_variantSetINT32(_nativePtr, value);
2016 }
2017 }
2018
2024 private DLR_RESULT SetUInt32(uint value)
2025 {
2026 unsafe
2027 {
2028 return NativeMethods.Datalayer.DLR_variantSetUINT32(_nativePtr, value);
2029 }
2030 }
2031
2037 private DLR_RESULT SetInt64(long value)
2038 {
2039 unsafe
2040 {
2041 return NativeMethods.Datalayer.DLR_variantSetINT64(_nativePtr, value);
2042 }
2043 }
2044
2050 private DLR_RESULT SetUInt64(ulong value)
2051 {
2052 unsafe
2053 {
2054 return NativeMethods.Datalayer.DLR_variantSetUINT64(_nativePtr, value);
2055 }
2056 }
2057
2063 private DLR_RESULT SetFloat32(float value)
2064 {
2065 unsafe
2066 {
2067 return NativeMethods.Datalayer.DLR_variantSetFLOAT32(_nativePtr, value);
2068 }
2069 }
2070
2076 private DLR_RESULT SetFloat64(double value)
2077 {
2078 unsafe
2079 {
2080 return NativeMethods.Datalayer.DLR_variantSetFLOAT64(_nativePtr, value);
2081 }
2082 }
2083
2090 private DLR_RESULT SetString(string value)
2091 {
2092 if (value == null)
2093 {
2094 throw new ArgumentNullException(nameof(value));
2095 }
2096
2097 var valueBuffer = StringBuffer.FromString(value);
2098 unsafe
2099 {
2100 return NativeMethods.Datalayer.DLR_variantSetSTRING(_nativePtr, valueBuffer.ToNativePtr());
2101 }
2102 }
2103
2109 private DLR_RESULT SetTimestamp(DateTime value)
2110 {
2111 unsafe
2112 {
2113 try
2114 {
2115 //DateTime -> FileTimeUtc -> ulong -> uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC)
2116 return NativeMethods.Datalayer.DLR_variantSetTimestamp(_nativePtr, Convert.ToUInt64(value.ToFileTimeUtc()));
2117 }
2118 catch (ArgumentOutOfRangeException)
2119 {
2120 // The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
2121 return DLR_RESULT.DL_FAILED;
2122 }
2123 }
2124 }
2125
2132 private DLR_RESULT SetArrayOfBool(bool[] value)
2133 {
2134 if (value == null)
2135 {
2136 throw new ArgumentNullException(nameof(value));
2137 }
2138
2139 unsafe
2140 {
2141 fixed (bool* p = value)
2142 {
2143 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_BOOL8(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2144 }
2145 }
2146 }
2147
2154 private DLR_RESULT SetArrayOfInt8(sbyte[] value)
2155 {
2156 if (value == null)
2157 {
2158 throw new ArgumentNullException(nameof(value));
2159 }
2160
2161 unsafe
2162 {
2163 fixed (sbyte* p = value)
2164 {
2165 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT8(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2166 }
2167 }
2168 }
2169
2176 private DLR_RESULT SetArrayOfUInt8(byte[] value)
2177 {
2178 if (value == null)
2179 {
2180 throw new ArgumentNullException(nameof(value));
2181 }
2182
2183 unsafe
2184 {
2185 fixed (byte* p = value)
2186 {
2187 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT8(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2188 }
2189 }
2190 }
2191
2198 private DLR_RESULT SetArrayOfInt16(short[] value)
2199 {
2200 if (value == null)
2201 {
2202 throw new ArgumentNullException(nameof(value));
2203 }
2204
2205 unsafe
2206 {
2207 fixed (short* p = value)
2208 {
2209 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT16(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2210 }
2211 }
2212 }
2213
2220 private DLR_RESULT SetArrayOfUInt16(ushort[] value)
2221 {
2222 if (value == null)
2223 {
2224 throw new ArgumentNullException(nameof(value));
2225 }
2226
2227 unsafe
2228 {
2229 fixed (ushort* p = value)
2230 {
2231 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT16(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2232 }
2233 }
2234 }
2235
2242 private DLR_RESULT SetArrayOfInt32(int[] value)
2243 {
2244 if (value == null)
2245 {
2246 throw new ArgumentNullException(nameof(value));
2247 }
2248
2249 unsafe
2250 {
2251 fixed (int* p = value)
2252 {
2253 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT32(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2254 }
2255 }
2256 }
2257
2264 private DLR_RESULT SetArrayOfUInt32(uint[] value)
2265 {
2266 if (value == null)
2267 {
2268 throw new ArgumentNullException(nameof(value));
2269 }
2270
2271 unsafe
2272 {
2273 fixed (uint* p = value)
2274 {
2275 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT32(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2276 }
2277 }
2278 }
2279
2286 private DLR_RESULT SetArrayOfInt64(long[] value)
2287 {
2288 if (value == null)
2289 {
2290 throw new ArgumentNullException(nameof(value));
2291 }
2292
2293 unsafe
2294 {
2295 fixed (long* p = value)
2296 {
2297 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT64(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2298 }
2299 }
2300 }
2301
2308 private DLR_RESULT SetArrayOfUInt64(ulong[] value)
2309 {
2310 if (value == null)
2311 {
2312 throw new ArgumentNullException(nameof(value));
2313 }
2314
2315 unsafe
2316 {
2317 fixed (ulong* p = value)
2318 {
2319 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT64(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2320 }
2321 }
2322 }
2323
2330 private DLR_RESULT SetArrayOfFloat32(float[] value)
2331 {
2332 if (value == null)
2333 {
2334 throw new ArgumentNullException(nameof(value));
2335 }
2336
2337 unsafe
2338 {
2339 fixed (float* p = value)
2340 {
2341 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_FLOAT32(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2342 }
2343 }
2344 }
2345
2352 private DLR_RESULT SetArrayOfFloat64(double[] value)
2353 {
2354 if (value == null)
2355 {
2356 throw new ArgumentNullException(nameof(value));
2357 }
2358
2359 unsafe
2360 {
2361 fixed (double* p = value)
2362 {
2363 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_FLOAT64(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2364 }
2365 }
2366 }
2367
2374 private DLR_RESULT SetArrayOfTimestamp(DateTime[] value)
2375 {
2376 if (value == null)
2377 {
2378 throw new ArgumentNullException(nameof(value));
2379 }
2380
2381 unsafe
2382 {
2383 try
2384 {
2385 //DateTime -> FileTimeUtc -> ulong -> uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC)
2386 var timeStamps = value.Select(v => Convert.ToUInt64(v.ToFileTimeUtc())).ToArray();
2387
2388 fixed (ulong* p = timeStamps)
2389 {
2390 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_TIMESTAMP(_nativePtr, p, new UIntPtr(Convert.ToUInt32(timeStamps.Length)));
2391 }
2392 }
2393 catch (ArgumentOutOfRangeException)
2394 {
2395 // The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
2396 return DLR_RESULT.DL_FAILED;
2397 }
2398 }
2399 }
2400
2407 private DLR_RESULT SetArrayOfString(string[] value)
2408 {
2409 if (value == null)
2410 {
2411 throw new ArgumentNullException(nameof(value));
2412 }
2413
2414 var stringBufferArray = StringBufferArray.FromStringArray(value);
2415 unsafe
2416 {
2417 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_STRING(_nativePtr, stringBufferArray.ToNativePtr(), new UIntPtr(Convert.ToUInt32(value.Length)));
2418 }
2419 }
2420
2427 private DLR_RESULT SetFlatbuffers(ByteBuffer value)
2428 {
2429 if (value == null)
2430 {
2431 throw new ArgumentNullException(nameof(value));
2432 }
2433
2434 // Note: We have to convert Flatbuffers original byte[] to a sbyte[], because of bad Datalayer ANSI-C API design (which would be a incompabible change to byte[]).
2435
2436 //OPTION A: SLOW: Convert byte[] to sbyte[] bytewise
2437 //var sbyteArray = Array.ConvertAll(value.ToSizedArray(), b => unchecked((sbyte)b));
2438 //unsafe
2439 //{
2440 // fixed (sbyte* p = sbyteArray)
2441 // {
2442 // return NativeMethods.Datalayer.DLR_variantSetFlatbuffers(_nativePtr, p, new UIntPtr(Convert.ToUInt32(sbyteArray.Length)));
2443 // }
2444 //}
2445
2446 //OPTION B: FASTER: Use BlockCopy to convert byte[] to sbyte[]
2447 //var buffer = value.ToSizedArray();
2448 //sbyte[] sbyteArray = new sbyte[buffer.Length];
2449 //Buffer.BlockCopy(buffer, 0, sbyteArray, 0, buffer.Length);
2450 //unsafe
2451 //{
2452 // fixed (sbyte* p = sbyteArray)
2453 // {
2454 // return NativeMethods.Datalayer.DLR_variantSetFlatbuffers(_nativePtr, p, new UIntPtr(Convert.ToUInt32(sbyteArray.Length)));
2455 // }
2456 //}
2457
2458 //OPTION C: FASTEST: Convert byte* to sbyte*, pointing to original memory (no copy)
2459 var byteArray = value.ToSizedArray();
2460 unsafe
2461 {
2462 fixed (byte* p = byteArray)
2463 {
2464 sbyte* psByte = (sbyte*)p;
2465 return NativeMethods.Datalayer.DLR_variantSetFlatbuffers(_nativePtr, psByte, new UIntPtr(Convert.ToUInt32(byteArray.Length)));
2466 }
2467 }
2468 }
2469
2476 private DLR_RESULT SetArrayOfRawBytes(byte[] value)
2477 {
2478 if (value == null)
2479 {
2480 throw new ArgumentNullException(nameof(value));
2481 }
2482
2483 unsafe
2484 {
2485 fixed (byte* p = value)
2486 {
2487 sbyte* psByte = (sbyte*)p;
2488 return NativeMethods.Datalayer.DLR_variantSetRaw(_nativePtr, psByte, new UIntPtr(Convert.ToUInt32(value.Length)));
2489 }
2490 }
2491 }
2492
2493 #endregion
2494
2495 #region Private Methods
2496
2501 internal UIntPtr GetSize()
2502 {
2503 if (IsNull)
2504 {
2505 return UIntPtr.Zero;
2506 }
2507
2508 unsafe
2509 {
2510 return NativeMethods.Datalayer.DLR_variantGetSize(_nativePtr);
2511 }
2512 }
2513
2518 internal UIntPtr GetCount()
2519 {
2520 if (IsNull)
2521 {
2522 return UIntPtr.Zero;
2523 }
2524
2525 unsafe
2526 {
2527 return NativeMethods.Datalayer.DLR_variantGetCount(_nativePtr);
2528 }
2529 }
2530 #endregion
2531 }
2532}
Provides the implementation for IVariant.
Definition: Variant.cs:19
string[] ToStringArray()
Gets the value as string array.
Definition: Variant.cs:1459
short ToInt16()
Gets the value as short.
Definition: Variant.cs:975
long[] ToInt64Array()
Gets the value as long array.
Definition: Variant.cs:1346
sbyte ToSByte()
Gets the value as sbyte.
Definition: Variant.cs:939
float[] ToFloatArray()
Gets the value as float array.
Definition: Variant.cs:1407
double ToDouble()
Gets the value as double.
Definition: Variant.cs:1111
Variant(sbyte[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:379
Variant(string value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:180
sbyte[] ToSByteArray()
Gets the value as sbyte array.
Definition: Variant.cs:1164
Variant(MetadataT metadata)
Initializes a new instance of the Variant class.
Definition: Variant.cs:591
ushort[] ToUInt16Array()
Gets the value as ushort array.
Definition: Variant.cs:1251
Variant(int value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:222
Variant(ByteBuffer flatBuffers)
Initializes a new instance of the Variant class.
Definition: Variant.cs:556
static readonly Variant Zero
Gets a Variant with value '0' of data type 'int' (Int32).
Definition: Variant.cs:758
object Value
Gets the value.
Definition: Variant.cs:789
Variant(DateTime value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:250
DateTime ToDateTime()
Converts the value to a timestamp.
Definition: Variant.cs:1082
short[] ToInt16Array()
Gets the value as short array.
Definition: Variant.cs:1225
Variant()
Initializes a new instance of the Variant class.
Definition: Variant.cs:130
Variant(bool[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:349
double[] ToDoubleArray()
Gets the value as double array.
Definition: Variant.cs:1433
ByteBuffer ToFlatbuffers()
Gets the value as Flatbuffers.
Definition: Variant.cs:1538
uint ToUInt32()
Gets the value as uint.
Definition: Variant.cs:1029
Variant(DateTime[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:541
byte ToByte()
Gets the value as byte.
Definition: Variant.cs:957
ulong[] ToUInt64Array()
Gets the value as ulong array.
Definition: Variant.cs:1372
bool IsString
Gets a value that indicates whether the Variant contains a string value.
Definition: Variant.cs:867
byte[] ToByteArray()
Gets the value as byte array.
Definition: Variant.cs:1199
Variant(ulong value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:306
static readonly Variant One
Gets a Variant with value '1' of data type 'int' (Int32).
Definition: Variant.cs:763
Variant(ushort value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:278
Variant(sbyte value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:194
bool IsNull
Gets a value that indicates whether the Variant is null.
Definition: Variant.cs:861
Variant(short[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:394
void Dispose()
Disposes the instance.
Definition: Variant.cs:116
Variant(IVariant other)
Initializes a new instance of the Variant class.
Definition: Variant.cs:143
bool Equals(Variant other)
Returns a value that indicates if this Variant equals given Variant.
Definition: Variant.cs:623
Variant(byte[] value, bool raw=false)
Initializes a new instance of the Variant class.
Definition: Variant.cs:440
override int GetHashCode()
Gets the HashCode of this Variant.
Definition: Variant.cs:661
bool IsFlatbuffers
Gets a value that indicates whether the Variant contains Flatbuffers.
Definition: Variant.cs:879
Variant(long value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:236
byte[] ToRawByteArray()
Gets the value as raw byte array (UTF8).
Definition: Variant.cs:1569
DLR_VARIANT_TYPE DataType
Gets the data type.
Definition: Variant.cs:1496
DLR_RESULT result
Gets data of a complex Variant (flatbuffers) by query.
Definition: Variant.cs:1602
bool ToBool()
Gets the value as bool.
Definition: Variant.cs:921
Variant(bool value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:165
uint[] ToUInt32Array()
Gets the value as uint array.
Definition: Variant.cs:1311
virtual void Dispose(bool disposing)
Disposes the instance.
Definition: Variant.cs:70
Variant(byte value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:264
static readonly int DefaultFlatbuffersInitialSize
Gets the default Flatbuffers initial size in bytes.
Definition: Variant.cs:748
Variant(float value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:320
Variant(uint[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:480
static readonly Variant Null
Gets a Variant with no value of data type 'DLR_VARIANT_TYPE_UNKNOWN'.
Definition: Variant.cs:753
Variant(double value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:334
long ToInt64()
Gets the value as long.
Definition: Variant.cs:1047
Variant Clone()
Clones the instance.
Definition: Variant.cs:1637
Variant(double[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:525
override string ToString()
Gets the value as string.
Definition: Variant.cs:672
static bool operator!=(Variant l, Variant r)
s Unequality Operator.
Definition: Variant.cs:723
ulong ToUInt64()
Gets the value as ulong.
Definition: Variant.cs:1065
override bool Equals(object obj)
Returns a value that indicates if this Variant equals given object.
Definition: Variant.cs:612
string JsonDataType
Gets the Json data type.
Definition: Variant.cs:1521
Variant(string[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:364
bool IsDisposed
Gets a value that indicates whether the instance is disposed.
Definition: Variant.cs:64
Variant(short value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:208
Variant(ushort[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:465
bool IsBool
Gets a value that indicates whether the Variant contains a boolean value.
Definition: Variant.cs:873
static readonly Variant True
Gets a Variant with boolean value 'true'.
Definition: Variant.cs:773
Variant(float[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:510
DLR_RESULT CheckConvert(DLR_VARIANT_TYPE type)
Checks if the Variant is convertable to given data type.
Definition: Variant.cs:1667
static bool operator==(Variant l, Variant r)
Equality Operator.
Definition: Variant.cs:699
ushort ToUInt16()
Gets the value as ushort.
Definition: Variant.cs:993
Variant(uint value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:292
float ToFloat()
Gets the value as float.
Definition: Variant.cs:1093
Variant(ulong[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:495
static readonly Variant False
Gets a Variant with boolean value 'false'.
Definition: Variant.cs:778
int ToInt32()
Gets the value as int.
Definition: Variant.cs:1011
static readonly Variant Empty
Gets a Variant with empty string value.
Definition: Variant.cs:768
bool IsNumber
Gets a value that indicates whether the Variant contains a numeric value. Returns false for numeric a...
Definition: Variant.cs:904
Variant(long[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:424
Variant(FlatBufferBuilder builder)
Initializes a new instance of the Variant class.
Definition: Variant.cs:571
int[] ToInt32Array()
Gets the value as int array.
Definition: Variant.cs:1285
bool IsArray
Gets a value that indicates whether the Variant is an array.
Definition: Variant.cs:886
Variant(int[] value)
Initializes a new instance of the Variant class.
Definition: Variant.cs:409
DateTime[] ToDateTimeArray()
Gets the value as DateTime array.
Definition: Variant.cs:1485
bool[] ToBoolArray()
Gets the value as bool array.
Definition: Variant.cs:1129
The IVariant interface.
Definition: IVariant.cs:10
DLR_RESULT
The result.
Definition: Enums.cs:153
DLR_VARIANT_TYPE
DLR_VARIANT_TYPE.
Definition: Enums.cs:409