コード例 #1
0
        /// <summary>
        /// Get the value of the designer property for this model item.
        /// If there is not a value then create one using the factory.
        /// </summary>
        /// <typeparam name="T">Property value type.</typeparam>
        /// <param name="item">Model item.</param>
        /// <param name="property">Designer property.</param>
        /// <param name="factory">A function to initialize the designer property value.</param>
        /// <returns>Designer property value.</returns>
        public static T GetDesignerProperty <T>(this ModelItem item, DesignerProperty <T> property, Func <ModelItem, T> factory)
        {
            DesignerStateDictionary dictionary = item.Context.Services.GetService <DesignerStateDictionary>();

            if (dictionary == null)
            {
                dictionary = new DesignerStateDictionary();
                item.Context.Services.Publish <DesignerStateDictionary>(dictionary);
            }

            StateTable table;

            if (dictionary.TryGetValue(item, out table))
            {
                object value;
                if (table.TryGetValue(property, out value))
                {
                    return((T)value);
                }
                else if (factory != null)
                {
                    T v = factory(item);
                    table[property] = v;
                    return(v);
                }
            }
            return(default(T));
        }
コード例 #2
0
        /// <summary>
        /// Clear the value of the designer property for this model item.
        /// </summary>
        /// <typeparam name="T">Property value type.</typeparam>
        /// <param name="item">Model item.</param>
        /// <param name="property">Designer property.</param>
        public static void ClearDesignerProperty <T>(this ModelItem item, DesignerProperty <T> property)
        {
            DesignerStateDictionary dictionary = item.Context.Services.GetService <DesignerStateDictionary>();

            if (dictionary != null)
            {
                StateTable table;
                if (dictionary.TryGetValue(item, out table))
                {
                    table.Remove(property);
                }
                if (table != null && table.Count == 0)
                {
                    dictionary.Remove(item);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Set the value of the designer property for this model item.
        /// </summary>
        /// <typeparam name="T">Property value type.</typeparam>
        /// <param name="item">Model item.</param>
        /// <param name="property">Designer property.</param>
        /// <param name="value">Designer property value.</param>
        public static void SetDesignerProperty <T>(this ModelItem item, DesignerProperty <T> property, T value)
        {
            DesignerStateDictionary dictionary = item.Context.Services.GetService <DesignerStateDictionary>();

            if (dictionary == null)
            {
                dictionary = new DesignerStateDictionary();
                item.Context.Services.Publish <DesignerStateDictionary>(dictionary);
            }

            StateTable table;

            if (!dictionary.TryGetValue(item, out table))
            {
                table            = new StateTable();
                dictionary[item] = table;
            }

            table[property] = value;
        }
コード例 #4
0
 /// <summary>
 /// Get the value of the designer property for this model item.
 /// </summary>
 /// <typeparam name="T">Property value type.</typeparam>
 /// <param name="item">Model item.</param>
 /// <param name="property">Designer property.</param>
 /// <returns>Designer property value.</returns>
 public static T GetDesignerProperty <T>(this ModelItem item, DesignerProperty <T> property)
 {
     return(GetDesignerProperty <T>(item, property, null));
 }