// A string requires a special case because it's not a struct or value type private string[] GetStringVector() { int count = Propsys.PropVariantGetElementCount(ref this); if (count <= 0) { return(null); } string[] strArr = new string[count]; for (uint i = 0; i < count; i++) { Propsys.PropVariantGetStringElem(ref this, i, out strArr[i]); } return(strArr); }
private Array GetVector <T>() where T : struct { int count = Propsys.PropVariantGetElementCount(ref this); if (count <= 0) { return(null); } Array arr = new T[count]; for (uint i = 0; i < count; i++) { if (typeof(T) == typeof(Int16)) { short val; Propsys.PropVariantGetInt16Elem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(UInt16)) { ushort val; Propsys.PropVariantGetUInt16Elem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(Int32)) { int val; Propsys.PropVariantGetInt32Elem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(UInt32)) { uint val; Propsys.PropVariantGetUInt32Elem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(Int64)) { long val; Propsys.PropVariantGetInt64Elem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(UInt64)) { ulong val; Propsys.PropVariantGetUInt64Elem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(DateTime)) { System.Runtime.InteropServices.ComTypes.FILETIME val; Propsys.PropVariantGetFileTimeElem(ref this, i, out val); long fileTime = FileTimeToDateTime(ref val); arr.SetValue(DateTime.FromFileTime(fileTime), i); } else if (typeof(T) == typeof(Boolean)) { bool val; Propsys.PropVariantGetBooleanElem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(Double)) { double val; Propsys.PropVariantGetDoubleElem(ref this, i, out val); arr.SetValue(val, i); } else if (typeof(T) == typeof(String)) { string val; Propsys.PropVariantGetStringElem(ref this, i, out val); arr.SetValue(val, i); } } return(arr); }