private static IMethodChooserPolicy GetChooserFromContext(IBuilderContext context, Type typeToBuild, string idToBuild) { IMethodChooserPolicy chooser = context.Policies.Get <IMethodChooserPolicy>(typeToBuild, idToBuild); if (chooser == null) { throw new InvalidOperationException("No IMethodChooserPolicy available"); } return(chooser); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="typeToBuild"></param> /// <param name="existing"></param> /// <param name="idToBuild"></param> /// <param name="il"></param> protected override void BuildUp( IBuilderContext context, Type typeToBuild, object existing, string idToBuild, ILGenerator il) { IMethodChooserPolicy chooser = GetChooserFromContext(context, typeToBuild, idToBuild); List <MethodInfo> methods = new List <MethodInfo>(chooser.GetMethods(typeToBuild)); if (methods.Count > 0) { LocalBuilder objectToBuild = il.DeclareLocal(typeToBuild); il.Emit(OpCodes.Stloc, objectToBuild); foreach (MethodInfo method in chooser.GetMethods(typeToBuild)) { il.Emit(OpCodes.Ldloc, objectToBuild); foreach (ParameterInfo paramInfo in method.GetParameters()) { EmitResolveParameter(il, paramInfo); } il.EmitCall(OpCodes.Call, method, null); } il.Emit(OpCodes.Ldloc, objectToBuild); } }