Пример #1
0
        public IList <object> GetRuleHandlers(Type type, string ruleType, string realTargetName)
        {
            IList <object> tResults = new List <object>();

            lock (lock_flag)
            {
                //var tempType = ruleHandlerContainer.Where(pre => pre.Key.FullName == type.FullName).FirstOrDefault();
                //if (tempType.Key==null || tempType.Value==null)
                //    return tResults;

                //var interfaceTypeName = this.GetTypeName(ruleType);
                //interfaceTypeName = realTargetName + interfaceTypeName;
                //var tempKeyValuePair = tempType.Value.Where(
                //    pre =>
                //    pre.ImplementType.Name.StartsWith(interfaceTypeName) &&
                //    pre.InterfaceType.GetGenericArguments()[0].Name == type.Name).LastOrDefault();

                //if (tempKeyValuePair == null)
                //    return new List<object>();

                //tResults.Add(ObjectContainer.CreateInstance(tempKeyValuePair.InterfaceType));

                if (ruleHandlerContainer.ContainsKey(type))
                {
                    IList <RuleHandlerKeyValuePair> ruleHandlerKeyValuePairs = ruleHandlerContainer[type];

                    if (ruleHandlerKeyValuePairs == null)
                    {
                        return(tResults);
                    }

                    if (ruleHandlerKeyValuePairs.Count == 0)
                    {
                        return(new List <object>());
                    }

                    var interfaceTypeName = this.GetTypeName(ruleType);
                    interfaceTypeName = realTargetName + interfaceTypeName;
                    var tempKeyValuePair = ruleHandlerKeyValuePairs.Where(
                        pre =>
                        pre.ImplementType.Name.StartsWith(interfaceTypeName) &&
                        pre.InterfaceType.GetGenericArguments()[0].Name == type.Name).LastOrDefault();

                    if (tempKeyValuePair == null)
                    {
                        return(new List <object>());
                    }

                    tResults.Add(ObjectContainer.CreateInstance(tempKeyValuePair.ImplementType));
                }
            }
            return(tResults);
        }
Пример #2
0
        public IList <object> GetEventHandlers(Type eventType)
        {
            IList <object> tResults = new List <object>();

            lock (lock_flag)
            {
                if (eventHandlerContainer.ContainsKey(eventType))
                {
                    IList <EventHandlerKeyValuePair> eventHandlerKeyValuePairs = eventHandlerContainer[eventType];

                    foreach (var eventHandlerKeyValuePair in eventHandlerKeyValuePairs)
                    {
                        tResults.Add(ObjectContainer.CreateInstance(eventHandlerKeyValuePair.InterfaceType));
                    }
                }
            }
            return(tResults);
        }
Пример #3
0
        public object CreateInstance(System.Reflection.MethodInfo methodInfo, System.Reflection.ParameterInfo parmeterInfo)
        {
            lock (lock_flag)
            {
                ValidatorMethodMapping mapping = new ValidatorMethodMapping(methodInfo);

                if (!methodMappingContainer.ContainsKey(methodInfo.DeclaringType))
                {
                    return(null);
                }

                var mappings = methodMappingContainer[methodInfo.DeclaringType];

                var methodMapping = mappings.Where(pre => pre == mapping).FirstOrDefault();

                if (methodMapping.MethodParameters != null && methodMapping.MethodParameters.Length > 0)
                {
                    var parameterMapping = methodMapping.MethodParameters.Where(pre => pre.ParameterInfo.ParameterType == parmeterInfo.ParameterType && pre.ParameterInfo.Position == parmeterInfo.Position).FirstOrDefault();

                    if (parameterMapping == null || parameterMapping.ValidatorType == null)
                    {
                        return(null);
                    }

                    //如果不包含则处理所有的内容
                    if (!validatorInstanceTypeContainer.Contains(parameterMapping.ValidatorType))
                    {
                        ObjectContainer.RegisterInstance(parameterMapping.ValidatorType, ObjectContainer.CreateInstance(parameterMapping.ValidatorType));
                    }

                    return(ObjectContainer.CreateInstance(parameterMapping.ValidatorType));
                }

                return(null);
            }
        }