/// <summary> /// Attempts to retrieve a value of the known type from this StyleItem /// </summary> /// <typeparam name="T">The type of value to retrieve</typeparam> /// <param name="itembase">This style item</param> /// <param name="key">The style key of the value to retrieve</param> /// <param name="found">Set to the value of any found item, or default value.</param> /// <returns>True if the item has a reference to the value required, otherwise false.</returns> public static bool TryGetValue <T>(this StyleItemBase itembase, PDFStyleKey <T> key, out T found) { StyleValue <T> exist; if (itembase.AssertOwner().TryGetValue(key, out exist)) { found = exist.Value(itembase.AssertOwner()); return(true); } else { found = default(T); return(false); } }
/// <summary> /// Sets a value of a known type for this style item, based on the specified key. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="itembase"></param> /// <param name="key"></param> /// <param name="value"></param> public static void SetValue <T>(this StyleItemBase itembase, PDFStyleKey <T> key, T value) { StyleValue <T> found; if (itembase.AssertOwner().TryGetValue(key, out found)) { found.SetValue(value); } else { found = new StyleValue <T>(key, value); itembase.AddBaseValue(found); } }