/// <summary>
		/// Validates the specified model to make sure that any methods that are being intercepted
		/// are virtual and can be intercepted.
		/// </summary>
		/// <param name="model">The model.</param>
		/// <param name="store">The store.</param>
		private void Validate(ComponentModel model, MethodValidatorMetaStore store)
		{
			if (model.Service == null || model.Service.IsInterface)
				return;

			MethodValidatorMetaInfo meta = store.GetMetaFor(model.Implementation);

			if (meta == null)
				return;

			List<string> problematicMethods = new List<string>();

			foreach (MethodInfo method in meta.Methods)
			{
				if (!method.IsVirtual)
					problematicMethods.Add(method.Name);
			}

			if (problematicMethods.Count != 0)
			{
				String message = String.Format("The class {0} wants to use method validator interception, " +
											   "however the methods must be marked as virtual in order to do so. Please correct " +
											   "the following methods: {1}", model.Implementation.FullName,
											   String.Join(", ", problematicMethods.ToArray()));
				throw new FacilityException(message);
			}
		}
示例#2
0
        /// <summary>
        /// Validates the specified model to make sure that any methods that are being intercepted
        /// are virtual and can be intercepted.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="store">The store.</param>
        private void Validate(ComponentModel model, MethodValidatorMetaStore store)
        {
            if (model.Service == null || model.Service.IsInterface)
            {
                return;
            }

            MethodValidatorMetaInfo meta = store.GetMetaFor(model.Implementation);

            if (meta == null)
            {
                return;
            }

            List <string> problematicMethods = new List <string>();

            foreach (MethodInfo method in meta.Methods)
            {
                if (!method.IsVirtual)
                {
                    problematicMethods.Add(method.Name);
                }
            }

            if (problematicMethods.Count != 0)
            {
                String message = String.Format("The class {0} wants to use method validator interception, " +
                                               "however the methods must be marked as virtual in order to do so. Please correct " +
                                               "the following methods: {1}", model.Implementation.FullName,
                                               String.Join(", ", problematicMethods.ToArray()));
                throw new FacilityException(message);
            }
        }
示例#3
0
        /// <summary>
        /// Adds the method interceptor to the type if there are methods that have validators
        /// declared.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="store">The store.</param>
        private static void AddMethodInterceptorIfValidatable(ComponentModel model, MethodValidatorMetaStore store)
        {
            MethodValidatorMetaInfo meta = store.GetMetaFor(GetServiceOrDefault(model));

            if (meta == null)
            {
                return;
            }

            model.Dependencies.Add(new DependencyModel(DependencyType.Service, null, typeof(MethodValidatorInterceptor), false));
            model.Interceptors.AddFirst(new InterceptorReference(typeof(MethodValidatorInterceptor)));
        }
		/// <summary>
		/// Adds the method interceptor to the type if there are methods that have validators
		/// declared.
		/// </summary>
		/// <param name="model">The model.</param>
		/// <param name="store">The store.</param>
		private static void AddMethodInterceptorIfValidatable(ComponentModel model, MethodValidatorMetaStore store)
		{
			MethodValidatorMetaInfo meta = store.GetMetaFor(GetServiceOrDefault(model));

			if (meta == null)
				return;

			model.Dependencies.Add(new DependencyModel(DependencyType.Service, null, typeof(MethodValidatorInterceptor), false));
			model.Interceptors.AddFirst(new InterceptorReference(typeof(MethodValidatorInterceptor)));
		}