Example #1
0
        public void doesnt_match_subpackage_c_based_on_required_and_noneOf()
        {
            instance.Require(REQUIRE).NoneOf(NONE_OF);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.False(typeFilter.Matches(ITEM_C));
        }
Example #2
0
        public void doesnt_match_based_on_noneOf()
        {
            instance.NoneOf(NONE_OF);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.False(typeFilter.Matches(ITEM_C));
        }
Example #3
0
        public void matches_based_on_anyOf()
        {
            instance.AnyOf(ANY_OF);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.That(typeFilter.Matches(ITEM_A), Is.True);
        }
Example #4
0
        public void matches_based_on_noneOf()
        {
            instance.NoneOf(NONE_OF);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.True(typeFilter.Matches(ITEM_B));
        }
Example #5
0
        public SwiftTranslator(Poco2SwiftType configuration, ITypeFilter filter, DocumentationCache documentation, IAppDomainProxy appDomain)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            if (documentation == null)
            {
                throw new ArgumentNullException("documentation");
            }

            if (appDomain == null)
            {
                throw new ArgumentNullException("appDomain");
            }

            _configuration = configuration;
            _filter        = filter;
            _documentation = documentation;
            _appDomain     = appDomain;

            InitPredefinedMapTypes();
            InitExternalTypes();
        }
Example #6
0
 private void MapTypeForFilterBinding(ITypeFilter filter, Type type, object item)
 {
     foreach (Type requiredType in RequiredTypesFor(filter, type))
     {
         _injector.Map(requiredType).ToValue(item);
     }
 }
Example #7
0
        public void matches_subpackage_b_based_on_required()
        {
            instance.Require(REQUIRE);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.True(typeFilter.Matches(ITEM_B));
        }
 public void AddFilter(ITypeFilter filter)
 {
     if (null == filter)
     {
         throw new ArgumentNullException("filter");
     }
     _filters.Add(filter);
 }
