///<summary> /// Builds a custom filter. ///</summary> ///<param name="filterPropertyDef"></param> ///<returns></returns> public ICustomFilter BuildCustomFilter(IFilterPropertyDef filterPropertyDef) { Type filterType = TypeLoader.LoadType(filterPropertyDef.FilterTypeAssembly, filterPropertyDef.FilterType); ICustomFilter customFilter = (ICustomFilter)Activator.CreateInstance(filterType, _controlFactory, filterPropertyDef.PropertyName, filterPropertyDef.FilterClauseOperator); SetParametersOnFilter(filterPropertyDef, filterType, customFilter); return(customFilter); }
/// <summary> /// Loads all the data out of the reader, assuming the document is /// well-formed, otherwise the error must be caught and thrown. /// By the end of this method the reader must be finished reading. /// This method needs to be implemented by the sub-class. /// </summary> protected override void LoadFromReader() { if (_reader.Name == "filter") { _reader.Read(); string filterModeStr = _reader.GetAttribute("filterMode"); _filterMode = (FilterModes)Enum.Parse(typeof(FilterModes), filterModeStr); _columns = Convert.ToInt32(_reader.GetAttribute("columns")); } _reader.Read(); while (_reader.Name == "filterProperty") { string propertyName = _reader.GetAttribute("name"); string label = _reader.GetAttribute("label"); string filterType = _reader.GetAttribute("filterType"); string filterTypeAssembly = _reader.GetAttribute("filterTypeAssembly"); string filterClauseOperatorStr = _reader.GetAttribute("operator"); FilterClauseOperator filterClauseOperator = (FilterClauseOperator)Enum.Parse(typeof(FilterClauseOperator), filterClauseOperatorStr); Dictionary <string, string> parameters = new Dictionary <string, string>(); IFilterPropertyDef filterPropertyDef = _defClassFactory.CreateFilterPropertyDef(propertyName, label, filterType, filterTypeAssembly, filterClauseOperator, parameters); _reader.Read(); if (_reader.Name == "parameter") { while (_reader.Name == "parameter") { string name = _reader.GetAttribute("name"); string value = _reader.GetAttribute("value"); parameters.Add(name, value); _reader.Read(); } _reader.Read(); } _propertyDefs.Add(filterPropertyDef); if (!_reader.IsStartElement()) { _reader.ReadEndElement(); } filterPropertyDef.Parameters = parameters; } while (_reader.Name == "filter") { _reader.Read(); } }
public IFilterPropertyDef CreateUIFilterProperty(IPropDef propDef) { if (propDef == null) { throw new ArgumentNullException("propDef"); } UIControlType uiControlType = GetControlType(propDef); var filterClauseOperator = GetFilterClauseOperator(propDef); IFilterPropertyDef filterPropertyDef = _factory.CreateFilterPropertyDef(propDef.PropertyName, propDef.DisplayName, uiControlType.TypeName, uiControlType.AssemblyName, filterClauseOperator, new Dictionary <string, string>()); return(filterPropertyDef); }
private static void SetParametersOnFilter(IFilterPropertyDef filterPropertyDef, Type filterType, ICustomFilter customFilter) { if (filterPropertyDef.Parameters == null) return; foreach (KeyValuePair<string, string> parameter in filterPropertyDef.Parameters) { System.Reflection.PropertyInfo propertyInfo = filterType.GetProperty (parameter.Key, BindingFlags.Instance | BindingFlags.Public); if (propertyInfo == null) { throw new HabaneroDeveloperException (string.Format ("The property '{0}' was not found on a filter of type '{1}' for property '{2}'", parameter.Key, filterPropertyDef.FilterType, filterPropertyDef.PropertyName), ""); } propertyInfo.SetValue (customFilter, Convert.ChangeType(parameter.Value, propertyInfo.PropertyType), null); } }
private static void SetParametersOnFilter(IFilterPropertyDef filterPropertyDef, Type filterType, ICustomFilter customFilter) { if (filterPropertyDef.Parameters == null) { return; } foreach (KeyValuePair <string, string> parameter in filterPropertyDef.Parameters) { System.Reflection.PropertyInfo propertyInfo = filterType.GetProperty (parameter.Key, BindingFlags.Instance | BindingFlags.Public); if (propertyInfo == null) { throw new HabaneroDeveloperException (string.Format ("The property '{0}' was not found on a filter of type '{1}' for property '{2}'", parameter.Key, filterPropertyDef.FilterType, filterPropertyDef.PropertyName), ""); } propertyInfo.SetValue (customFilter, Convert.ChangeType(parameter.Value, propertyInfo.PropertyType), null); } }
private static void AssertIsControlOfType(string controlName, string assemblyName, IFilterPropertyDef filterPropertyDef) { Assert.AreEqual(controlName, filterPropertyDef.FilterType); Assert.AreEqual(assemblyName, filterPropertyDef.FilterTypeAssembly); }
///<summary> /// Builds a custom filter. ///</summary> ///<param name="filterPropertyDef"></param> ///<returns></returns> public ICustomFilter BuildCustomFilter(IFilterPropertyDef filterPropertyDef) { Type filterType = TypeLoader.LoadType(filterPropertyDef.FilterTypeAssembly, filterPropertyDef.FilterType); ICustomFilter customFilter = (ICustomFilter)Activator.CreateInstance(filterType, _controlFactory, filterPropertyDef.PropertyName, filterPropertyDef.FilterClauseOperator); SetParametersOnFilter(filterPropertyDef, filterType, customFilter); return customFilter; }