/// <summary> /// Set a ulong vector /// </summary> /// <param name="value">The new value to set.</param> public void SetULongVector(ulong[] value) { PropVariant propVar; Propsys.InitPropVariantFromUInt64Vector(value, (uint)value.Length, out propVar); CopyData(propVar); }
/// <summary> /// Set a double vector /// </summary> /// <param name="value">The new value to set.</param> public void SetDoubleVector(double[] value) { PropVariant propVar; Propsys.InitPropVariantFromDoubleVector(value, (uint)value.Length, out propVar); CopyData(propVar); }
/// <summary> /// Set a short vector /// </summary> /// <param name="value">The new value to set.</param> public void SetUShortVector(ushort[] value) { PropVariant propVar; Propsys.InitPropVariantFromUInt16Vector(value, (uint)value.Length, out propVar); CopyData(propVar); }
/// <summary> /// Set an int vector /// </summary> /// <param name="value">The new value to set.</param> public void SetIntVector(int[] value) { PropVariant propVar; Propsys.InitPropVariantFromInt32Vector(value, (uint)value.Length, out propVar); CopyData(propVar); }
/// <summary> /// Set a bool vector /// </summary> /// <param name="value">The new value to set.</param> public void SetBoolVector(bool[] value) { PropVariant propVar; Propsys.InitPropVariantFromBooleanVector(value, (uint)value.Length, out propVar); CopyData(propVar); }
/// <summary> /// Set a string vector /// </summary> /// <param name="value">The new value to set.</param> public void SetStringVector(string[] value) { PropVariant propVar; Propsys.InitPropVariantFromStringVector(value, (uint)value.Length, out propVar); CopyData(propVar); }
private void CreatePropVariantFromVectorElement(PropVariant propVar) { //Copy the first vector element to a new PropVariant CopyData(propVar); Propsys.InitPropVariantFromPropVariantVectorElem(ref this, 0, out propVar); //Overwrite the existing data CopyData(propVar); }
/// <summary> /// Set a ulong /// </summary> /// <param name="value">The new value to set.</param> public void SetULong(ulong value) { PropVariant propVar; ulong[] valueArr = new ulong[] { value }; Propsys.InitPropVariantFromUInt64Vector(valueArr, 1, out propVar); CreatePropVariantFromVectorElement(propVar); }
/// <summary> /// Set a double /// </summary> /// <param name="value">The new value to set.</param> public void SetDouble(double value) { double[] valueArr = new double[] { value }; PropVariant propVar; Propsys.InitPropVariantFromDoubleVector(valueArr, 1, out propVar); CreatePropVariantFromVectorElement(propVar); }
/// <summary> /// Set a DateTime value /// </summary> /// <param name="value">The new value to set.</param> public void SetDateTime(DateTime value) { valueType = (ushort)VarEnum.VT_FILETIME; PropVariant propVar; System.Runtime.InteropServices.ComTypes.FILETIME ft = DateTimeTotFileTime(value); Propsys.InitPropVariantFromFileTime(ref ft, out propVar); CopyData(propVar); }
public T GetProperty <T>(PROPERTYKEY property) { var item = (IShellItem2)GetItem(); try{ return((T)Propsys.PropVariantToVariant(item.GetProperty(ref property))); }finally{ Marshal.FinalReleaseComObject(item); } }
/// <summary> /// Set a DateTime vector /// </summary> /// <param name="value">The new value to set.</param> public void SetDateTimeVector(DateTime[] value) { System.Runtime.InteropServices.ComTypes.FILETIME[] fileTimeArr = new System.Runtime.InteropServices.ComTypes.FILETIME[value.Length]; for (int i = 0; i < value.Length; i++) { fileTimeArr[i] = DateTimeTotFileTime(value[i]); } PropVariant propVar; Propsys.InitPropVariantFromFileTimeVector(fileTimeArr, (uint)fileTimeArr.Length, out propVar); CopyData(propVar); }
// 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); }
public void SetProperty <T>(PROPERTYKEY property, T value) { var item = GetItem(); try{ var propvar = Propsys.VariantToPropVariant(value); var properties = Propsys.PSCreatePropertyChangeArray <IPropertyChangeArray>(new[] { Shell32.PKEY_FileAttributes }, new[] { Propsys.PKA_FLAGS.PKA_SET }, new[] { propvar }); var op = Shell32.CreateFileOperation(); op.SetOwnerWindow(fs.OwnerHwnd); op.SetOperationFlags(0x0400 | 0x0004 | 0x0200 | 0x00100000); op.SetProperties(properties); op.ApplyPropertiesToItem(item); op.PerformOperations(); }finally{ Marshal.FinalReleaseComObject(item); } }
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); }