コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyFilterValueGetter"/> class.
 /// </summary>
 /// <param name="valueFilter">
 /// Associated property Filter descriptor
 /// </param>
 /// <param name="type">
 /// Underlying type
 /// </param>
 public PropertyFilterValueGetter(PropertyFilter valueFilter, Type type)
 {
     ValueFilterDescriptor = valueFilter;
     fieldName = valueFilter.FieldName;
     monitorPropertyChanged = valueFilter.MonitorPropertyChanged;
     _propertyValueGetter = CompileValueGetter(valueFilter.FieldName, type);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyFilterValueGetter"/> class.
 /// </summary>
 /// <param name="valueFilter">
 /// Associated property Filter descriptor
 /// </param>
 /// <param name="type">
 /// Underlying type
 /// </param>
 public PropertyFilterValueGetter(PropertyFilter valueFilter, Type type)
 {
     ValueFilterDescriptor  = valueFilter;
     fieldName              = valueFilter.FieldName;
     monitorPropertyChanged = valueFilter.MonitorPropertyChanged;
     _propertyValueGetter   = CompileValueGetter(valueFilter.FieldName, type);
 }
コード例 #3
0
        /// <summary>
        /// Method called when FilterColumns property changes
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// Raised when a a property filter refers to a non existing candidate object type property
        /// </exception>
        private void SetFilterColumns()
        {
            var propertyFilters = Items.Cast<ValueFilter>().ToList();

            if (UnderlyingType.Equals(typeof (string)) || UnderlyingType.IsValueType)
            {
                // for native types, only one ValueFilter accepted to apply string format or IValueConverter 
                if (propertyFilters.Count > 1)
                {
                    throw new InvalidOperationException(
                        "Only one property filter is authorized when underlying type is String or a value type.");
                }


// Then if there is no property filter at all, there is no conversion needed and we build a defautl property getter
                // and there is one, we build a property getter accordingly
                _valueGetters.Add(propertyFilters.Count == 0
                                      ? new PropertyFilterValueGetter(new ValueFilter())
                                      : new PropertyFilterValueGetter(propertyFilters[0]));
            }
                

// if the underlying type if neither a string nor value type, then it is a reference type
            else
            {
                IEnumerable<PropertyFilter> apfs;


// if there is no PropertyFilter defined, we build it by default based on every instance public properties of the underlying type
                if (propertyFilters.Count == 0)
                {
                    apfs = new List<PropertyFilter>();


// Get the type Properties
                    var pis = UnderlyingType.GetProperties(BindingFlags.Public | BindingFlags.Instance);


// iterate
                    foreach (var propertyInfo in pis)
                    {
                        var pf = new PropertyFilter(propertyInfo.Name, DefaultMonitorPropertyChanges);
                        var pfvg = new PropertyFilterValueGetter(pf, UnderlyingType); // Generate...
                        _valueGetters.Add(pfvg); // ...and add value getter for each properties
                    }
                }
                else
                {
                    // and thus every ValueFilter must be PropertyFilter
                    if (propertyFilters.Any(p => !(p is PropertyFilter)))
                    {
                        throw new InvalidOperationException("ValueFilter can't be used with reference type.");
                    }

                    apfs = propertyFilters.Cast<PropertyFilter>().ToList();
                    foreach (PropertyFilter pf in apfs)
                    {
                        // Get the PropertyInfo
                        PropertyInfo pi = UnderlyingType.GetProperty(pf.FieldName);

                        // this info is mandatory
                        if (pi == null)
                        {
                            throw new InvalidOperationException(
                                string.Format("Cant't find the property {0} for type {1}", 
                                              pf.FieldName, UnderlyingType.Name));
                        }

                        // If pi is ok, build the value getter and add it to the list
                        var pfvg = new PropertyFilterValueGetter(pf, UnderlyingType);
                        _valueGetters.Add(pfvg);
                    }
                }

                // If there is no ValueFilter which is set to be monitored for property changes, we keep track of it to avoid to subscribe to propertychanged event later on
                _hasAnyPropertyChangesToMonitor = apfs.Any(p => p.MonitorPropertyChanged);
            }
        }
コード例 #4
0
        /// <summary>
        /// Method called when FilterColumns property changes
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// Raised when a a property filter refers to a non existing candidate object type property
        /// </exception>
        private void SetFilterColumns()
        {
            var propertyFilters = Items.Cast <ValueFilter>().ToList();

            if (UnderlyingType.Equals(typeof(string)) || UnderlyingType.IsValueType)
            {
                // for native types, only one ValueFilter accepted to apply string format or IValueConverter
                if (propertyFilters.Count > 1)
                {
                    throw new InvalidOperationException(
                              "Only one property filter is authorized when underlying type is String or a value type.");
                }


// Then if there is no property filter at all, there is no conversion needed and we build a defautl property getter
                // and there is one, we build a property getter accordingly
                _valueGetters.Add(propertyFilters.Count == 0
                                      ? new PropertyFilterValueGetter(new ValueFilter())
                                      : new PropertyFilterValueGetter(propertyFilters[0]));
            }


// if the underlying type if neither a string nor value type, then it is a reference type
            else
            {
                IEnumerable <PropertyFilter> apfs;


// if there is no PropertyFilter defined, we build it by default based on every instance public properties of the underlying type
                if (propertyFilters.Count == 0)
                {
                    apfs = new List <PropertyFilter>();


// Get the type Properties
                    var pis = UnderlyingType.GetProperties(BindingFlags.Public | BindingFlags.Instance);


// iterate
                    foreach (var propertyInfo in pis)
                    {
                        var pf   = new PropertyFilter(propertyInfo.Name, DefaultMonitorPropertyChanges);
                        var pfvg = new PropertyFilterValueGetter(pf, UnderlyingType); // Generate...
                        _valueGetters.Add(pfvg);                                      // ...and add value getter for each properties
                    }
                }
                else
                {
                    // and thus every ValueFilter must be PropertyFilter
                    if (propertyFilters.Any(p => !(p is PropertyFilter)))
                    {
                        throw new InvalidOperationException("ValueFilter can't be used with reference type.");
                    }

                    apfs = propertyFilters.Cast <PropertyFilter>().ToList();
                    foreach (PropertyFilter pf in apfs)
                    {
                        // Get the PropertyInfo
                        PropertyInfo pi = UnderlyingType.GetProperty(pf.FieldName);

                        // this info is mandatory
                        if (pi == null)
                        {
                            throw new InvalidOperationException(
                                      string.Format("Cant't find the property {0} for type {1}",
                                                    pf.FieldName, UnderlyingType.Name));
                        }

                        // If pi is ok, build the value getter and add it to the list
                        var pfvg = new PropertyFilterValueGetter(pf, UnderlyingType);
                        _valueGetters.Add(pfvg);
                    }
                }

                // If there is no ValueFilter which is set to be monitored for property changes, we keep track of it to avoid to subscribe to propertychanged event later on
                _hasAnyPropertyChangesToMonitor = apfs.Any(p => p.MonitorPropertyChanged);
            }
        }