public Variant(object?obj) { _data = 0; VarEnum vt = VarEnum.VT_EMPTY; if (obj is DateTime) { _objref = null; _flags = CV_DATETIME; _data = ((DateTime)obj).Ticks; return; } if (obj is string) { _flags = CV_STRING; _objref = obj; return; } if (obj == null) { this = Empty; return; } if (obj == System.DBNull.Value) { this = DBNull; return; } if (obj == Type.Missing) { this = Missing; return; } if (obj is Array) { _flags = CV_OBJECT | ArrayBitMask; _objref = obj; return; } // Compiler appeasement _flags = CV_EMPTY; _objref = null; // Check to see if the object passed in is a wrapper object. if (obj is UnknownWrapper) { vt = VarEnum.VT_UNKNOWN; obj = ((UnknownWrapper)obj).WrappedObject; } else if (obj is DispatchWrapper) { vt = VarEnum.VT_DISPATCH; Debug.Assert(OperatingSystem.IsWindows()); obj = ((DispatchWrapper)obj).WrappedObject; } else if (obj is ErrorWrapper) { vt = VarEnum.VT_ERROR; obj = (object)(((ErrorWrapper)obj).ErrorCode); Debug.Assert(obj != null, "obj != null"); } else if (obj is CurrencyWrapper) { vt = VarEnum.VT_CY; obj = (object)(((CurrencyWrapper)obj).WrappedObject); Debug.Assert(obj != null, "obj != null"); } else if (obj is BStrWrapper) { vt = VarEnum.VT_BSTR; obj = (object?)(((BStrWrapper)obj).WrappedObject); } if (obj != null) { SetFieldsObject(obj); } // If the object passed in is one of the wrappers then set the VARIANT type. if (vt != VarEnum.VT_EMPTY) { _flags |= ((int)vt << VTBitShift); } }