Ejemplo n.º 1
0
        public void GivenAType_WhenSearchingForTypeHierarchy_ShouldReturnBaseTypesAndInputType(Type input, IEnumerable<Type> expectedResult)
        {
            var inspector = new TypeInspector();

            var result = inspector.GetTypeHierarchy(input);

            CollectionAssert.AreEqual(expectedResult, result);
        }
        public void GivenAType_WhenSearchingForTypeHierarchy_ShouldReturnBaseTypesAndInputType(Type input, IEnumerable <Type> expectedResult)
        {
            var inspector = new TypeInspector();

            var result = inspector.GetTypeHierarchy(input);

            CollectionAssert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the Apply methods for each type in the event type's inheritance
        /// hierarchy, top-down, from interfaces before classes.
        /// </summary>
        private IEnumerable <MethodInfo> FindApplyMethods(object evt)
        {
            var typeInspector = new TypeInspector();

            var typeHierarchy = typeInspector.GetTypeHierarchy(evt.GetType());

            var applyMethods = Enumerable.Select <Type, MethodInfo>(typeHierarchy, FindApplyMethod)
                               .Where(x => x != null)
                               .ToList();

            if (Conventions.AggregatesMustImplementApplyMethods && applyMethods.Count == 0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Class {0} does not implement an Apply() method for {1} or any of it's superclasses. Either implement the method or set Conventions.AggregatesMustImplementApplyMethods to false.",
                              GetType().Name,
                              evt.GetType()));
            }

            return(applyMethods);
        }
Ejemplo n.º 4
0
        private MethodInfo FindApplyMethod(Type eventType)
        {
            var typeInspector = new TypeInspector();

            MethodInfo applyMethod;

            if (false == _applyMethodCache.TryGetValue(eventType.TypeHandle, out applyMethod))
            {
                applyMethod =
                    Enumerable.SelectMany <Type, MethodInfo>(typeInspector.GetTypeHierarchy(GetType()), x => x.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic))
                    .Where(m => m.Name == "Apply")
                    .Where(
                        m =>
                {
                    var parameters = m.GetParameters();
                    return(parameters.Length == 1 && parameters[0].ParameterType == eventType);
                }).SingleOrDefault();

                _applyMethodCache.Add(eventType.TypeHandle, applyMethod);
            }

            return(applyMethod);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the Apply methods for each type in the event type's inheritance
        /// hierarchy, top-down, from interfaces before classes.
        /// </summary>
        private IEnumerable<MethodInfo> FindApplyMethods(object evt)
        {
            var typeInspector = new TypeInspector();

            var applyMethods = typeInspector.GetTypeHierarchy(evt.GetType())
                                            .Select(FindApplyMethod)
                                            .Where(x => x != null)
                                            .ToList();

            return applyMethods;
        }
        private static IEnumerable <Type> GetEventTypeHierarchy(Type eventType)
        {
            var inspector = new TypeInspector();

            return(inspector.GetTypeHierarchy(eventType));
        }