Example #9
0
        /// <summary>
        /// 构造方法。
        /// </summary>
        public Pointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
        {
            Check.MustNotNull(typeFilter, "typeFilter");
            Check.MustNotNull(methodMatcher, "methodMatcher");

            this.TypeFilter = typeFilter;
            this.MethodMatcher = methodMatcher;
        }
        /// <summary>
        /// 构造方法。
        /// </summary>
        public IntroductionAspect(ITypeFilter typeFilter, IIntroductionAdvice advice)
        {
            Check.MustNotNull(typeFilter, "typeFilter");
            Check.MustNotNull(advice, "advice");

            this.TypeFilter = typeFilter;
            this.Advice = advice;
        }
        public void Deserialization()
        {
            ITypeFilter deserializedVersion
                = (ITypeFilter)SerializationTestUtils.SerializeAndDeserialize(
                      TrueTypeFilter.True);

            Assert.IsTrue(Object.ReferenceEquals(TrueTypeFilter.True, deserializedVersion),
                          "Singleton instance not being deserialized correctly");
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionSyntax"/> class.
 /// </summary>
 /// <param name="bindingBuilder">The binding builder.</param>
 /// <param name="typeFilter">The type filter.</param>
 /// <param name="bindingGeneratorFactory">The binding generator factory.</param>
 public ConventionSyntax(
     IConventionBindingBuilder bindingBuilder,
     ITypeFilter typeFilter,
     IBindingGeneratorFactory bindingGeneratorFactory)
 {
     this.bindingBuilder          = bindingBuilder;
     this.typeFilter              = typeFilter;
     this.bindingGeneratorFactory = bindingGeneratorFactory;
 }
Example #13
0
        private void MapTypeForFilterBinding(ITypeFilter filter, Type type, object view)
        {
            List <Type> requiredTypes = RequiredTypesFor(filter, type);

            foreach (Type requiredType in requiredTypes)
            {
                _injector.Map(requiredType).ToValue(view);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionSyntax"/> class.
 /// </summary>
 /// <param name="bindingBuilder">The binding builder.</param>
 /// <param name="typeFilter">The type filter.</param>
 /// <param name="bindingGeneratorFactory">The binding generator factory.</param>
 public ConventionSyntax(
     IConventionBindingBuilder bindingBuilder, 
     ITypeFilter typeFilter,
     IBindingGeneratorFactory bindingGeneratorFactory)
 {
     this.bindingBuilder = bindingBuilder;
     this.typeFilter = typeFilter;
     this.bindingGeneratorFactory = bindingGeneratorFactory;
 }
		public void SetUp()
		{
			logger = new Mock<ILogger>();
			handler = new Mock<IMediatorViewHandler>();

			TypeMatcher matcher = new TypeMatcher().AllOf(typeof(SupportView));
			filter = matcher.CreateTypeFilter();
			mapper = new MediatorMapper(matcher.CreateTypeFilter(), handler.Object, logger.Object);
		}
Example #16
0
        /// <summary>
        /// Adds the include filter.
        /// </summary>
        /// <param name="filter">The filter type.</param>
        /// <returns></returns>
        public IAssemblyTypeScanner WithIncludeFilter(ITypeFilter filter)
        {
            if (filter != null)
            {
                TypeInclusionTypeFilter.Add(filter);
            }

            return(this);
        }
Example #17
0
        public void matches_based_on_noneOf_twice()
        {
            instance.NoneOf(NONE_OF);
            instance.NoneOf(NONE_OF_2);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.False(typeFilter.Matches(ITEM_B));
            Assert.False(typeFilter.Matches(ITEM_C));
        }
Example #18
0
        public void SetUp()
        {
            logger  = new Mock <ILogging>();
            handler = new Mock <IMediatorViewHandler>();

            TypeMatcher matcher = new TypeMatcher().AllOf(typeof(SupportView));

            filter = matcher.CreateTypeFilter();
            mapper = new MediatorMapper(matcher.CreateTypeFilter(), handler.Object, logger.Object);
        }
Example #19
0
        public void matches_based_on_anyOf_twice()
        {
            instance.AnyOf(ANY_OF);
            instance.AnyOf(ANY_OF_2);
            ITypeFilter typeFilter = instance.CreateTypeFilter();

            Assert.True(typeFilter.Matches(ITEM_A));
            Assert.True(typeFilter.Matches(ITEM_B));
            Assert.True(typeFilter.Matches(ITEM_C));
        }
Example #20
0
 private void UnmapTypeForFilterBinding(ITypeFilter filter, Type type, object item)
 {
     foreach (Type requiredType in RequiredTypesFor(filter, type))
     {
         if (_injector.SatisfiesDirectly(requiredType))
         {
             _injector.Unmap(requiredType);
         }
     }
 }
Example #21
0
        public void Intersection()
        {
            Assert.IsTrue(exceptionFilter.Matches(typeof(SystemException)));
            Assert.IsTrue(hasRootCauseFilter.Matches(typeof(StackOverflowException)));

            ITypeFilter intersection = TypeFilters.Intersection(exceptionFilter, hasRootCauseFilter);

            Assert.IsFalse(intersection.Matches(typeof(SystemException)));
            Assert.IsFalse(intersection.Matches(typeof(TestObject)));
            Assert.IsTrue(intersection.Matches(typeof(StackOverflowException)));
        }
Example #22
0
        public void Union()
        {
            Assert.IsTrue(exceptionFilter.Matches(typeof(SystemException)));
            Assert.IsFalse(exceptionFilter.Matches(typeof(TestObject)));
            Assert.IsFalse(itoFilter.Matches(typeof(Exception)));
            Assert.IsTrue(itoFilter.Matches(typeof(TestObject)));
            ITypeFilter union = TypeFilters.Union(exceptionFilter, itoFilter);

            Assert.IsTrue(union.Matches(typeof(SystemException)));
            Assert.IsTrue(union.Matches(typeof(TestObject)));
        }
Example #23
0
        private ScriptContext(string name, ITypeFilter typeFilter)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("typeFilter", typeFilter);

            _name = name;

            var moduleScope = ReflectionHelper.CreateModuleScope("Scripting.ScriptContext." + name, false);

            _proxyProvider = new StableBindingProxyProvider(typeFilter, moduleScope);
        }
Example #24
0
        private List <Type> RequiredTypesFor(ITypeFilter filter, Type type)
        {
            List <Type> requiredTypes = new List <Type>(filter.AllOfTypes);

            if (!requiredTypes.Contains(type))
            {
                requiredTypes.Add(type);
            }

            return(requiredTypes);
        }
Example #25
0
        public void GetDistinctTypes_WhenFiltered_ReturnsCorrectResult(ITypeFilter filter, int expected)
        {
            var fixture = new CustomAutoDataAttribute().Fixture;
            var sut     = fixture.Create <WindowLocator>();
            var types   = new List <Type> {
                typeof(string), typeof(FakeWindow), typeof(object), typeof(FakeCustomWindow)
            };

            var actual = sut.GetDistinctTypes(types, filter).ToList();

            Assert.Equal(expected, actual.Count);
        }
Example #26
0
        private void UnmapTypeForFilterBinding(ITypeFilter filter, Type type, object view)
        {
            List <Type> requiredTypes = RequiredTypesFor(filter, type);

            foreach (Type requiredType in requiredTypes)
            {
                if (_injector.HasDirectMapping(requiredType))
                {
                    _injector.Unmap(requiredType);
                }
            }
        }
        public void DefaultClassFilterImplAlwaysMatchesRegardless()
        {
            Type oneType               = typeof(One);
            ControlFlowPointcut cut    = new ControlFlowPointcut(oneType);
            ITypeFilter         filter = cut.TypeFilter;

            Assert.IsTrue(filter.Matches(oneType),
                          "Must always match regardless of the supplied argument Type.");
            Assert.IsTrue(filter.Matches(GetType()),
                          "Must always match even if the supplied argument Type is not " +
                          "a match for the Type supplied in the ctor.");
            Assert.IsTrue(filter.Matches(null),             // args are ingored in this impl...
                          "Must always match even if the supplied argument Type is null");
        }
Example #28
0
        private List <Type> RequiredTypesFor(ITypeFilter filter, Type type)
        {
            List <Type> requiredTypes = new List <Type> ();

            requiredTypes.AddRange(filter.AllOfTypes);
            requiredTypes.AddRange(filter.AnyOfTypes);

            if (requiredTypes.IndexOf(type) == -1)
            {
                requiredTypes.Add(type);
            }

            return(requiredTypes);
        }
        /// <summary>
        /// Executes the <paramref name="filter"/> on the <paramref name="type"/>, logging information if it was
        /// excluded.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="filter">The <see cref="Type"/> filter.</param>
        /// <returns>The result of <see cref="ITypeFilter.ExcludeType"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="type"/> or <paramref name="filter"/> parameters
        /// are <see langword="null"/>.</exception>
        private static bool ApplyFilter(this Type type, ITypeFilter filter)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (filter == null)
                throw new ArgumentNullException("filter");

            bool excludeType = filter.ExcludeType(type);
            if (excludeType)
            {
                Trace.TraceInformation(
                    "The type '{0}' was excluded by the filter '{1}'.",
                    type,
                    filter.Name);
            }

            return excludeType;
        }
Example #30
0
        /// <summary>
        ///     Adds field interception support to the target type.
        /// </summary>
        /// <param name="targetAssembly">The type that will be modified.</param>
        /// <param name="hostTypeFilter">The filter that determines the host types to be modified.</param>
        /// <param name="fieldFilter">The field filter that determines the fields that will be intercepted.</param>
        public static void InterceptFields(this AssemblyDefinition targetAssembly, ITypeFilter hostTypeFilter,
                                           IFieldFilter fieldFilter)
        {
            var typeWeaver  = new ImplementFieldInterceptionHostWeaver(hostTypeFilter.ShouldWeave);
            var fieldWeaver = new InterceptFieldAccess(fieldFilter);

            var module      = targetAssembly.MainModule;
            var targetTypes = module.Types.Where(hostTypeFilter.ShouldWeave).ToArray();

            foreach (var type in targetTypes)
            {
                typeWeaver.Weave(type);
                foreach (var method in type.Methods.Where(m => m.HasBody))
                {
                    fieldWeaver.Rewrite(method, method.GetILGenerator(), method.Body.Instructions.ToArray());
                }
            }
        }
Example #31
0
        /// <summary>
        /// Creates a new <see cref="ScriptContext"/>.
        /// </summary>
        /// <param name="name">The tag name of the <see cref="ScriptContext"/>. Must be unique. Suggested naming scheme:
        /// company domain name + namespace of module (e.g. "rubicon.eu.Remotion.Data.DomainObjects.Scripting", "microsoft.com.Word.Scripting").
        /// </param>
        /// <param name="typeFilter">
        /// The <see cref="ITypeFilter"/> which decides which <see cref="Type"/>|s are known in the <see cref="ScriptContext"/>.
        /// </param>
        public static ScriptContext Create(string name, ITypeFilter typeFilter)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("typeFilter", typeFilter);

            lock (s_scriptContextLock)
            {
                var scriptContext = new ScriptContext(name, typeFilter);
                try
                {
                    s_scriptContexts.Add(name, scriptContext);
                }
                catch (ArgumentException)
                {
                    var message = string.Format("ScriptContext '{0}' already exists.", name);
                    throw new ArgumentException(message);
                }

                return(scriptContext);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the given
        /// attribute type
        /// </summary>
        /// <param name="classAttributeType">The attribute type to look for at the class level.</param>
        /// <param name="methodAttributeType">The attribute type to look for at the method attribute.</param>
        public AttributeMatchingPointcut(Type classAttributeType, Type methodAttributeType)
        {
            AssertUtils.IsTrue(classAttributeType != null || methodAttributeType != null,
                               "Either Type attribute type or Method attribute type needs to be specified (or both)");

            if (classAttributeType != null)
            {
                this.typeFilter = new AttributeTypeFilter(classAttributeType);
            } else
            {
                this.typeFilter = TrueTypeFilter.True;
            }

            if (methodAttributeType != null)
            {
                this.methodMatcher = new AttributeMethodMatcher(methodAttributeType);
            } else
            {
                this.methodMatcher = TrueMethodMatcher.True;
            }
        }
Example #33
0
        public StableBindingProxyBuilder(Type proxiedType, ITypeFilter typeFilter, ModuleScope moduleScope)
        {
            ArgumentUtility.CheckNotNull("proxiedType", proxiedType);
            ArgumentUtility.CheckNotNull("typeFilter", typeFilter);
            _typeFilter  = typeFilter;
            _moduleScope = moduleScope;
            _proxiedType = proxiedType;

            _knownInterfaces = FindKnownInterfaces();
            BuildClassMethodToInterfaceMethodsMap();

            _forwardingProxyBuilder = new ForwardingProxyBuilder(_proxiedType.Name, _moduleScope, _proxiedType, _knownInterfaces);

            _firstKnownBaseType = GetFirstKnownBaseType();
            if (_firstKnownBaseType != null)
            {
                _publicMethodsInFirstKnownBaseType = _firstKnownBaseType.GetMethods().ToArray();
                _knownBaseTypeStableMetadataTokenToMethodInfoMap = new StableMetadataTokenToMethodInfoMap(_firstKnownBaseType);
                _firstKnownBaseTypeSpecialMethodsToPropertyMap   = BuildSpecialMethodsToPropertyMap(_firstKnownBaseType);
            }
        }
Example #34
0
 public static Type LoadTypeByName(string name, bool disallowUnsafeTypes, ITypeFilter typeFilter)
 {
     if (disallowUnsafeTypes)
     {
         if (IsDisallowedType(name))
         {
             throw new EvilDeserializationException("Unsafe Type Deserialization Detected!", name);
         }
         if (!typeFilter.IsAllowed(name))
         {
             throw new UserEvilDeserializationException("Unsafe Type Deserialization Detected!", name);
         }
     }
     try
     {
         // Try to load type name using strict version to avoid possible conflicts
         // i.e. if there are different version available in GAC and locally
         var typename = ToQualifiedAssemblyName(name, ignoreAssemblyVersion: false);
         var type     = Type.GetType(typename, true);
         if (disallowUnsafeTypes && UnsafeInheritanceCheck(type))
         {
             throw new EvilDeserializationException(
                       "Unsafe Type Deserialization Detected!", name);
         }
         return(type);
     }
     catch (IOException)
     {
         var typename = ToQualifiedAssemblyName(name, ignoreAssemblyVersion: true);
         var type     = Type.GetType(typename, true);
         if (disallowUnsafeTypes && UnsafeInheritanceCheck(type))
         {
             throw new EvilDeserializationException(
                       "Unsafe Type Deserialization Detected!", name);
         }
         return(type);
     }
 }
Example #35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the given
        /// attribute type
        /// </summary>
        /// <param name="classAttributeType">The attribute type to look for at the class level.</param>
        /// <param name="methodAttributeType">The attribute type to look for at the method attribute.</param>
        public AttributeMatchingPointcut(Type classAttributeType, Type methodAttributeType)
        {
            AssertUtils.IsTrue(classAttributeType != null || methodAttributeType != null,
                               "Either Type attribute type or Method attribute type needs to be specified (or both)");

            if (classAttributeType != null)
            {
                this.typeFilter = new AttributeTypeFilter(classAttributeType);
            }
            else
            {
                this.typeFilter = TrueTypeFilter.True;
            }

            if (methodAttributeType != null)
            {
                this.methodMatcher = new AttributeMethodMatcher(methodAttributeType);
            }
            else
            {
                this.methodMatcher = TrueMethodMatcher.True;
            }
        }
Example #36
0
        /// <summary>
        /// Executes the <paramref name="filter"/> on the <paramref name="type"/>, logging information if it was
        /// excluded.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="filter">The <see cref="Type"/> filter.</param>
        /// <returns>The result of <see cref="ITypeFilter.ExcludeType"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="type"/> or <paramref name="filter"/> parameters
        /// are <see langword="null"/>.</exception>
        private static bool ApplyFilter(this Type type, ITypeFilter filter)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            bool excludeType = filter.ExcludeType(type);

            if (excludeType)
            {
                ////TODO: Look into Tracing.
                ////Trace.TraceInformation(
                ////    "The type '{0}' was excluded by the filter '{1}'.",
                ////    type,
                ////    filter.Name);
            }

            return(excludeType);
        }
			public UnionTypeFilter(ITypeFilter[] filters)
			{
				_filters = filters;
			}
		/// <summary>
		/// Creates the intersection of two <see cref="System.Type"/> filters.
		/// </summary>
		/// <remarks>
		/// <p>
		/// The filter arising from the intersection will match all of the
		/// <see cref="System.Type"/> that both of the two supplied filters
		/// would match.
		/// </p>
		/// </remarks>
		/// <param name="first">
		/// The first <see cref="System.Type"/> filter.
		/// </param>
		/// <param name="second">
		/// The second <see cref="System.Type"/> filter.
		/// </param>
		/// <returns>
		/// The intersection of the supplied <see cref="System.Type"/> filters.
		/// </returns>
		public static ITypeFilter Intersection(ITypeFilter first, ITypeFilter second)
		{
			return new IntersectionTypeFilter(new ITypeFilter[] {first, second});
		}
			public IntersectionTypeFilter(ITypeFilter[] filters)
			{
				_filters = filters;
			}
Example #40
0
		/// <summary>
		/// Creates a new instance of the 
		/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
		/// that uses the supplied <paramref name="typeFilter"/> and
		/// <paramref name="methodMatcher"/>.
		/// </summary>
		/// <param name="typeFilter">
		/// The type filter to use.
		/// </param>
		/// <param name="methodMatcher">
		/// The method matcher to use.
		/// </param>
		public ComposablePointcut(ITypeFilter typeFilter, IMethodMatcher methodMatcher)
		{
			_typeFilter = typeFilter;
			_methodMatcher = methodMatcher;
		}
Example #41
0
		/// <summary>
		/// Creates a new instance of the 
		/// <see cref="Spring.Aop.Support.ComposablePointcut"/> class
		/// that matches all the methods on all <see cref="System.Type"/>s.
		/// </summary>
		public ComposablePointcut()
		{
			_typeFilter = TrueTypeFilter.True;
			_methodMatcher = TrueMethodMatcher.True;
		}
		public virtual void Visit(ITypeFilter customFiltersScore)
		{
		}
 public SetterPointcut(Type type)
 {
     typeFilter = new RootTypeFilter(type);
 }
 /// <summary>
 /// Intercepts all method bodies on the target item.
 /// </summary>
 /// <param name="target">The target to be modified.</param>
 /// <param name="methodFilter">The method filter that will determine the methods that will be modified.</param>
 public static void InterceptMethodBody(this IReflectionStructureVisitable target, IMethodFilter methodFilter,  ITypeFilter typeFilter)
 {
     target.InterceptMethodBody(methodFilter.ShouldWeave, typeFilter.ShouldWeave);
 }
		/*============================================================================*/
		/* Public Functions                                                           */
		/*============================================================================*/

		/**
		 * @inheritDoc
		 */
		public ITypeFilter CreateTypeFilter()
		{
			return _typeFilter == null ? _typeFilter = BuildTypeFilter () : _typeFilter;
		}
		public ITypeFilter CreateTypeFilter()
		{
			return typeFilter != null ? typeFilter : typeFilter = BuildTypeFilter();
		}
        /// <summary>
        /// Adds field interception support to the target type.
        /// </summary>
        /// <param name="targetType">The type that will be modified.</param>
        /// <param name="hostTypeFilter">The filter that determines the host types to be modified.</param>
        /// <param name="fieldFilter">The field filter that determines the fields that will be intercepted.</param>
        public static void InterceptFields(this IReflectionStructureVisitable targetType, ITypeFilter hostTypeFilter,
            IFieldFilter fieldFilter)
        {
            var typeWeaver = new ImplementFieldInterceptionHostWeaver(hostTypeFilter.ShouldWeave);
            var fieldWeaver = new InterceptFieldAccess(fieldFilter);

            targetType.WeaveWith(fieldWeaver, m => true);
            targetType.Accept(typeWeaver);
        }
Example #48
0
		/// <summary>
		/// Changes current pointcut to intersection of the current and supplied pointcut
		/// </summary>
		/// <param name="other">pointcut to diff against</param>
		/// <returns>updated pointcut</returns>
		public virtual ComposablePointcut Intersection(IPointcut other)
		{
			_typeFilter = TypeFilters.Intersection(_typeFilter, other.TypeFilter);
			_methodMatcher = MethodMatchers.Intersection(_methodMatcher, other.MethodMatcher);
			return this;
		}
		private List<Type> RequiredTypesFor(ITypeFilter filter, Type type)
		{
			List<Type> requiredTypes = new List<Type> ();
			requiredTypes.AddRange (filter.AllOfTypes);
			requiredTypes.AddRange (filter.AnyOfTypes);

			if (requiredTypes.IndexOf(type) == -1)
				requiredTypes.Add(type);

			return requiredTypes;
		}
		/*============================================================================*/
		/* Constructor                                                                */
		/*============================================================================*/

		public ViewProcessorMapping(ITypeFilter matcher, object processor)
		{
			_matcher = matcher;
			SetProcessor(processor);
		}
		public void Setup()
		{
			EMPTY_CLASS_LIST = new List<Type> ();
			MATCHER = new TypeFilter(EMPTY_CLASS_LIST, EMPTY_CLASS_LIST, EMPTY_CLASS_LIST);
		}
		private void UnmapTypeForFilterBinding(ITypeFilter filter, Type type, object view)
		{
			List<Type> requiredTypes = RequiredTypesFor(filter, type);

			foreach (Type requiredType in requiredTypes)
			{
				if (_injector.HasDirectMapping(requiredType))
					_injector.Unmap(requiredType);
			}
		}
		private void MapTypeForFilterBinding(ITypeFilter filter, Type type, object view)
		{
			List<Type> requiredTypes = RequiredTypesFor(filter, type);

			foreach (Type requiredType in requiredTypes)
			{
				_injector.Map(requiredType).ToValue(view);
			}
		}
Example #54
0
		/// <summary>
		/// Changes the current type filter to be the intersection of the existing filter
		/// and the supplied <paramref name="filter"/>.
		/// </summary>
		/// <param name="filter">The filter to diff against.</param>
		/// <returns>
		/// The intersection of the existing filter and the supplied <paramref name="filter"/>.
		/// </returns>
		public virtual ComposablePointcut Intersection(ITypeFilter filter)
		{
			_typeFilter = TypeFilters.Intersection(_typeFilter, filter);
			return this;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="AttributeMatchingPointcut"/> class for the
 /// given attribute type
 /// </summary>
 /// <param name="attributeType">Type of the attribute.</param>
 /// <param name="checkInherited">if set to <c>true</c> [check inherited].</param>
 public AttributeMatchingPointcut(Type attributeType, bool checkInherited)
 {
     ValidateAttributeTypeArgument(attributeType);
     this.typeFilter = new AttributeTypeFilter(attributeType, checkInherited);
     this.methodMatcher = TrueMethodMatcher.True;
 }
Example #56
0
        /// <summary>
        /// Will look for a user defined logic class in a set of types.
        /// </summary>
        /// <param name="domainType"></param>
        /// <param name="types"></param>
        /// <param name="typeFilter"></param>
        /// <returns></returns>
        private Type GetLogicClass(Type domainType, IEnumerable<Type> types, ITypeFilter typeFilter)
        {
            //we have 2 criteria to search a logic class:
            //1. look for the MDataLogic attribute
            //2. look for descendants of the LogicBase<> class
            var defaultImplementationName = domainType.Name.Substring(1);

            //filter out the list of types, and assign a score (the lowest score will win)
            //this score is used if multiple logic implementation candidates exist, then logicclasses with
            //the Mdatalogic attr go first, then logicclasses who have the default logic name convention, last all others
            var candidates = (from candidate in types
                             let score = candidate.HasAttribute<MDataLogicAttribute>() ? 0 : candidate.Name == defaultImplementationName ? 1 : 2
                             where candidate.BaseType == typeof(LogicBase<>).MakeGenericType(domainType)
                             orderby score
                             select candidate)
                             .ToList();

            //if multiple logic class had the MDataLogic attribute throw an exception because this is not normal
            if(candidates.Count(x=> x.HasAttribute<MDataLogicAttribute>()) > 1)
                throw new FoundMultipleLogicImplementationsException(domainType, candidates);

            //return the best candidate
            return candidates.FirstOrDefault();
        }
Example #57
0
 /// <summary>
 /// 构造方法。
 /// </summary>
 public Pointcut(ITypeFilter typeFilter)
     : this(typeFilter, TrueMethodMatcher.True)
 {
 }
Example #58
0
		public void AddFilter(ITypeFilter filter)
	    {
            if (null == filter) throw new ArgumentNullException("filter");
	        _filters.Add(filter);
	    }
 public virtual void Visit(ITypeFilter filter)
 {
     Write("type");
 }
Example #60
0
		public NotFilter(ITypeFilter filter)
		{
			_filter = filter;
		}