/// <summary>
 /// Validate the supplied <paramref name="methodOverride"/>.
 /// </summary>
 /// <param name="methodOverride">
 /// The <see cref="Oragon.Spring.Objects.Factory.Support.MethodOverride"/>
 /// to be validated.
 /// </param>
 protected void PrepareMethodOverride(MethodOverride methodOverride)
 {
     if (!ReflectionUtils.HasAtLeastOneMethodWithName(ObjectType, methodOverride.MethodName))
     {
         throw new ObjectDefinitionValidationException(
                   string.Format(
                       CultureInfo.InvariantCulture,
                       "Invalid method override: no method with name '{0}' on class [{1}].",
                       methodOverride.MethodName, ObjectTypeName));
     }
     //TODO investigate setting overloaded at this point using MethodCountForName...
     //Test SunnyDayReplaceMethod_WithArgumentAcceptingReplacerWithNoTypeFragmentsSpecified
     // will fail if doing this optimization.
 }
 /// <summary>
 /// Defines overrides for those methods that are configured with an appropriate
 /// <see cref="Oragon.Spring.Objects.Factory.Support.MethodOverride"/>.
 /// </summary>
 /// <param name="typeBuilder">
 /// The overarching <see cref="System.Reflection.Emit.TypeBuilder"/> that is defining
 /// the generated <see cref="System.Type"/>.
 /// </param>
 private TypeBuilder DefineMethods(TypeBuilder typeBuilder)
 {
     MethodInfo[] methods = BaseType.GetMethods(
         BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
     for (int i = 0; i < methods.Length; ++i)
     {
         MethodInfo     method = methods[i];
         MethodOverride methodOverride
             = this.objectDefinition.MethodOverrides.GetOverride(method);
         if (methodOverride != null)
         {
             if (!method.IsVirtual || method.IsFinal)
             {
                 throw new ObjectCreationException(
                           "A replaced method must be marked as either abstract or virtual.");
             }
             FieldBuilder field = null;
             if (methodOverride is ReplacedMethodOverride)
             {
                 field = this.methodReplacementField;
             }
             else
             {
                 // lookup methods cannot have any arguments...
                 if (method.GetParameters().Length > 0)
                 {
                     throw new ObjectCreationException(
                               "The signature of a lookup method cannot have any arguments.");
                 }
                 // lookup methods cannot return void...
                 if (method.ReturnType == typeof(void))
                 {
                     throw new ObjectCreationException(
                               "A lookup method cannot be declared with a void return type.");
                 }
                 field = this.methodLookupField;
             }
             DefineReplacedMethod(typeBuilder, method, field);
         }
     }
     return(typeBuilder);
 }
Пример #3
0
 /// <summary>
 /// Adds the supplied <paramref name="theOverride"/> to the overrides contained
 /// within this instance.
 /// </summary>
 /// <param name="theOverride">
 /// The <see cref="Oragon.Spring.Objects.Factory.Support.MethodOverride"/> to be
 /// added.
 /// </param>
 public void Add(MethodOverride theOverride)
 {
     Overrides.Add(theOverride);
 }