コード例 #1
0
        private FilterDef BuildFilterDef(FullTextFilterDefAttribute attribute)
        {
            var filterDef = new FilterDef
            {
                Name = attribute.Name,
                Impl = attribute.Impl,
                Cache = attribute.Cache
            };

            try {
                Activator.CreateInstance(filterDef.Impl);
            }
            catch (Exception e) {
                throw new SearchException("Unable to create Filter class: " + filterDef.Impl.FullName, e);
            }

            foreach (var method in filterDef.Impl.GetMethods())
            {
                if (AttributeUtil.HasAttribute<FactoryAttribute>(method))
                {
                    if (filterDef.FactoryMethod != null)
                        throw new SearchException("Multiple Factory methods found " + filterDef.Name + ":" +
                                                  filterDef.Impl.FullName + "." + method.Name);
                    filterDef.FactoryMethod = method;
                }

                if (AttributeUtil.HasAttribute<KeyAttribute>(method))
                {
                    if (filterDef.KeyMethod != null)
                        throw new SearchException("Multiple Key methods found " + filterDef.Name + ":" +
                                                  filterDef.Impl.FullName + "." + method.Name);
                    filterDef.KeyMethod = method;
                }
            }

            // Use properties rather than the Java setter logic idea
            foreach (PropertyInfo prop in filterDef.Impl.GetProperties())
            {
                if (AttributeUtil.HasAttribute<FilterParameterAttribute>(prop))
                {
                    filterDef.AddSetter(prop);
                }
            }

            return filterDef;
        }
コード例 #2
0
        private void BindFilterDef(FullTextFilterDefAttribute defAnn, System.Type mappedClass)
        {
            if (filterDefinitions.ContainsKey(defAnn.Name))
                throw new SearchException("Multiple definitions of FullTextFilterDef.Name = " + defAnn.Name + ":" +
                                          mappedClass.FullName);

            FilterDef filterDef = new FilterDef();
            filterDef.Impl = defAnn.Impl;
            filterDef.Cache = defAnn.Cache;
            try
            {
                Activator.CreateInstance(filterDef.Impl);
            }
            catch (Exception e)
            {
                throw new SearchException("Unable to create Filter class: " + filterDef.Impl.FullName, e);
            }

            foreach (MethodInfo method in filterDef.Impl.GetMethods())
            {
                if (AttributeUtil.HasAttribute<FactoryAttribute>(method))
                {
                    if (filterDef.FactoryMethod != null)
                        throw new SearchException("Multiple Factory methods found " + defAnn.Name + ":" +
                                                  filterDef.Impl.FullName + "." + method.Name);
                    filterDef.FactoryMethod = method;
                }

                if (AttributeUtil.HasAttribute<KeyAttribute>(method))
                {
                    if (filterDef.KeyMethod != null)
                        throw new SearchException("Multiple Key methods found " + defAnn.Name + ":" +
                                                  filterDef.Impl.FullName + "." + method.Name);
                    filterDef.KeyMethod = method;
                }
            }

            // Use properties rather than the Java setter logic idea
            foreach (PropertyInfo prop in filterDef.Impl.GetProperties())
            {
                if (AttributeUtil.HasAttribute<FilterParameterAttribute>(prop))
                {
                    filterDef.AddSetter(prop);
                }
            }

            filterDefinitions[defAnn.Name] = filterDef;
        }