ctrlX Data Layer .NET API  4.3.0
Loading...
Searching...
No Matches
Variant.cs
1
2
3using Datalayer.Internal;
4using Google.FlatBuffers;
5using System;
6using System.Collections;
7using System.Diagnostics;
8using System.Linq;
9using System.Runtime.InteropServices;
10
11namespace Datalayer
12{
16 [DebuggerDisplay("{Value}")]
17 public class Variant : IVariant, INative
18 {
19 // Fields
20 private readonly bool _skipDelete;
21 private unsafe void* _nativePtr;
22
23 #region Internal Constructors
24
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 Constructors
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
585 #endregion
586
587 #region Public Overrides
588
594 public override bool Equals(object obj)
595 {
596 return Equals(obj as Variant);
597 }
598
605 public bool Equals(Variant other)
606 {
607 if (other is null)
608 {
609 return false;
610 }
611
612 if (ReferenceEquals(this, other))
613 {
614 return true;
615 }
616
617 var dataType = DataType;
618 if (dataType != other.DataType)
619 {
620 return false;
621 }
622
623 //Arrays
624 if (Utils.IsArray(dataType))
625 {
626 return StructuralComparisons.StructuralEqualityComparer.Equals(Value, other.Value);
627 }
628
629 //Flatbuffers
630 if (dataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLATBUFFERS)
631 {
632 return StructuralComparisons.StructuralEqualityComparer.Equals(ToFlatbuffers().ToSizedArray(), other.ToFlatbuffers().ToSizedArray());
633 }
634
635 //Scalars
636 return Equals(Value, other.Value);
637 }
638
643 public override int GetHashCode()
644 {
645 var v = Value;
646 return v != null ? base.GetHashCode() ^ v.GetHashCode() : base.GetHashCode();
647 }
648
654 public override string ToString()
655 {
656 if (IsNull)
657 {
658 return string.Empty;
659 }
660
661 unsafe
662 {
663 var length = Convert.ToInt32(GetSize().ToUInt32()) - 1;
664 if (length <= 0)
665 {
666 return string.Empty;
667 }
668
669 var stringBuffer =
670 StringBuffer.FromNativePtr(NativeMethods.Datalayer.DLR_variantGetSTRING(_nativePtr), length);
671 return stringBuffer.ToString();
672 }
673 }
674
681 public static bool operator ==(Variant l, Variant r)
682 {
683 //x not null
684 if (l is Variant)
685 {
686 return l.Equals(r);
687 }
688
689 //y not null
690 if (r is Variant)
691 {
692 return r.Equals(l);
693 }
694
695 //Both null
696 return true;
697 }
698
705 public static bool operator !=(Variant l, Variant r)
706 {
707 //x not null
708 if (l is Variant)
709 {
710 return !l.Equals(r);
711 }
712
713 //y not null
714 if (r is Variant)
715 {
716 return !r.Equals(l);
717 }
718
719 //Both null
720 return false;
721 }
722
723 #endregion
724
725 #region Public Statics
726
730 public static readonly int DefaultFlatbuffersInitialSize = 1024;
731
735 public static readonly Variant Null = new Variant();
736
740 public static readonly Variant Zero = new Variant(0);
741
745 public static readonly Variant One = new Variant(1);
746
750 public static readonly Variant Empty = new Variant(string.Empty);
751
755 public static readonly Variant True = new Variant(true);
756
760 public static readonly Variant False = new Variant(false);
761
762 #endregion
763
764 #region Public Getters
765
770 public object Value
771 {
772 get
773 {
774 switch (DataType)
775 {
776 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_BOOL8:
777 return ToBool();
778 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT8:
779 return ToSByte();
780 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT8:
781 return ToByte();
782 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT16:
783 return ToInt16();
784 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT16:
785 return ToUInt16();
786 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT32:
787 return ToInt32();
788 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT32:
789 return ToUInt32();
790 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_INT64:
791 return ToInt64();
792 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UINT64:
793 return ToUInt64();
794 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLOAT32:
795 return ToFloat();
796 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLOAT64:
797 return ToDouble();
798 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_STRING:
799 return ToString();
800 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_TIMESTAMP:
801 return ToDateTime();
802 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_BOOL8:
803 return ToBoolArray();
804 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT8:
805 return ToSByteArray();
806 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT8:
807 return ToByteArray();
808 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT16:
809 return ToInt16Array();
810 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT16:
811 return ToUInt16Array();
812 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT32:
813 return ToInt32Array();
814 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT32:
815 return ToUInt32Array();
816 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_INT64:
817 return ToInt64Array();
818 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_UINT64:
819 return ToUInt64Array();
820 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_FLOAT32:
821 return ToFloatArray();
822 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_FLOAT64:
823 return ToDoubleArray();
824 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_STRING:
825 return ToStringArray();
826 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_ARRAY_OF_TIMESTAMP:
827 return ToDateTimeArray();
828 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_RAW:
829 return ToRawByteArray();
830 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLATBUFFERS:
831 return ToFlatbuffers();
832 case DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UNKNOWN:
833 default:
834 return null;
835 }
836 }
837 }
838
843 public bool IsNull => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UNKNOWN;
844
849 public bool IsString => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_STRING;
850
855 public bool IsBool => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_BOOL8;
856
861 public bool IsFlatbuffers => DataType == DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_FLATBUFFERS;
862
867 public bool IsArray
868 {
869 get
870 {
871 if (IsDisposed)
872 {
873 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
874 }
875
876 return Utils.IsArray(DataType);
877 }
878 }
879
885 public bool IsNumber
886 {
887 get
888 {
889 if (IsDisposed)
890 {
891 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
892 }
893
894 return Utils.IsNumber(DataType);
895 }
896 }
897
903 public bool ToBool()
904 {
905 if (IsNull)
906 {
907 return false;
908 }
909
910 unsafe
911 {
912 return NativeMethods.Datalayer.DLR_variantGetBOOL8(_nativePtr);
913 }
914 }
915
921 public sbyte ToSByte()
922 {
923 if (IsNull)
924 {
925 return 0;
926 }
927
928 unsafe
929 {
930 return NativeMethods.Datalayer.DLR_variantGetINT8(_nativePtr);
931 }
932 }
933
939 public byte ToByte()
940 {
941 if (IsNull)
942 {
943 return 0;
944 }
945
946 unsafe
947 {
948 return NativeMethods.Datalayer.DLR_variantGetUINT8(_nativePtr);
949 }
950 }
951
957 public short ToInt16()
958 {
959 if (IsNull)
960 {
961 return 0;
962 }
963
964 unsafe
965 {
966 return NativeMethods.Datalayer.DLR_variantGetINT16(_nativePtr);
967 }
968 }
969
975 public ushort ToUInt16()
976 {
977 if (IsNull)
978 {
979 return 0;
980 }
981
982 unsafe
983 {
984 return NativeMethods.Datalayer.DLR_variantGetUINT16(_nativePtr);
985 }
986 }
987
993 public int ToInt32()
994 {
995 if (IsNull)
996 {
997 return 0;
998 }
999
1000 unsafe
1001 {
1002 return NativeMethods.Datalayer.DLR_variantGetINT32(_nativePtr);
1003 }
1004 }
1005
1011 public uint ToUInt32()
1012 {
1013 if (IsNull)
1014 {
1015 return 0;
1016 }
1017
1018 unsafe
1019 {
1020 return NativeMethods.Datalayer.DLR_variantGetUINT32(_nativePtr);
1021 }
1022 }
1023
1029 public long ToInt64()
1030 {
1031 if (IsNull)
1032 {
1033 return 0;
1034 }
1035
1036 unsafe
1037 {
1038 return NativeMethods.Datalayer.DLR_variantGetINT64(_nativePtr);
1039 }
1040 }
1041
1047 public ulong ToUInt64()
1048 {
1049 if (IsNull)
1050 {
1051 return 0;
1052 }
1053
1054 unsafe
1055 {
1056 return NativeMethods.Datalayer.DLR_variantGetUINT64(_nativePtr);
1057 }
1058 }
1059
1064 public DateTime ToDateTime()
1065 {
1066 //uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC) -> long -> DateTime
1067 return DateTime.FromFileTimeUtc(Convert.ToInt64(ToUInt64()));
1068 }
1069
1075 public float ToFloat()
1076 {
1077 if (IsNull)
1078 {
1079 return 0;
1080 }
1081
1082 unsafe
1083 {
1084 return NativeMethods.Datalayer.DLR_variantGetFLOAT32(_nativePtr);
1085 }
1086 }
1087
1093 public double ToDouble()
1094 {
1095 if (IsNull)
1096 {
1097 return 0;
1098 }
1099
1100 unsafe
1101 {
1102 return NativeMethods.Datalayer.DLR_variantGetFLOAT64(_nativePtr);
1103 }
1104 }
1105
1111 public bool[] ToBoolArray()
1112 {
1113 if (IsNull)
1114 {
1115 return null;
1116 }
1117
1118 unsafe
1119 {
1120 bool* p = NativeMethods.Datalayer.DLR_variantGetArrayOfBOOL8(_nativePtr);
1121 if (p == null)
1122 {
1123 return Array.Empty<bool>();
1124 }
1125
1126 // memcopy not available: we have to iterate
1127
1128 //var array = new bool[GetCount().ToUInt32()];
1129 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1130
1131 var count = GetCount().ToUInt32();
1132 var array = new bool[count];
1133 for (var i = 0; i < count; i++)
1134 {
1135 array[i] = p[i];
1136 }
1137 return array;
1138 }
1139 }
1140
1146 public sbyte[] ToSByteArray()
1147 {
1148 if (IsNull)
1149 {
1150 return null;
1151 }
1152
1153 unsafe
1154 {
1155 sbyte* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT8(_nativePtr);
1156 if (p == null)
1157 {
1158 return Array.Empty<sbyte>();
1159 }
1160
1161 // memcopy not available: we have to iterate
1162
1163 //var array = new sbyte[GetCount().ToUInt32()];
1164 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1165
1166 var count = GetCount().ToUInt32();
1167 var array = new sbyte[count];
1168 for (var i = 0; i < count; i++)
1169 {
1170 array[i] = p[i];
1171 }
1172 return array;
1173 }
1174 }
1175
1181 public byte[] ToByteArray()
1182 {
1183 if (IsNull)
1184 {
1185 return null;
1186 }
1187
1188 unsafe
1189 {
1190 byte* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT8(_nativePtr);
1191 if (p == null)
1192 {
1193 return Array.Empty<byte>();
1194 }
1195
1196 var array = new byte[GetCount().ToUInt32()];
1197 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1198 return array;
1199 }
1200 }
1201
1207 public short[] ToInt16Array()
1208 {
1209 if (IsNull)
1210 {
1211 return null;
1212 }
1213
1214 unsafe
1215 {
1216 short* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT16(_nativePtr);
1217 if (p == null)
1218 {
1219 return Array.Empty<short>();
1220 }
1221
1222 var array = new short[GetCount().ToUInt32()];
1223 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1224 return array;
1225 }
1226 }
1227
1233 public ushort[] ToUInt16Array()
1234 {
1235 if (IsNull)
1236 {
1237 return null;
1238 }
1239
1240 unsafe
1241 {
1242 ushort* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT16(_nativePtr);
1243 if (p == null)
1244 {
1245 return Array.Empty<ushort>();
1246 }
1247 // memcopy not available: we have to iterate
1248
1249 //var array = new ushort[GetCount().ToUInt32()];
1250 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1251
1252 var count = GetCount().ToUInt32();
1253 var array = new ushort[count];
1254 for (var i = 0; i < count; i++)
1255 {
1256 array[i] = p[i];
1257 }
1258 return array;
1259 }
1260 }
1261
1267 public int[] ToInt32Array()
1268 {
1269 if (IsNull)
1270 {
1271 return null;
1272 }
1273
1274 unsafe
1275 {
1276 int* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT32(_nativePtr);
1277 if (p == null)
1278 {
1279 return Array.Empty<int>();
1280 }
1281
1282 var array = new int[GetCount().ToUInt32()];
1283 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1284 return array;
1285 }
1286 }
1287
1293 public uint[] ToUInt32Array()
1294 {
1295 if (IsNull)
1296 {
1297 return null;
1298 }
1299
1300 unsafe
1301 {
1302 uint* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT32(_nativePtr);
1303 if (p == null)
1304 {
1305 return Array.Empty<uint>();
1306 }
1307
1308 // memcopy not available: we have to iterate
1309
1310 //var array = new uint[GetCount().ToUInt32()];
1311 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1312
1313 var count = GetCount().ToUInt32();
1314 var array = new uint[count];
1315 for (var i = 0; i < count; i++)
1316 {
1317 array[i] = p[i];
1318 }
1319 return array;
1320 }
1321 }
1322
1328 public long[] ToInt64Array()
1329 {
1330 if (IsNull)
1331 {
1332 return null;
1333 }
1334
1335 unsafe
1336 {
1337 long* p = NativeMethods.Datalayer.DLR_variantGetArrayOfINT64(_nativePtr);
1338 if (p == null)
1339 {
1340 return Array.Empty<long>();
1341 }
1342
1343 var array = new long[GetCount().ToUInt32()];
1344 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1345 return array;
1346 }
1347 }
1348
1354 public ulong[] ToUInt64Array()
1355 {
1356 if (IsNull)
1357 {
1358 return null;
1359 }
1360
1361 unsafe
1362 {
1363 ulong* p = NativeMethods.Datalayer.DLR_variantGetArrayOfUINT64(_nativePtr);
1364 if (p == null)
1365 {
1366 return Array.Empty<ulong>();
1367 }
1368
1369 // memcopy not available: we have to iterate
1370
1371 //var array = new ulong[GetCount().ToUInt32()];
1372 //Marshal.Copy((IntPtr)p, array, 0, array.Length);
1373
1374 var count = GetCount().ToUInt32();
1375 var array = new ulong[count];
1376 for (var i = 0; i < count; i++)
1377 {
1378 array[i] = p[i];
1379 }
1380 return array;
1381 }
1382 }
1383
1389 public float[] ToFloatArray()
1390 {
1391 if (IsNull)
1392 {
1393 return null;
1394 }
1395
1396 unsafe
1397 {
1398 float* p = NativeMethods.Datalayer.DLR_variantGetArrayOfFLOAT32(_nativePtr);
1399 if (p == null)
1400 {
1401 return Array.Empty<float>();
1402 }
1403
1404 var array = new float[GetCount().ToUInt32()];
1405 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1406 return array;
1407 }
1408 }
1409
1415 public double[] ToDoubleArray()
1416 {
1417 if (IsNull)
1418 {
1419 return null;
1420 }
1421
1422 unsafe
1423 {
1424 double* p = NativeMethods.Datalayer.DLR_variantGetArrayOfFLOAT64(_nativePtr);
1425 if (p == null)
1426 {
1427 return Array.Empty<double>();
1428 }
1429
1430 var array = new double[GetCount().ToUInt32()];
1431 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1432 return array;
1433 }
1434 }
1435
1441 public string[] ToStringArray()
1442 {
1443 if (IsNull)
1444 {
1445 return null;
1446 }
1447
1448 unsafe
1449 {
1450 sbyte** p = NativeMethods.Datalayer.DLR_variantGetArrayOfSTRING(_nativePtr);
1451 if (p == null)
1452 {
1453 return Array.Empty<string>();
1454 }
1455
1456 var count = GetCount().ToUInt32();
1457 var stringBufferArray = StringBufferArray.FromNativePtr(p, count);
1458 return stringBufferArray.ToStringArray();
1459 }
1460 }
1461
1467 public DateTime[] ToDateTimeArray()
1468 {
1469 //uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC) -> long -> DateTime
1470 return ToUInt64Array()?.Select(v => DateTime.FromFileTimeUtc(Convert.ToInt64(v))).ToArray();
1471 }
1472
1478 {
1479 get
1480 {
1481 if (IsDisposed)
1482 {
1483 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1484 }
1485
1486 if (IsNullPtr)
1487 {
1488 return DLR_VARIANT_TYPE.DLR_VARIANT_TYPE_UNKNOWN;
1489 }
1490
1491 unsafe
1492 {
1493 return NativeMethods.Datalayer.DLR_variantGetType(_nativePtr);
1494 }
1495 }
1496 }
1497
1502 public string JsonDataType
1503 {
1504 get
1505 {
1506 if (IsDisposed)
1507 {
1508 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1509 }
1510
1511 return Utils.ToJsonDataType(DataType);
1512 }
1513 }
1514
1520 public ByteBuffer ToFlatbuffers()
1521 {
1522 if (IsNull)
1523 {
1524 return null;
1525 }
1526
1527 if (!IsFlatbuffers)
1528 {
1529 return null;
1530 }
1531
1532 unsafe
1533 {
1534 byte* p = NativeMethods.Datalayer.DLR_variantGetData(_nativePtr);
1535 if (p == null)
1536 {
1537 return null;
1538 }
1539
1540 var array = new byte[GetCount().ToUInt32()];
1541 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1542 return new ByteBuffer(array);
1543 }
1544 }
1545
1551 public byte[] ToRawByteArray()
1552 {
1553 if (IsNull)
1554 {
1555 return null;
1556 }
1557
1558 unsafe
1559 {
1560 byte* p = NativeMethods.Datalayer.DLR_variantGetData(_nativePtr);
1561 if (p == null)
1562 {
1563 return Array.Empty<byte>();
1564 }
1565
1566 var array = new byte[GetCount().ToUInt32()];
1567 Marshal.Copy((IntPtr)p, array, 0, array.Length);
1568 return array;
1569 }
1570 }
1571
1572 #endregion
1573
1574 #region Public Methods
1575
1584 public (DLR_RESULT result, IVariant value) GetDataFromFlatbuffers(IVariant typeFlatbuffers, string query)
1585 {
1586 if (IsDisposed)
1587 {
1588 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1589 }
1590
1591 if (typeFlatbuffers == null)
1592 {
1593 throw new ArgumentNullException(nameof(typeFlatbuffers));
1594 }
1595
1596 if (query == null)
1597 {
1598 throw new ArgumentNullException(nameof(query));
1599 }
1600
1601 if (IsNull)
1602 {
1603 return (DLR_RESULT.DL_INVALID_VALUE, Null);
1604 }
1605
1606 var dataValue = new Variant();
1607 var queryBuffer = StringBuffer.FromString(query);
1608
1609 unsafe
1610 {
1611 return (NativeMethods.Datalayer.DLR_getDataFromFlatbuffers(
1612 this.ToNativePtr(),
1613 typeFlatbuffers.ToNativePtr(),
1614 queryBuffer.ToNativePtr(),
1615 dataValue.ToNativePtr()), dataValue);
1616 }
1617 }
1618
1625 {
1626 if (IsDisposed)
1627 {
1628 throw new ObjectDisposedException(Utils.Strings.ErrorObjectDisposed);
1629 }
1630
1631 if (IsNullPtr)
1632 {
1633 return new Variant();
1634 }
1635
1636 unsafe
1637 {
1638 var clone = new Variant();
1639 if (NativeMethods.Datalayer.DLR_variantCopy(clone.ToNativePtr(), this.ToNativePtr()).IsBad())
1640 {
1641 throw new InvalidOperationException(Utils.Strings.ErrorObjectNotCloneable);
1642 }
1643
1644 return clone;
1645 }
1646 }
1647
1655 {
1656 if (IsNull)
1657 {
1658 return DLR_RESULT.DL_TYPE_MISMATCH;
1659 }
1660
1661 unsafe
1662 {
1663 return NativeMethods.Datalayer.DLR_variantCheckConvert(_nativePtr, type);
1664 }
1665 }
1666
1667 #endregion
1668
1669 #region Public Implicit Operators
1670
1675 public static implicit operator Variant(bool source)
1676 {
1677 return new Variant(source);
1678 }
1679
1684 public static implicit operator Variant(bool[] source)
1685 {
1686 return new Variant(source);
1687 }
1688
1693 public static implicit operator Variant(sbyte source)
1694 {
1695 return new Variant(source);
1696 }
1697
1701 public static implicit operator Variant(sbyte[] source)
1702 {
1703 return new Variant(source);
1704 }
1705
1710 public static implicit operator Variant(byte source)
1711 {
1712 return new Variant(source);
1713 }
1714
1718 public static implicit operator Variant(byte[] source)
1719 {
1720 return new Variant(source);
1721 }
1722
1727 public static implicit operator Variant(short source)
1728 {
1729 return new Variant(source);
1730 }
1731
1735 public static implicit operator Variant(short[] source)
1736 {
1737 return new Variant(source);
1738 }
1743 public static implicit operator Variant(ushort source)
1744 {
1745 return new Variant(source);
1746 }
1747
1751 public static implicit operator Variant(ushort[] source)
1752 {
1753 return new Variant(source);
1754 }
1755
1760 public static implicit operator Variant(int source)
1761 {
1762 return new Variant(source);
1763 }
1764
1769 public static implicit operator Variant(int[] source)
1770 {
1771 return new Variant(source);
1772 }
1773
1778 public static implicit operator Variant(uint source)
1779 {
1780 return new Variant(source);
1781 }
1782
1787 public static implicit operator Variant(uint[] source)
1788 {
1789 return new Variant(source);
1790 }
1791
1796 public static implicit operator Variant(long source)
1797 {
1798 return new Variant(source);
1799 }
1800
1805 public static implicit operator Variant(long[] source)
1806 {
1807 return new Variant(source);
1808 }
1809
1814 public static implicit operator Variant(ulong source)
1815 {
1816 return new Variant(source);
1817 }
1818
1822 public static implicit operator Variant(ulong[] source)
1823 {
1824 return new Variant(source);
1825 }
1826
1831 public static implicit operator Variant(float source)
1832 {
1833 return new Variant(source);
1834 }
1835
1839 public static implicit operator Variant(float[] source)
1840 {
1841 return new Variant(source);
1842 }
1843
1848 public static implicit operator Variant(double source)
1849 {
1850 return new Variant(source);
1851 }
1852
1856 public static implicit operator Variant(double[] source)
1857 {
1858 return new Variant(source);
1859 }
1860
1865 public static implicit operator Variant(string source)
1866 {
1867 return new Variant(source);
1868 }
1869
1874 public static implicit operator Variant(string[] source)
1875 {
1876 return new Variant(source);
1877 }
1878
1883 public static implicit operator Variant(DateTime source)
1884 {
1885 return new Variant(source);
1886 }
1887
1892 public static implicit operator Variant(DateTime[] source)
1893 {
1894 return new Variant(source);
1895 }
1896
1901 public static implicit operator Variant(FlatBufferBuilder source)
1902 {
1903 return new Variant(source);
1904 }
1905
1910 public static implicit operator Variant(ByteBuffer source)
1911 {
1912 return new Variant(source);
1913 }
1914
1915 #endregion
1916
1917 #region Private Setter
1918
1924 private DLR_RESULT SetBool(bool value)
1925 {
1926 unsafe
1927 {
1928 return NativeMethods.Datalayer.DLR_variantSetBOOL8(_nativePtr, Convert.ToByte(value));
1929 }
1930 }
1931
1937 private DLR_RESULT SetInt8(sbyte value)
1938 {
1939 unsafe
1940 {
1941 return NativeMethods.Datalayer.DLR_variantSetINT8(_nativePtr, value);
1942 }
1943 }
1944
1950 private DLR_RESULT SetUInt8(byte value)
1951 {
1952 unsafe
1953 {
1954 return NativeMethods.Datalayer.DLR_variantSetUINT8(_nativePtr, value);
1955 }
1956 }
1957
1963 private DLR_RESULT SetInt16(short value)
1964 {
1965 unsafe
1966 {
1967 return NativeMethods.Datalayer.DLR_variantSetINT16(_nativePtr, value);
1968 }
1969 }
1970
1976 private DLR_RESULT SetUInt16(ushort value)
1977 {
1978 unsafe
1979 {
1980 return NativeMethods.Datalayer.DLR_variantSetUINT16(_nativePtr, value);
1981 }
1982 }
1983
1989 private DLR_RESULT SetInt32(int value)
1990 {
1991 unsafe
1992 {
1993 return NativeMethods.Datalayer.DLR_variantSetINT32(_nativePtr, value);
1994 }
1995 }
1996
2002 private DLR_RESULT SetUInt32(uint value)
2003 {
2004 unsafe
2005 {
2006 return NativeMethods.Datalayer.DLR_variantSetUINT32(_nativePtr, value);
2007 }
2008 }
2009
2015 private DLR_RESULT SetInt64(long value)
2016 {
2017 unsafe
2018 {
2019 return NativeMethods.Datalayer.DLR_variantSetINT64(_nativePtr, value);
2020 }
2021 }
2022
2028 private DLR_RESULT SetUInt64(ulong value)
2029 {
2030 unsafe
2031 {
2032 return NativeMethods.Datalayer.DLR_variantSetUINT64(_nativePtr, value);
2033 }
2034 }
2035
2041 private DLR_RESULT SetFloat32(float value)
2042 {
2043 unsafe
2044 {
2045 return NativeMethods.Datalayer.DLR_variantSetFLOAT32(_nativePtr, value);
2046 }
2047 }
2048
2054 private DLR_RESULT SetFloat64(double value)
2055 {
2056 unsafe
2057 {
2058 return NativeMethods.Datalayer.DLR_variantSetFLOAT64(_nativePtr, value);
2059 }
2060 }
2061
2068 private DLR_RESULT SetString(string value)
2069 {
2070 if (value == null)
2071 {
2072 throw new ArgumentNullException(nameof(value));
2073 }
2074
2075 var valueBuffer = StringBuffer.FromString(value);
2076 unsafe
2077 {
2078 return NativeMethods.Datalayer.DLR_variantSetSTRING(_nativePtr, valueBuffer.ToNativePtr());
2079 }
2080 }
2081
2087 private DLR_RESULT SetTimestamp(DateTime value)
2088 {
2089 unsafe
2090 {
2091 try
2092 {
2093 //DateTime -> FileTimeUtc -> ulong -> uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC)
2094 return NativeMethods.Datalayer.DLR_variantSetTimestamp(_nativePtr, Convert.ToUInt64(value.ToFileTimeUtc()));
2095 }
2096 catch (ArgumentOutOfRangeException)
2097 {
2098 // The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
2099 return DLR_RESULT.DL_FAILED;
2100 }
2101 }
2102 }
2103
2110 private DLR_RESULT SetArrayOfBool(bool[] value)
2111 {
2112 if (value == null)
2113 {
2114 throw new ArgumentNullException(nameof(value));
2115 }
2116
2117 unsafe
2118 {
2119 fixed (bool* p = value)
2120 {
2121 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_BOOL8(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2122 }
2123 }
2124 }
2125
2132 private DLR_RESULT SetArrayOfInt8(sbyte[] value)
2133 {
2134 if (value == null)
2135 {
2136 throw new ArgumentNullException(nameof(value));
2137 }
2138
2139 unsafe
2140 {
2141 fixed (sbyte* p = value)
2142 {
2143 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT8(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2144 }
2145 }
2146 }
2147
2154 private DLR_RESULT SetArrayOfUInt8(byte[] value)
2155 {
2156 if (value == null)
2157 {
2158 throw new ArgumentNullException(nameof(value));
2159 }
2160
2161 unsafe
2162 {
2163 fixed (byte* p = value)
2164 {
2165 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT8(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2166 }
2167 }
2168 }
2169
2176 private DLR_RESULT SetArrayOfInt16(short[] value)
2177 {
2178 if (value == null)
2179 {
2180 throw new ArgumentNullException(nameof(value));
2181 }
2182
2183 unsafe
2184 {
2185 fixed (short* p = value)
2186 {
2187 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT16(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2188 }
2189 }
2190 }
2191
2198 private DLR_RESULT SetArrayOfUInt16(ushort[] value)
2199 {
2200 if (value == null)
2201 {
2202 throw new ArgumentNullException(nameof(value));
2203 }
2204
2205 unsafe
2206 {
2207 fixed (ushort* p = value)
2208 {
2209 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT16(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2210 }
2211 }
2212 }
2213
2220 private DLR_RESULT SetArrayOfInt32(int[] value)
2221 {
2222 if (value == null)
2223 {
2224 throw new ArgumentNullException(nameof(value));
2225 }
2226
2227 unsafe
2228 {
2229 fixed (int* p = value)
2230 {
2231 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT32(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2232 }
2233 }
2234 }
2235
2242 private DLR_RESULT SetArrayOfUInt32(uint[] value)
2243 {
2244 if (value == null)
2245 {
2246 throw new ArgumentNullException(nameof(value));
2247 }
2248
2249 unsafe
2250 {
2251 fixed (uint* p = value)
2252 {
2253 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT32(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2254 }
2255 }
2256 }
2257
2264 private DLR_RESULT SetArrayOfInt64(long[] value)
2265 {
2266 if (value == null)
2267 {
2268 throw new ArgumentNullException(nameof(value));
2269 }
2270
2271 unsafe
2272 {
2273 fixed (long* p = value)
2274 {
2275 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_INT64(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2276 }
2277 }
2278 }
2279
2286 private DLR_RESULT SetArrayOfUInt64(ulong[] value)
2287 {
2288 if (value == null)
2289 {
2290 throw new ArgumentNullException(nameof(value));
2291 }
2292
2293 unsafe
2294 {
2295 fixed (ulong* p = value)
2296 {
2297 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_UINT64(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2298 }
2299 }
2300 }
2301
2308 private DLR_RESULT SetArrayOfFloat32(float[] value)
2309 {
2310 if (value == null)
2311 {
2312 throw new ArgumentNullException(nameof(value));
2313 }
2314
2315 unsafe
2316 {
2317 fixed (float* p = value)
2318 {
2319 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_FLOAT32(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2320 }
2321 }
2322 }
2323
2330 private DLR_RESULT SetArrayOfFloat64(double[] value)
2331 {
2332 if (value == null)
2333 {
2334 throw new ArgumentNullException(nameof(value));
2335 }
2336
2337 unsafe
2338 {
2339 fixed (double* p = value)
2340 {
2341 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_FLOAT64(_nativePtr, p, new UIntPtr(Convert.ToUInt32(value.Length)));
2342 }
2343 }
2344 }
2345
2352 private DLR_RESULT SetArrayOfTimestamp(DateTime[] value)
2353 {
2354 if (value == null)
2355 {
2356 throw new ArgumentNullException(nameof(value));
2357 }
2358
2359 unsafe
2360 {
2361 try
2362 {
2363 //DateTime -> FileTimeUtc -> ulong -> uint64 (FILETIME) 64 bit 100ns since 1.1.1601 (UTC)
2364 var timeStamps = value.Select(v => Convert.ToUInt64(v.ToFileTimeUtc())).ToArray();
2365
2366 fixed (ulong* p = timeStamps)
2367 {
2368 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_TIMESTAMP(_nativePtr, p, new UIntPtr(Convert.ToUInt32(timeStamps.Length)));
2369 }
2370 }
2371 catch (ArgumentOutOfRangeException)
2372 {
2373 // The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC.
2374 return DLR_RESULT.DL_FAILED;
2375 }
2376 }
2377 }
2378
2385 private DLR_RESULT SetArrayOfString(string[] value)
2386 {
2387 if (value == null)
2388 {
2389 throw new ArgumentNullException(nameof(value));
2390 }
2391
2392
2393 var stringBufferArray = StringBufferArray.FromStringArray(value);
2394 unsafe
2395 {
2396 return NativeMethods.Datalayer.DLR_variantSetARRAY_OF_STRING(_nativePtr, stringBufferArray.ToNativePtr(), new UIntPtr(Convert.ToUInt32(value.Length)));
2397 }
2398 }
2399
2406 private DLR_RESULT SetFlatbuffers(ByteBuffer value)
2407 {
2408 if (value == null)
2409 {
2410 throw new ArgumentNullException(nameof(value));
2411 }
2412
2413 // 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[]).
2414
2415 //OPTION A: SLOW: Convert byte[] to sbyte[] bytewise
2416 //var sbyteArray = Array.ConvertAll(value.ToSizedArray(), b => unchecked((sbyte)b));
2417 //unsafe
2418 //{
2419 // fixed (sbyte* p = sbyteArray)
2420 // {
2421 // return NativeMethods.Datalayer.DLR_variantSetFlatbuffers(_nativePtr, p, new UIntPtr(Convert.ToUInt32(sbyteArray.Length)));
2422 // }
2423 //}
2424
2425 //OPTION B: FASTER: Use BlockCopy to convert byte[] to sbyte[]
2426 //var buffer = value.ToSizedArray();
2427 //sbyte[] sbyteArray = new sbyte[buffer.Length];
2428 //Buffer.BlockCopy(buffer, 0, sbyteArray, 0, buffer.Length);
2429 //unsafe
2430 //{
2431 // fixed (sbyte* p = sbyteArray)
2432 // {
2433 // return NativeMethods.Datalayer.DLR_variantSetFlatbuffers(_nativePtr, p, new UIntPtr(Convert.ToUInt32(sbyteArray.Length)));
2434 // }
2435 //}
2436
2437 //OPTION C: FASTEST: Convert byte* to sbyte*, pointing to original memory (no copy)
2438 var byteArray = value.ToSizedArray();
2439 unsafe
2440 {
2441 fixed (byte* p = byteArray)
2442 {
2443 sbyte* psByte = (sbyte*)p;
2444 return NativeMethods.Datalayer.DLR_variantSetFlatbuffers(_nativePtr, psByte, new UIntPtr(Convert.ToUInt32(byteArray.Length)));
2445 }
2446 }
2447 }
2448
2455 private DLR_RESULT SetArrayOfRawBytes(byte[] value)
2456 {
2457 if (value == null)
2458 {
2459 throw new ArgumentNullException(nameof(value));
2460 }
2461
2462 unsafe
2463 {
2464 fixed (byte* p = value)
2465 {
2466 sbyte* psByte = (sbyte*)p;
2467 return NativeMethods.Datalayer.DLR_variantSetRaw(_nativePtr, psByte, new UIntPtr(Convert.ToUInt32(value.Length)));
2468 }
2469 }
2470 }
2471
2472 #endregion
2473
2474 #region Private Methods
2475
2480 internal UIntPtr GetSize()
2481 {
2482 if (IsNull)
2483 {
2484 return UIntPtr.Zero;
2485 }
2486
2487 unsafe
2488 {
2489 return NativeMethods.Datalayer.DLR_variantGetSize(_nativePtr);
2490 }
2491 }
2492
2497 internal UIntPtr GetCount()
2498 {
2499 if (IsNull)
2500 {
2501 return UIntPtr.Zero;
2502 }
2503
2504 unsafe
2505 {
2506 return NativeMethods.Datalayer.DLR_variantGetCount(_nativePtr);
2507 }
2508 }
2509 #endregion
2510 }
2511}
Provides the implementation for IVariant.
Definition: Variant.cs:18
string[] ToStringArray()
Gets the value as string array.
Definition: Variant.cs:1441
short ToInt16()
Gets the value as short.
Definition: Variant.cs:957
long[] ToInt64Array()
Gets the value as long array.
Definition: Variant.cs:1328
sbyte ToSByte()
Gets the value as sbyte.
Definition: Variant.cs:921
float[] ToFloatArray()
Gets the value as float array.
Definition: Variant.cs:1389
double ToDouble()
Gets the value as double.
Definition: Variant.cs:1093
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:1146
ushort[] ToUInt16Array()
Gets the value as ushort array.
Definition: Variant.cs:1233
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:740
object Value
Gets the value.
Definition: Variant.cs:771
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:1064
short[] ToInt16Array()
Gets the value as short array.
Definition: Variant.cs:1207
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:1415
ByteBuffer ToFlatbuffers()
Gets the value as Flatbuffers.
Definition: Variant.cs:1520
uint ToUInt32()
Gets the value as uint.
Definition: Variant.cs:1011
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:939
ulong[] ToUInt64Array()
Gets the value as ulong array.
Definition: Variant.cs:1354
bool IsString
Gets a value that indicates whether the Variant contains a string value.
Definition: Variant.cs:849
byte[] ToByteArray()
Gets the value as byte array.
Definition: Variant.cs:1181
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:745
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:843
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:605
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:643
bool IsFlatbuffers
Gets a value that indicates whether the Variant contains Flatbuffers.
Definition: Variant.cs:861
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:1551
DLR_VARIANT_TYPE DataType
Gets the data type.
Definition: Variant.cs:1478
DLR_RESULT result
Gets data of a complex Variant (flatbuffers) by query.
Definition: Variant.cs:1584
bool ToBool()
Gets the value as bool.
Definition: Variant.cs:903
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:1293
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:730
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:735
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:1029
Variant Clone()
Clones the instance.
Definition: Variant.cs:1624
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:654
static bool operator!=(Variant l, Variant r)
s Unequality Operator.
Definition: Variant.cs:705
ulong ToUInt64()
Gets the value as ulong.
Definition: Variant.cs:1047
override bool Equals(object obj)
Returns a value that indicates if this Variant equals given object.
Definition: Variant.cs:594
string JsonDataType
Gets the Json data type.
Definition: Variant.cs:1503
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:855
static readonly Variant True
Gets a Variant with boolean value 'true'.
Definition: Variant.cs:755
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:1654
static bool operator==(Variant l, Variant r)
Equality Operator.
Definition: Variant.cs:681
ushort ToUInt16()
Gets the value as ushort.
Definition: Variant.cs:975
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:1075
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:760
int ToInt32()
Gets the value as int.
Definition: Variant.cs:993
static readonly Variant Empty
Gets a Variant with empty string value.
Definition: Variant.cs:750
bool IsNumber
Gets a value that indicates whether the Variant contains a numeric value. Returns false for numeric a...
Definition: Variant.cs:886
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:1267
bool IsArray
Gets a value that indicates whether the Variant is an array.
Definition: Variant.cs:868
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:1467
bool[] ToBoolArray()
Gets the value as bool array.
Definition: Variant.cs:1111
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