packages/Windows API Code Pack 1.1/source/WindowsAPICodePack/Shell/PropertySystem/ShellPropertyWriter.cs
/// <summary>
/// Writes the given property key and value. To allow truncation of the given value, set allowTruncatedValue
/// to true.
/// </summary>
/// <param name="key">The property key.</param>
/// <param name="value">The value associated with the key.</param>
/// <param name="allowTruncatedValue">True to allow truncation (default); otherwise False.</param>
/// <exception cref="System.InvalidOperationException">If the writable property store is already 
/// closed.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">If AllowTruncatedValue is set to false 
/// and while setting the value on the property it had to be truncated in a string or rounded in 
/// a numeric value.</exception>
Writes the given property key and value. To allow truncation of the given value, set allowTruncatedValue
to true.
Writes the given property key and value . To allow truncation of the given value set allowTruncatedValue to true .
public void WriteProperty(PropertyKey key, object value, bool allowTruncatedValue)
        {
            if (writablePropStore == null)
                throw new InvalidOperationException("Writeable store has been closed.");
            using (PropVariant propVar = PropVariant.FromObject(value))
            {
                HResult result = writablePropStore.SetValue(ref key, propVar);
                if (!allowTruncatedValue && ((int)result == ShellNativeMethods.InPlaceStringTruncated))
                {
                    Marshal.ReleaseComObject(writablePropStore);
                    writablePropStore = null;
                    throw new ArgumentOutOfRangeException("value", LocalizedMessages.ShellPropertyValueTruncated);
                }
                if (!CoreErrorHelper.Succeeded(result))
                {
                    throw new PropertySystemException(LocalizedMessages.ShellPropertySetValue, Marshal.GetExceptionForHR((int)result));
                }
            }
        }
public void WriteProperty ( PropertyKey key , object value , bool allowTruncatedValue ) { if ( writablePropStore == null ) throw new InvalidOperationException ( " " ) ; using ( PropVariant propVar = PropVariant . FromObject ( value ) ) { HResult result = writablePropStore . SetValue ( ref key , propVar ) ; if ( ! allowTruncatedValue && ( ( int ) result == ShellNativeMethods . InPlaceStringTruncated ) ) { Marshal . ReleaseComObject ( writablePropStore ) ; writablePropStore = null ; throw new ArgumentOutOfRangeException ( " " , LocalizedMessages . ShellPropertyValueTruncated ) ; } if ( ! CoreErrorHelper . Succeeded ( result ) ) { throw new PropertySystemException ( LocalizedMessages . ShellPropertySetValue , Marshal . GetExceptionForHR ( ( int ) result ) ) ; } } }
Writes the given property key and value.
Writes the given property key and value .
// At this point we can't revert back the commit // so don't commit, close the property store and throw an exception // to let the user know.
If the writable property store is already
closed.
If the writable property store is already closed .
If AllowTruncatedValue is set to false
and while setting the value on the property it had to be truncated in a string or rounded in
a numeric value.
If AllowTruncatedValue is set to false and while setting the value on the property it had to be truncated in a string or rounded in a numeric value .
key
PropertyKey
The property key.
The property key .
value
object
The value associated with the key.
The value associated with the key .
allowTruncatedValue
bool
True to allow truncation (default); otherwise False.
True to allow truncation ( default ) ; otherwise False .