public IEnumerator <IShellProperty> GetEnumerator() { if (this.properties == null) { using (var propertyStore = ShellPropertyStore.Create(this.ShellObject)) { var propertyCount = propertyStore.Count; this.properties = new List <IShellProperty>(propertyCount); for (var index = 0u; index < propertyCount; ++index) { var propertyKey = propertyStore.GetAt(index); try { this.properties.Add(ShellPropertyFactory.Create(propertyKey, this.ShellObject)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } } } return(this.properties.GetEnumerator()); }
/// <summary> /// Gets the text for displaying the property value. /// </summary> /// <param name="formatFlags">Format flags.</param> /// <returns></returns> public string GetDisplayText(PropertyDescriptionFormatFlags formatFlags) { using (var store = ShellPropertyStore.Create(this.ShellObject)) { var propVar = default(PropVariant); try { store.GetPropVariant(this.PropertyKey, out propVar); return(this.Description.GetDisplayText(ref propVar, formatFlags)); } finally { propVar.Clear(); } } }
/// <summary> /// Initialize a new instance of the <see cref="ShellPropertyWriter" /> class /// to the specified <see cref="ShellObject" />. /// </summary> /// <param name="shellObject"></param> internal ShellPropertyWriter(ShellObject shellObject) { Contract.Requires <ArgumentNullException>(shellObject != null); try { this.Store = ShellPropertyStore.CreateWritable(shellObject); } catch (InvalidComObjectException e) { throw new ShellException(ErrorMessages.ShellPropertyUnableToGetWritableProperty, e); } catch (InvalidCastException) { throw new ShellException(ErrorMessages.ShellPropertyUnableToGetWritableProperty); } }
/// <summary> /// Clear property value. /// </summary> public void ClearValue() { try { using (var writableStore = ShellPropertyStore.CreateWritable(this.ShellObject)) { writableStore.ClearValue(this.PropertyKey); writableStore.Commit(); } } catch (InvalidComObjectException e) { throw new ShellException(ErrorMessages.ShellPropertyUnableToGetWritableProperty, e); } catch (InvalidCastException e) { throw new ShellException(ErrorMessages.ShellPropertyUnableToGetWritableProperty, e); } }
public bool TryGetDisplayText(PropertyDescriptionFormatFlags formatFlags, out string text) { using (var store = ShellPropertyStore.Create(this.ShellObject)) { var propVar = default(PropVariant); try { store.GetPropVariant(this.PropertyKey, out propVar); if (!this.Description.TryGetDisplayText(ref propVar, formatFlags, out text)) { text = String.Empty; return(false); } return(true); } finally { propVar.Clear(); } } }
/// <summary> /// Initialize a instance of the <see cref="ShellProperty{T}" /> class. /// </summary> /// <param name="propertyKey"></param> /// <param name="description"></param> /// <param name="propertyStore"></param> /// <remarks> /// This constructor is used in <see cref="ShellPropertyFactory" />. /// Do not change the order of the parameters. /// </remarks> internal ShellProperty(ShellPropertyKey propertyKey, ShellPropertyDescription description, ShellPropertyStore propertyStore) { Contract.Requires <ArgumentNullException>(propertyKey != null); Contract.Requires <ArgumentNullException>(propertyStore != null); this.PropertyStore = propertyStore; this.PropertyKey = propertyKey; this.description = description; this.AllowSetTruncatedValue = false; if (this.Description.ValueType != typeof(T)) { throw new InvalidOperationException( String.Format(ErrorMessages.ShellPropertyUnmatchValueType, typeof(T), this.Description.ValueType)); } }