/// <summary> /// Sets the value of the property with this name /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> public void Set(string name, object value) { CheckIfInitialized(); // In order to set a property in the property bag // we need to convert the value to the destination type var previousValue = Get(name); value = Convert.ChangeType(value, previousValue == null?value.GetType() : previousValue.GetType()); // Set the property var propbag2 = new PROPBAG2() { Name = name }; var result = nativePropertyBag.Write(1, ref propbag2, value); result.CheckError(); propbag2.Dispose(); }
/// <summary> /// Gets the value of the property with this name. /// </summary> /// <param name="name">The name.</param> /// <returns>Value of the property</returns> public object Get(string name) { CheckIfInitialized(); object value; var propbag2 = new PROPBAG2() { Name = name }; Result error; // Gets the property var result = nativePropertyBag.Read(1, ref propbag2, IntPtr.Zero, out value, out error); if (result.Failure || error.Failure) { throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Property with name [{0}] is not valid for this instance", name)); } propbag2.Dispose(); return(value); }