/// <summary> /// Disposes the object, calls the clear function. /// </summary> public void Dispose() { PropVariantNativeMethods.PropVariantClear(this); GC.SuppressFinalize(this); }
private static Dictionary <Type, Action <PropVariant, Array, uint> > GenerateVectorActions() { var cache = new Dictionary <Type, Action <PropVariant, Array, uint> >(); cache.Add(typeof(short), (pv, array, i) => { short val; PropVariantNativeMethods.PropVariantGetInt16Elem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(ushort), (pv, array, i) => { ushort val; PropVariantNativeMethods.PropVariantGetUInt16Elem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(int), (pv, array, i) => { int val; PropVariantNativeMethods.PropVariantGetInt32Elem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(uint), (pv, array, i) => { uint val; PropVariantNativeMethods.PropVariantGetUInt32Elem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(long), (pv, array, i) => { long val; PropVariantNativeMethods.PropVariantGetInt64Elem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(ulong), (pv, array, i) => { ulong val; PropVariantNativeMethods.PropVariantGetUInt64Elem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(DateTime), (pv, array, i) => { System.Runtime.InteropServices.ComTypes.FILETIME val; PropVariantNativeMethods.PropVariantGetFileTimeElem(pv, i, out val); long fileTime = GetFileTimeAsLong(ref val); array.SetValue(DateTime.FromFileTime(fileTime), i); }); cache.Add(typeof(bool), (pv, array, i) => { bool val; PropVariantNativeMethods.PropVariantGetBooleanElem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(double), (pv, array, i) => { double val; PropVariantNativeMethods.PropVariantGetDoubleElem(pv, i, out val); array.SetValue(val, i); }); cache.Add(typeof(float), (pv, array, i) => { // float var val = new float[1]; Marshal.Copy(pv._ptr2, val, (int)i, 1); array.SetValue(val[0], (int)i); }); cache.Add(typeof(decimal), (pv, array, i) => { var val = new int[4]; for (int a = 0, l = val.Length; a < l; a++) { // index * size + offset quarter val[a] = Marshal.ReadInt32(pv._ptr2, (int)i * sizeof(decimal) + a * 4); } array.SetValue(new decimal(val), i); }); cache.Add(typeof(string), (pv, array, i) => { string val = string.Empty; PropVariantNativeMethods.PropVariantGetStringElem(pv, i, out val); array.SetValue(val, i); }); return(cache); }