Exemplo n.º 1
0
        /// <summary>
        /// Generate CanExpand and ChildrenGetter delegates from the given property.
        /// </summary>
        /// <param name="tlv"></param>
        /// <param name="pinfo"></param>
        protected virtual void GenerateChildrenDelegates(TreeListView tlv, PropertyInfo pinfo)
        {
            Munger childrenGetter = new Munger(pinfo.Name);

            tlv.CanExpandGetter = delegate(object x) {
                try {
                    IEnumerable result = childrenGetter.GetValueEx(x) as IEnumerable;
                    return(!ObjectListView.IsEnumerableEmpty(result));
                }
                catch (MungerException ex) {
                    System.Diagnostics.Debug.WriteLine(ex);
                    return(false);
                }
            };
            tlv.ChildrenGetter = delegate(object x) {
                try {
                    return(childrenGetter.GetValueEx(x) as IEnumerable);
                }
                catch (MungerException ex) {
                    System.Diagnostics.Debug.WriteLine(ex);
                    return(null);
                }
            };
        }
Exemplo n.º 2
0
Arquivo: Munger.cs Projeto: VicBoss/KR
        /// <summary>
        /// A helper method to put the given value into the given aspect of the given object.
        /// </summary>
        /// <remarks>This method catches and silently ignores any errors that occur
        /// while modifying the target object</remarks>
        /// <param name="target">The object to be modified</param>
        /// <param name="propertyName">The name of the property/field to be modified</param>
        /// <param name="value">The value to be assigned</param>
        /// <returns>Did the modification work?</returns>
        public static bool PutProperty(object target, string propertyName, object value) {
            try {
                Munger munger = new Munger(propertyName);
                return munger.PutValue(target, value);
            }
            catch (MungerException) {
                // Not a lot we can do about this. Something went wrong in the bowels
                // of the property. Let's take the ostrich approach and just ignore it :-)
            } 

            return false;
        }
Exemplo n.º 3
0
        /// <summary>
        /// A helper method to put the given value into the given aspect of the given object.
        /// </summary>
        /// <remarks>This method catches and silently ignores any errors that occur
        /// while modifying the target object</remarks>
        /// <param name="target">The object to be modified</param>
        /// <param name="propertyName">The name of the property/field to be modified</param>
        /// <param name="value">The value to be assigned</param>
        /// <returns>Did the modification work?</returns>
        public static bool PutProperty(object target, string propertyName, object value) {
            try {
                Munger munger = new Munger(propertyName);
                return munger.PutValue(target, value);
            }
            catch (MungerException) {
                // Not a lot we can do about this. Something went wrong in the bowels
                // of the property. Let's take the ostrich approach and just ignore it :-)

                // Normally, we would never just silently ignore an exception.
                // However, in this case, this is a utility method that explicitly
                // contracts to catch and ignore errors. If this is not acceptible,
                // the programmer should not use this method.
            }

            return false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fetch the description from the model class
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual string GetDescription(object model)
        {
            if (String.IsNullOrEmpty(this.DescriptionAspectName))
                return String.Empty;

            if (this.descriptionGetter == null)
                this.descriptionGetter = new Munger(this.DescriptionAspectName);

            return this.descriptionGetter.GetValue(model) as string;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Fetch the description from the model class
        /// </summary>
        /// <returns></returns>
        protected virtual string GetDescription()
        {
            if (String.IsNullOrEmpty(this.DescriptionAspectName))
                return String.Empty;

            if (this.descriptionGetter == null)
                this.descriptionGetter = new Munger(this.DescriptionAspectName);

            return this.descriptionGetter.GetValue(this.RowObject) as String;
        }
Exemplo n.º 6
0
        /// <summary>
        /// If the given munger returns the same value for all the given
        /// songs, then return that value. Otherwise, return an empty string.
        /// </summary>
        /// <param name="songs">The list of songs to be considered</param>
        /// <param name="munger">The munger which will extract the value</param>
        /// <returns>The common value or an empty string</returns>
        private string GetCommonValue(IList<Song> songs, Munger munger)
        {
            if (songs.Count == 0 || songs.Count > 1000)
                return "";

            string value = (string)munger.GetValue(songs[0]);
            for (int i = 1; i < songs.Count; i++) {
                if (value != (string)munger.GetValue(songs[i]))
                    return "";
            }

            return value;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Generate CanExpand and ChildrenGetter delegates from the given property.
 /// </summary>
 /// <param name="tlv"></param>
 /// <param name="pinfo"></param>
 protected virtual void GenerateChildrenDelegates(TreeListView tlv, PropertyInfo pinfo) {
     Munger childrenGetter = new Munger(pinfo.Name);
     tlv.CanExpandGetter = delegate(object x) {
         try {
             IEnumerable result = childrenGetter.GetValueEx(x) as IEnumerable;
             return !ObjectListView.IsEnumerableEmpty(result);
         }
         catch (MungerException ex) {
             System.Diagnostics.Debug.WriteLine(ex);
             return false;
         }
     };
     tlv.ChildrenGetter = delegate(object x) {
         try {
             return childrenGetter.GetValueEx(x) as IEnumerable;
         }
         catch (MungerException ex) {
             System.Diagnostics.Debug.WriteLine(ex);
             return null;
         }
     };
 }